Loading...

verticapy.machine_learning.model_selection.hp_tuning.enet_search_cv

verticapy.machine_learning.model_selection.hp_tuning.enet_search_cv(input_relation: Annotated[str | vDataFrame, ''], X: Annotated[str | list[str], 'STRING representing one column or a list of columns'], y: str, metric: str = 'auto', cv: int = 3, estimator_type: Literal['logit', 'enet', 'auto'] = 'auto', cutoff: float = -1.0, print_info: bool = True, **kwargs) TableSample

Computes the k-fold grid search using multiple ENet models.

input_relation: SQLRelation

Relation used to train the model.

X: SQLColumns

list of the predictor columns.

y: str

Response Column.

metric: str, optional

Metric used for the model evaluation.

  • auto:

    logloss for classification & RMSE for regression.

For Classification

  • accuracy:

    Accuracy.

    \[Accuracy = \frac{TP + TN}{TP + TN + FP + FN}\]
  • auc:

    Area Under the Curve (ROC).

    \[AUC = \int_{0}^{1} TPR(FPR) \, dFPR\]
  • ba:

    Balanced Accuracy.

    \[BA = \frac{TPR + TNR}{2}\]
  • bm:

    Informedness

    \[BM = TPR + TNR - 1\]
  • csi:

    Critical Success Index

    \[index = \frac{TP}{TP + FN + FP}\]
  • f1:

    F1 Score .. math:

    F_1 Score = 2 \times 
    

rac{Precision times Recall}{Precision + Recall}

  • fdr:

    False Discovery Rate

    \[FDR = 1 - PPV\]
  • fm:

    Fowlkes-Mallows index

    \[FM = \sqrt{PPV * TPR}\]
  • fnr:

    False Negative Rate

    \[FNR = \frac{FN}{FN + TP}\]
  • for:

    False Omission Rate

    \[FOR = 1 - NPV\]
  • fpr:

    False Positive Rate

    \[FPR = \frac{FP}{FP + TN}\]
  • logloss:

    Log Loss

    \[Loss = -\frac{1}{N} \sum_{i=1}^{N} \left( y_i \log(p_i) + (1 - y_i) \log(1 - p_i) \right)\]
  • lr+:

    Positive Likelihood Ratio.

    \[LR+ = \frac{TPR}{FPR}\]
  • lr-:

    Negative Likelihood Ratio.

    \[LR- = \frac{FNR}{TNR}\]
  • dor:

    Diagnostic Odds Ratio.

    \[DOR = \frac{TP \times TN}{FP \times FN}\]
  • mcc:

    Matthews Correlation Coefficient

  • mk:

    Markedness

    \[MK = PPV + NPV - 1\]
  • npv:

    Negative Predictive Value

    \[NPV = \frac{TN}{TN + FN}\]
  • prc_auc:

    Area Under the Curve (PRC)

    \[AUC = \int_{0}^{1} Precision(Recall) \, dRecall\]
  • precision:

    Precision

    \[TP / (TP + FP)\]
  • pt:

    Prevalence Threshold.

    \[\frac{\sqrt{FPR}}{\sqrt{TPR} + \sqrt{FPR}}\]
  • recall:

    Recall.

    \[TP / (TP + FN)\]
  • specificity:

    Specificity.

    \[TN / (TN + FP)\]

For Regression

  • max:

    Max Error.

    \[ME = \max_{i=1}^{n} \left| y_i - \hat{y}_i \right|\]
  • mae:

    Mean Absolute Error.

    \[MAE = \frac{1}{n} \sum_{i=1}^{n} \left| y_i - \hat{y}_i \right|\]
  • median:

    Median Absolute Error.

    \[MedAE = \text{median}_{i=1}^{n} \left| y_i - \hat{y}_i \right|\]
  • mse:

    Mean Squared Error.

    \[MSE = \frac{1}{n} \sum_{i=1}^{n} \left( y_i - \hat{y}_i \right)^2\]
  • msle:

    Mean Squared Log Error.

    \[MSLE = \frac{1}{n} \sum_{i=1}^{n} (\log(1 + y_i) - \log(1 + \hat{y}_i))^2\]
  • r2:

    R squared coefficient.

    \[R^2 = 1 - \frac{\sum_{i=1}^{n} (y_i - \hat{y}_i)^2}{\sum_{i=1}^{n} (y_i - \bar{y})^2}\]
  • r2a:

    R2 adjusted

    \[\text{Adjusted } R^2 = 1 - \frac{(1 - R^2)(n - 1)}{n - k - 1}\]
  • var:

    Explained Variance.

    \[VAR = 1 - \frac{Var(y - \hat{y})}{Var(y)}\]
  • rmse:

    Root-mean-squared error

    \[RMSE = \sqrt{\frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2}\]
cv: int, optional

Number of folds.

estimator_type: str, optional

Estimator Type.

cutoff: float, optional

The model cutoff (logit only).

print_info: bool, optional

If set to True, prints the modelinformation at each step.

TableSample

result of the ENET search.

We import verticapy:

import verticapy as vp

Hint

By assigning an alias to verticapy, we mitigate the risk of code collisions with other libraries. This precaution is necessary because verticapy uses commonly known function names like “average” and “median”, which can potentially lead to naming conflicts. The use of an alias ensures that the functions from verticapy are used as intended without interfering with functions from other libraries.

For this example, we will use the Wine Quality dataset.

import verticapy.datasets as vpd

data = vpd.load_winequality()
123
fixed_acidity
Numeric(8)
123
volatile_acidity
Numeric(9)
123
citric_acid
Numeric(8)
123
residual_sugar
Numeric(9)
123
chlorides
Float(22)
123
free_sulfur_dioxide
Numeric(9)
123
total_sulfur_dioxide
Numeric(9)
123
density
Float(22)
123
pH
Numeric(8)
123
sulphates
Numeric(8)
123
alcohol
Float(22)
123
quality
Integer
123
good
Integer
Abc
color
Varchar(20)
13.80.310.0211.10.03620.0114.00.992483.750.4412.460white
23.90.2250.44.20.0329.0118.00.9893.570.3612.881white
34.20.170.361.80.02993.0161.00.989993.650.8912.071white
44.20.2150.235.10.04164.0157.00.996883.420.448.030white
54.40.320.394.30.0331.0127.00.989043.460.3612.881white
64.40.460.12.80.02431.0111.00.988163.480.3413.160white
74.40.540.095.10.03852.097.00.990223.410.412.271white
84.50.190.210.950.03389.0159.00.993323.340.428.050white
94.60.4450.01.40.05311.0178.00.994263.790.5510.250white
104.60.520.152.10.0548.065.00.99343.90.5613.140red
114.70.1450.291.00.04235.090.00.99083.760.4911.360white
124.70.3350.141.30.03669.0168.00.992123.470.4610.550white
134.70.4550.181.90.03633.0106.00.987463.210.8314.071white
144.70.60.172.30.05817.0106.00.99323.850.612.960red
154.70.670.091.00.025.09.00.987223.30.3413.650white
164.70.7850.03.40.03623.0134.00.989813.530.9213.860white
174.80.130.321.20.04240.098.00.98983.420.6411.871white
184.80.170.282.90.0322.0111.00.99023.380.3411.371white
194.80.210.2110.20.03717.0112.00.993243.660.4812.271white
204.80.2250.381.20.07447.0130.00.991323.310.410.360white
214.80.260.2310.60.03423.0111.00.992743.460.2811.571white
224.80.290.231.10.04438.0180.00.989243.280.3411.960white
234.80.330.06.50.02834.0163.00.99373.350.619.950white
244.80.340.06.50.02833.0163.00.99393.360.619.960white
254.80.650.121.10.0134.010.00.992463.320.3613.540white
264.90.2350.2711.750.0334.0118.00.99543.070.59.460white
274.90.330.311.20.01639.0150.00.987133.330.5914.081white
284.90.3350.141.30.03669.0168.00.992123.470.4610.466666666666750white
294.90.3350.141.30.03669.0168.00.992123.470.4610.466666666666750white
304.90.3450.341.00.06832.0143.00.991383.240.410.150white
314.90.3450.341.00.06832.0143.00.991383.240.410.150white
324.90.420.02.10.04816.042.00.991543.710.7414.071red
334.90.470.171.90.03560.0148.00.989643.270.3511.560white
345.00.170.561.50.02624.0115.00.99063.480.3910.871white
355.00.20.41.90.01520.098.00.98973.370.5512.0560white
365.00.2350.2711.750.0334.0118.00.99543.070.59.460white
375.00.240.195.00.04317.0101.00.994383.670.5710.050white
385.00.240.212.20.03931.0100.00.990983.690.6211.760white
395.00.240.341.10.03449.0158.00.987743.320.3213.171white
405.00.2550.222.70.04346.0153.00.992383.750.7611.360white
415.00.270.324.50.03258.0178.00.989563.450.3112.671white
425.00.270.324.50.03258.0178.00.989563.450.3112.671white
435.00.270.41.20.07642.0124.00.992043.320.4710.160white
445.00.290.545.70.03554.0155.00.989763.270.3412.981white
455.00.30.333.70.0354.0173.00.98873.360.313.071white
465.00.310.06.40.04643.0166.00.9943.30.639.960white
475.00.330.161.50.04910.097.00.99173.480.4410.760white
485.00.330.161.50.04910.097.00.99173.480.4410.760white
495.00.330.161.50.04910.097.00.99173.480.4410.760white
505.00.330.184.60.03240.0124.00.991143.180.411.060white
515.00.330.2311.80.0323.0158.00.993223.410.6411.860white
525.00.350.257.80.03124.0116.00.992413.390.411.360white
535.00.350.257.80.03124.0116.00.992413.390.411.360white
545.00.380.011.60.04826.060.00.990843.70.7514.060red
555.00.40.54.30.04629.080.00.99023.490.6613.660red
565.00.420.242.00.0619.050.00.99173.720.7414.081red
575.00.440.0418.60.03938.0128.00.99853.370.5710.260white
585.00.4550.181.90.03633.0106.00.987463.210.8314.071white
595.00.550.148.30.03235.0164.00.99183.530.5112.581white
605.00.610.121.30.00965.0100.00.98743.260.3713.550white
615.00.740.01.20.04116.046.00.992584.010.5912.560red
625.01.020.041.40.04541.085.00.99383.750.4810.540red
635.01.040.241.60.0532.096.00.99343.740.6211.550red
645.10.110.321.60.02812.090.00.990083.570.5212.260white
655.10.140.250.70.03915.089.00.99193.220.439.260white
665.10.1650.225.70.04742.0146.00.99343.180.559.960white
675.10.210.281.40.04748.0148.00.991683.50.4910.450white
685.10.230.181.00.05313.099.00.989563.220.3911.550white
695.10.250.361.30.03540.078.00.98913.230.6412.171white
705.10.260.331.10.02746.0113.00.989463.350.4311.471white
715.10.260.346.40.03426.099.00.994493.230.419.260white
725.10.290.288.30.02627.0107.00.993083.360.3711.060white
735.10.290.288.30.02627.0107.00.993083.360.3711.060white
745.10.30.32.30.04840.0150.00.989443.290.4612.260white
755.10.3050.131.750.03617.073.00.993.40.5112.333333333333350white
765.10.310.30.90.03728.0152.00.9923.540.5610.160white
775.10.330.221.60.02718.089.00.98933.510.3812.571white
785.10.330.221.60.02718.089.00.98933.510.3812.571white
795.10.330.221.60.02718.089.00.98933.510.3812.571white
805.10.330.276.70.02244.0129.00.992213.360.3911.071white
815.10.350.266.80.03436.0120.00.991883.380.411.560white
825.10.350.266.80.03436.0120.00.991883.380.411.560white
835.10.350.266.80.03436.0120.00.991883.380.411.560white
845.10.390.211.70.02715.072.00.98943.50.4512.560white
855.10.420.01.80.04418.088.00.991573.680.7313.671red
865.10.420.011.50.01725.0102.00.98943.380.3612.371white
875.10.470.021.30.03418.044.00.99213.90.6212.860red
885.10.510.182.10.04216.0101.00.99243.460.8712.971red
895.10.520.062.70.05230.079.00.99323.320.439.350white
905.10.5850.01.70.04414.086.00.992643.560.9412.971red
915.20.1550.331.60.02813.059.00.989753.30.8411.981white
925.20.1550.331.60.02813.059.00.989753.30.8411.981white
935.20.160.340.80.02926.077.00.991553.250.5110.160white
945.20.170.270.70.0311.068.00.992183.30.419.850white
955.20.1850.221.00.0347.0123.00.992183.550.4410.1560white
965.20.20.273.20.04716.093.00.992353.440.5310.171white
975.20.210.311.70.04817.061.00.989533.240.3712.071white
985.20.220.466.20.06641.0187.00.993623.190.429.7333333333333350white
995.20.240.157.10.04332.0134.00.993783.240.489.960white
1005.20.240.453.80.02721.0128.00.9923.550.4911.281white
Rows: 1-100 | Columns: 14

Note

VerticaPy offers a wide range of sample datasets that are ideal for training and testing purposes. You can explore the full list of available datasets in the Datasets, which provides detailed information on each dataset and how to use them effectively. These datasets are invaluable resources for honing your data analysis and machine learning skills within the VerticaPy environment.

Next, we can initialize a LogisticRegression model:

from verticapy.machine_learning.vertica import LogisticRegression

model = LogisticRegression()

Now we can conveniently use the enet_search_cv() function to perform the k-fold grid search using multiple ENet models.

from verticapy.machine_learning.model_selection import enet_search_cv

result = enet_search_cv(
    model,
    input_relation = data,
    X = [
        "fixed_acidity",
        "volatile_acidity",
        "citric_acid",
        "residual_sugar",
        "chlorides",
        "density",
    ],
    y = "good",
    cv = 3,
)
avg_score
avg_train_score
avg_time
score_std
score_train_std
10.288755033993010.28897056995084070.50931755701700840.00157844069222484929.021984241016784e-05
20.289884752093302060.290879315153841360.50786805152893070.00088676669374930070.000739324649531738
30.291993819721928340.291227097703946340.46925401687622070.00176074918195547460.0007443208396006909
40.29210713156569170.292941482886869330.497729937235514340.00135306374240657660.00037384581751064136
50.292252628605441660.29433951890969360.52946162223815920.00074640908820813860.0006562532757860629
60.29297251055274770.292292607416540.49935746192932130.00051836064802621276.0482151377715214e-05
70.293029226035015360.291883284737914970.4981846014658610.000258232402028121250.0004614568950753615
80.293169361998168340.294626680263421370.51204633712768550.00041332212077980490.00015642091652040354
90.293214950194499340.29403979711771770.5153323014577230.00214493341210913450.0002773431265495126
100.293508228395926940.29247846777167970.51309744517008460.00166205002480986420.00026318299479527793
110.29376375691846170.293187226804785650.442175388336181640.00098713006137070750.0004785486710449681
120.294111433029888350.293020396990713970.447336037953694640.00138056241416625740.000530306839753773
130.294194240110458970.2927340583260160.49513395627339680.0013355829124107860.0004403397596976341
140.294209196466693360.29433722298432930.492472410202026370.0008401549121915460.00012772934751587858
150.2943917303145860.295705608669936340.48865715662638350.00056626332513958110.0002322281898129302
160.2945273958412970.294276916472119340.50491078694661460.001384674835273830.00045650863486426836
170.294653272430097650.2939721978550050.51698692639668790.000258405395262980840.0003748626071545178
180.294671174005846970.2941310228211960.50983270009358730.00270777369098214270.0006988274397574708
190.294688756675304030.29422750068446730.49580367406209310.0005629190109071470.000300265597443176
200.295186395351871360.295587255994197050.4627741177876790.0008449639103542740.00016341213630130728
210.295371380161502050.293935064354420.493307113647460940.00053277993591736433.7032185326878735e-05
220.29540700948538570.29569905170850430.469763437906901060.00097666593275090170.00021819825763408473
230.295445720126994660.295840141610187960.482709248860677060.00139897817040623030.0002592893825424637
240.29546541645394130.295757003275429360.4742744763692220.00059277200716899010.0003315935691227957
250.29548035376676360.295574334233640660.45998883247375490.00147816052982688530.0004394696321321296
260.295612510503487640.294260215909230350.49728377660115560.00034616661359017360.00033042248211202725
270.29566451879614770.29561507601073730.473087469736735040.00063550443296693720.0004306523914199375
280.29582039858140670.295840672394548370.489768187204996760.0016911147722216260.0005699737942436646
290.296009289445341660.2951910680012870.449558893839518250.00051949273756280870.00013932914339884124
300.2972397708579930.2953756810207480.48324251174926760.00189072243167497250.00019247645639536117
310.297478144358831350.298016033602252650.47712492942810060.000144760069014852449.640824439204522e-05
320.297901107246645370.297434204333464350.46457974116007490.00057986969385996540.00013256640930582524
330.297967617848540.2983470644868240.47909577687581380.00033397647634652296.1555176505539e-05
340.2980461212689560.2978469694922120.47091619173685710.0004609081430424180.0002735075504638667
350.2981303321179940.298412043617264370.48133563995361330.0004976659791813650.0002567417908336975
360.29850185879195370.29744592240067430.46286153793334960.00073903365281861360.0001408361978420144
370.2986567595421050.298497366215516650.46946477890014650.000231162052091707770.0001572099699721157
380.298832843722223350.298533320617896670.47471332550048835.3359540000122785e-050.00025357304787172264
390.298928220865068040.299075298207404360.47295101483662920.0004340441320900880.00018364970199760344
400.299427271706056650.2993810062159890.46336460113525390.00035748225235376550.0004070358610976282
410.299494120275884350.299558975887576350.465489308039347350.000240824434708144672.992681170917025e-05
420.2999032084240330.300264620155011650.40584023793538412.132396934047377e-050.00014219160637806544
430.300137086002946640.3002310432757630.303978204727172850.00024226214578168469.883012467130248e-05
440.30043284962551370.300431734699871330.31800429026285810.000128799140885683050.0001228978769460069
450.300501000714542330.300699543749140.297705094019571960.000101362157335269053.41589859123821e-05
460.300643015057733660.300661168565797330.452908833821614560.000191159590918193686.699357219484447e-05
470.30064977102853270.3006181244102570.43466838200887040.000165331870284026529.531028684657328e-05
480.30070653490085330.30064634798344130.44026517868041994.92183761025651e-050.00018079134637401077
490.3007401536622020.29989397866219670.468177000681559260.0003412564996345220.00023685694065802857
500.300771632474437670.300434355111471040.47190690040588380.000284872128134653150.00012536396366005884
510.30078639664915860.300429970828064660.47917556762695310.00018245418082986490.00011818889591886163
520.300794792467609650.30075769327236770.418872992197672546.666641180134395e-056.791146542654688e-05
530.3008576301825130.300741116891806660.418117602666219060.000113403819394696615.319235184174567e-05
540.30091564430238130.300763538125698340.319337526957194037.530684128951878e-059.107189333617933e-05
550.300957792534123360.300907525557150670.31878701845804852.4376501845209437e-052.45921206324533e-05
560.300999884537678950.30094998875027870.342677116394042972.187420327314401e-051.2120649774923495e-06
570.3010299956639810.3010299956639810.3385471502939860.00.0
580.3010299956639810.3010299956639810.327886978785196960.00.0
590.3010299956639810.3010299956639810.3304716746012370.00.0
600.3010299956639810.3010299956639810.33714373906453450.00.0
610.3010299956639810.3010299956639810.320292552312215150.00.0
620.3010299956639810.3010299956639810.31850814819335940.00.0
630.3010299956639810.3010299956639810.324469566345214840.00.0
640.3010299956639810.3010299956639810.333263953526814760.00.0
650.3010299956639810.3010299956639810.336585442225138360.00.0
660.3010299956639810.3010299956639810.3420237700144450.00.0
670.3010299956639810.3010299956639810.321164210637410460.00.0
680.3010299956639810.3010299956639810.32039268811543780.00.0
690.3010299956639810.3010299956639810.31698735555013020.00.0
700.3010299956639810.3010299956639810.320293029149373350.00.0
710.3010299956639810.3010299956639810.31842080752054850.00.0
720.3010299956639810.3010299956639810.32002178827921550.00.0
730.3010299956639810.3010299956639810.3147277832031250.00.0
740.3010299956639810.3010299956639810.30602812767028810.00.0
750.3010299956639810.3010299956639810.31510416666666670.00.0
760.3010299956639810.3010299956639810.328615585962931330.00.0
770.3010299956639810.3010299956639810.31993293762207030.00.0
780.3010299956639810.3010299956639810.328909317652384460.00.0
790.3010299956639810.3010299956639810.322041511535644530.00.0
800.3010299956639810.3010299956639810.32603534062703450.00.0
810.3010299956639810.3010299956639810.3204321861267090.00.0
820.3010299956639810.3010299956639810.317332108815511050.00.0
830.3010299956639810.3010299956639810.306739807128906250.00.0
840.3010299956639810.3010299956639810.30129901568094890.00.0
850.3010299956639810.3010299956639810.30706524848937990.00.0
860.3010299956639810.3010299956639810.306362708409627260.00.0
870.3010299956639810.3010299956639810.307960033416748050.00.0
880.3010299956639810.3010299956639810.308629035949707030.00.0
890.3010299956639810.3010299956639810.307178179423014340.00.0
900.3010299956639810.3010299956639810.309865713119506840.00.0
910.3010299956639810.3010299956639810.30899437268575030.00.0
920.3010299956639810.3010299956639810.302538077036539730.00.0
930.3010299956639810.3010299956639810.31507825851440430.00.0
940.3010299956639810.3010299956639810.328665018081665040.00.0
950.3010299956639810.3010299956639810.36980597178141280.00.0
960.3010299956639810.3010299956639810.347495953241984070.00.0
970.3010299956639810.3010299956639810.32270979881286620.00.0
980.3010299956639810.3010299956639810.33987180391947430.00.0
990.3010299956639810.3010299956639810.326577504475911440.00.0
1000.3010299956639810.3010299956639810.34528628985087080.00.0
1010.3010299956639810.3010299956639810.331916252772013360.00.0
1020.3010299956639810.3010299956639810.33593392372131350.00.0
1030.3010299956639810.3010299956639810.3331768512725830.00.0
1040.3010299956639810.3010299956639810.35350441932678220.00.0
1050.3010299956639810.3010299956639810.33410795529683430.00.0
1060.3010299956639810.3010299956639810.32596015930175780.00.0
1070.3010299956639810.3010299956639810.331733306248982730.00.0
1080.3010299956639810.3010299956639810.315423091252644840.00.0
1090.3010299956639810.3010299956639810.341616789499918640.00.0
1100.3010299956639810.3010299956639810.33724617958068850.00.0
Rows: 1-110 | Columns: 6

Note

In VerticaPy, Elastic Net Cross-Validation (EnetCV) utilizes multiple ElasticNet models for regression tasks and LogisticRegression models for classification tasks. It systematically tests various combinations of hyperparameters, such as the regularization terms (L1 and L2), to identify the set that optimizes the model’s performance. This process helps in automatically fine-tuning the model to achieve better accuracy and generalization on diverse datasets.

See also

grid_search_cv() : Computes the k-fold grid search of an estimator.
randomized_search_cv() : Computes the K-Fold randomized search of an estimator.