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.90.2250.44.20.0329.0118.00.9893.570.3612.881white
24.70.3350.141.30.03669.0168.00.992123.470.4610.550white
34.70.4550.181.90.03633.0106.00.987463.210.8314.071white
44.70.7850.03.40.03623.0134.00.989813.530.9213.860white
54.90.3450.341.00.06832.0143.00.991383.240.410.150white
64.90.3450.341.00.06832.0143.00.991383.240.410.150white
74.90.420.02.10.04816.042.00.991543.710.7414.071red
85.00.270.41.20.07642.0124.00.992043.320.4710.160white
95.00.310.06.40.04643.0166.00.9943.30.639.960white
105.00.40.54.30.04629.080.00.99023.490.6613.660red
115.00.440.0418.60.03938.0128.00.99853.370.5710.260white
125.10.110.321.60.02812.090.00.990083.570.5212.260white
135.10.140.250.70.03915.089.00.99193.220.439.260white
145.10.1650.225.70.04742.0146.00.99343.180.559.960white
155.10.330.221.60.02718.089.00.98933.510.3812.571white
165.10.330.221.60.02718.089.00.98933.510.3812.571white
175.10.330.221.60.02718.089.00.98933.510.3812.571white
185.10.390.211.70.02715.072.00.98943.50.4512.560white
195.20.20.273.20.04716.093.00.992353.440.5310.171white
205.20.210.311.70.04817.061.00.989533.240.3712.071white
215.20.220.466.20.06641.0187.00.993623.190.429.7333333333333350white
225.20.310.22.40.02727.0117.00.988863.560.4513.071white
235.20.320.251.80.10313.050.00.99573.380.559.250red
245.20.340.376.20.03142.0133.00.990763.250.4112.560white
255.20.360.021.60.03124.0104.00.98963.440.3512.260white
265.20.3650.0813.50.04137.0142.00.9973.460.399.960white
275.20.480.041.60.05419.0106.00.99273.540.6212.271red
285.20.50.182.00.03623.0129.00.989493.360.7713.471white
295.30.160.391.00.02840.0101.00.991563.570.5910.660white
305.30.160.391.00.02840.0101.00.991563.570.5910.660white
315.30.1650.241.10.05125.0105.00.99253.320.479.150white
325.30.230.560.90.04146.0141.00.991193.160.629.750white
335.30.30.31.20.02925.093.00.987423.310.413.671white
345.30.330.31.20.04825.0119.00.990453.320.6211.360white
355.30.360.276.30.02840.0132.00.991863.370.411.660white
365.30.360.276.30.02840.0132.00.991863.370.411.660white
375.30.40.253.90.03145.0130.00.990723.310.5811.7571white
385.30.470.112.20.04816.089.00.991823.540.8813.671red
395.30.470.112.20.04816.089.00.991823.540.8813.566666666666771red
405.30.7150.191.50.1617.062.00.993953.620.6111.050red
415.40.220.291.20.04569.0152.00.991783.760.6311.071white
425.40.5950.12.80.04226.080.00.99323.360.389.350white
435.40.740.091.70.08916.026.00.994023.670.5611.660red
445.50.120.331.00.03823.0131.00.991643.250.459.850white
455.50.120.331.00.03823.0131.00.991643.250.459.850white
465.50.140.274.60.02922.0104.00.99493.340.449.050white
475.50.140.274.60.02922.0104.00.99493.340.449.050white
485.50.160.311.20.02631.068.00.98983.330.4411.6560white
495.50.160.311.20.02631.068.00.98983.330.4411.633333333333360white
505.50.180.225.50.03710.086.00.991563.460.4412.250white
515.50.240.451.70.04622.0113.00.992243.220.4810.050white
525.50.290.31.10.02220.0110.00.988693.340.3812.871white
535.50.310.293.00.02716.0102.00.990673.230.5611.260white
545.50.320.454.90.02825.0191.00.99223.510.4911.571white
555.50.350.351.10.04514.0167.00.9923.340.689.960white
565.50.3750.381.70.03617.098.00.991423.290.3910.560white
575.60.150.265.550.05151.0139.00.993363.470.511.060white
585.60.150.315.30.0388.079.00.99233.30.3910.560white
595.60.160.271.40.04453.0168.00.99183.280.3710.160white
605.60.1750.290.80.04320.067.00.991123.280.489.960white
615.60.1850.197.10.04836.0110.00.994383.260.419.560white
625.60.1850.197.10.04836.0110.00.994383.260.419.560white
635.60.220.321.20.02429.097.00.988233.20.4613.0571white
645.60.260.181.40.03418.0135.00.991743.320.3510.260white
655.60.260.265.70.03112.080.00.99233.250.3810.850white
665.60.260.511.40.02925.093.00.994283.230.4910.560white
675.60.280.284.20.04452.0158.00.9923.350.4410.771white
685.60.30.16.40.04334.0142.00.993823.140.489.850white
695.60.350.145.00.04648.0198.00.99373.30.7110.350white
705.60.490.134.50.03917.0116.00.99073.420.913.771white
715.60.490.134.50.03917.0116.00.99073.420.913.771white
725.60.660.02.20.0873.011.00.993783.710.6312.871red
735.60.660.02.20.0873.011.00.993783.710.6312.871red
745.70.150.4711.40.03549.0128.00.994563.030.3410.581white
755.70.180.262.20.02321.095.00.98933.070.5412.360white
765.70.180.361.20.0469.071.00.991993.70.6810.971white
775.70.20.32.50.04638.0125.00.992763.340.59.960white
785.70.210.320.90.03838.0121.00.990743.240.4610.660white
795.70.210.374.50.0458.0140.00.993323.290.6210.660white
805.70.220.216.00.04441.0113.00.998623.220.468.960white
815.70.220.216.00.04441.0113.00.998623.220.468.960white
825.70.220.216.00.04441.0113.00.998623.220.468.960white
835.70.220.216.00.04441.0113.00.998623.220.468.960white
845.70.220.216.00.04441.0113.00.998623.220.468.960white
855.70.220.293.50.0427.0146.00.989993.170.3612.160white
865.70.230.289.650.02526.0121.00.99253.280.3811.360white
875.70.250.2612.50.04952.5106.00.996913.080.459.460white
885.70.250.2612.50.04952.5120.00.996913.080.459.460white
895.70.250.2711.50.0424.0120.00.994113.330.3110.860white
905.70.260.2417.80.05923.0124.00.997733.30.510.150white
915.70.260.2417.80.05923.0124.00.997733.30.510.150white
925.70.260.2417.80.05923.0124.00.997733.30.510.150white
935.70.270.321.20.04620.0155.00.99343.80.4110.260white
945.70.280.2417.50.04460.0167.00.99893.310.449.450white
955.70.320.181.40.02926.0104.00.99063.440.3711.060white
965.70.320.384.750.03323.094.00.9913.420.4211.871white
975.70.360.344.20.02621.077.00.99073.410.4511.960white
985.80.140.156.10.04227.0123.00.993623.060.69.960white
995.80.150.321.20.03714.0119.00.991373.190.510.260white
1005.80.170.341.80.04596.0170.00.990353.380.911.881white
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.289480968454575660.28854350612667372.3475975990295410.00110112528608301590.0003037964129141178
20.28982648113651130.2906306136949652.31634243329366060.000317466492834542140.00045722949844431324
30.290515412989890640.291216173458436642.3508361975351970.00157935866346617160.00035434663732691977
40.29125055278414830.292926273353148642.2053856849670410.00133890238881603720.0004730088272311401
50.29183803889471830.29310110628823632.29990061124165870.00010962443986555260.00029084033372754744
60.2920263420201860.2923486920518432.43629002571105960.00132279967819640079.972602625723529e-05
70.29202917359310440.292491850226334342.2228462696075440.00096964253923331440.00014770836733955044
80.29218080151217170.292838369928688342.2358773549397790.00120518486545183430.0002571654071367463
90.293637534297845670.294189467543019672.228921572367350.00235505623570326970.0003003642152580665
100.294090452090112640.293233863817006672.12163654963175440.00110545780016113680.00042870081230283715
110.294238027815882040.292802178353089362.2302014827728270.00067712691550130430.0001661021353163625
120.2942510790903180.293511640601970942.36397274335225440.00093334668441643020.00036869131403234227
130.294406486911280350.2940256103893352.1921270688374840.00145347136320228810.00024499824966433745
140.294516384714350650.2942533251598212.17706473668416360.000386464091179239930.00018192436912188714
150.29465587901429170.29420218872321432.19968922932942720.000229386992427070710.0003344092480104205
160.29467873215539070.2941061556144592.3193736871083580.00135955428742028660.0003460174339748435
170.294704757340942650.2957955955576962.1324115594228110.00141299878894421260.0005361822058133988
180.2947694394443980.2957176972465622.27953290939331050.00053961331362138940.00018507084167695867
190.294837056687998030.2937969139046092.2596761385599770.00148655272285201950.0001868971442415501
200.294985657988557640.294173726444125042.2363429864247640.00165076497387188690.0003739234429014296
210.295177868066405670.295493986980330642.22007703781127930.00067815920486744884.3961045086149625e-05
220.295417539197487030.293609189354514352.30360174179077150.00172462940223918060.0007579573152843574
230.295424747005768650.294174509635609042.2891697088877360.00129808173488629850.0002604929448194924
240.29550012609648870.29547225177803432.14292724927266450.00075989119058925620.0005151566478282865
250.295655760417489370.295515905277591032.08845742543538430.00067452559483239760.00025928545387849294
260.295738784398469730.295871482597696632.17361521720886230.00061640139127528620.000319007391786657
270.296326151473262970.295589369683361642.0322857697804770.0012956985172522190.0005909908951539158
280.2965631911577720.29541123726816472.13052455584208160.00167949125092912270.0004476603899010585
290.2968295387464140.29553378748362172.17796548207600930.0012104722989893980.00040227747649885685
300.297255080858897350.295509913470477672.1913406054178870.00086523488500096676.630083851597143e-05
310.297260643366590640.29791555212225432.11348668734232570.00081879657452078090.00024808365065915797
320.29777898906389760.297451342966615962.16470694541931150.00037425387582987490.00017779024379554125
330.2983496996618820.2976892625883212.05652268727620460.00084960779082878380.00023841198679803115
340.29853189957731430.297906290871816362.12041393915812160.00056623334753386740.0002471464171890414
350.29875027649518230.29780407397910931.97747524579366040.000198472308164818280.00038495217481445294
360.298761689270717670.298522097391117352.1631477673848470.00037955240836570830.0001023325693008224
370.29886907385976930.298304701300193652.22457098960876460.00085431621111068730.0003451147379466154
380.299033425404994340.29829077785008872.0294770399729410.00063975282004138329.410350442182807e-05
390.299223823866618670.298881801656983362.1198276678721110.000188302222811184570.0002888671188041458
400.29933152334104870.299295993580133652.06104564666748050.00064671770336519670.00014098249212630203
410.299381744696037340.29944233585096932.08558170000712060.00063636221675177727.80930793273516e-05
420.30023483077930170.300423160261873931.93428103129069020.00059501869154829190.00010537869745843063
430.30027810796516670.300228827211344641.59172685941060380.000301583068144730059.291509149259635e-05
440.30029656393890530.30017078523886332.13894351323445650.000390151552178217360.00016266414205041375
450.3003775631980690.30050200798172532.0292448202768960.000207100271986619660.00010087430636261172
460.30040970505135860.300586148816721351.56742437680562330.00025036028332794260.00010149042754452861
470.30043295205838530.3005231445677781.60775939623514820.000311226748139319163.198137173150413e-05
480.3004981146516490.300561358018322.09947045644124369.766869750030049e-050.00011111986461465852
490.300554079604620660.3006502850863212.0909044742584232.903747236564979e-053.367122851900289e-05
500.300562687389536340.3006256771940732.03563936551411960.000205109363904086720.00023724909990255544
510.30058466764886830.30065213677660731.6032011508941650.000117085808050364913.653184319112618e-05
520.300598034240923630.30062182803975341.91485095024108890.000115988120749505069.135702894238423e-05
530.300603729685937350.300536836534986031.5655575593312585.1459906234249375e-056.840932036306057e-05
540.300610586133228660.30073600185754561.7561586697896328.171762859367519e-057.284608200250072e-05
550.3007325129412110.300569473386902041.70223458607991530.000210171641657643767.627112898929406e-05
560.300753605930525970.30069208782872971.70162741343180350.00015344193927541661.2109219898862424e-05
570.300760495045601040.300769662326897671.66718276341756185.813210544065075e-051.7832999470904556e-05
580.300792530085700670.300688095243271671.66726088523864753.269042185681806e-052.266097327734702e-05
590.300807487253898330.300701734125866371.65784470240275078.518294221514455e-057.273916384170973e-05
600.30081757411997930.3008269011291391.93913133939107256.677401022616656e-050.00015794163526186363
610.30086922203291430.3007526422498271.76197353998824.0475093273226634e-052.7239401290218985e-05
620.300881382998106350.300788234483712671.53922494252522786.270186495706884e-050.00015023188694503426
630.300902133316854950.3008992215916131.65925033887227373.059044674910716e-052.881437475117058e-06
640.3009063971859020.3004786571697122.10348876317342140.000388294420129830360.0002378698434477806
650.300972446518804340.300982587225082031.68908866246541331.2875473214912374e-051.0423060718716696e-05
660.30100347777995470.30079323186372031.69320114453633622.4152088580376617e-057.045771193043205e-05
670.3010299956639810.3010299956639811.5757486025492350.00.0
680.3010299956639810.3010299956639811.65878796577453610.00.0
690.3010299956639810.3010299956639811.65598305066426590.00.0
700.3010299956639810.3010299956639811.66930349667867020.00.0
710.3010299956639810.3010299956639811.53765233357747390.00.0
720.3010299956639810.3010299956639811.70798603693644210.00.0
730.3010299956639810.3010299956639811.5706410408020020.00.0
740.3010299956639810.3010299956639811.58400042851765940.00.0
750.3010299956639810.3010299956639811.59574596087137870.00.0
760.3010299956639810.3010299956639811.51607839266459150.00.0
770.3010299956639810.3010299956639811.64257979393005370.00.0
780.3010299956639810.3010299956639811.77061549822489430.00.0
790.3010299956639810.3010299956639811.59212390581766770.00.0
800.3010299956639810.3010299956639811.61839230855305980.00.0
810.3010299956639810.3010299956639811.75748523076375320.00.0
820.3010299956639810.3010299956639811.62301818529764820.00.0
830.3010299956639810.3010299956639811.64782977104187010.00.0
840.3010299956639810.3010299956639811.6801462968190510.00.0
850.3010299956639810.3010299956639811.62132271130879710.00.0
860.3010299956639810.3010299956639811.6290951569875080.00.0
870.3010299956639810.3010299956639811.74141947428385420.00.0
880.3010299956639810.3010299956639811.73996988932291670.00.0
890.3010299956639810.3010299956639811.63089656829833980.00.0
900.3010299956639810.3010299956639811.64669378598531080.00.0
910.3010299956639810.3010299956639811.61268766721089670.00.0
920.3010299956639810.3010299956639811.70558651288350420.00.0
930.3010299956639810.3010299956639811.65862544377644850.00.0
940.3010299956639810.3010299956639811.53925323486328120.00.0
950.3010299956639810.3010299956639811.6346215407053630.00.0
960.3010299956639810.3010299956639811.66109347343444820.00.0
970.3010299956639810.3010299956639811.75076182683308910.00.0
980.3010299956639810.3010299956639811.78287839889526370.00.0
990.3010299956639810.3010299956639811.56200702985127760.00.0
1000.3010299956639810.3010299956639811.6544343630472820.00.0
1010.3010299956639810.3010299956639811.58255203564961740.00.0
1020.3010299956639810.3010299956639811.65738431612650560.00.0
1030.3010299956639810.3010299956639811.56505250930786130.00.0
1040.3010299956639810.3010299956639811.6369674205780030.00.0
1050.3010299956639810.3010299956639811.59447407722473140.00.0
1060.3010299956639810.3010299956639811.74286111195882150.00.0
1070.3010299956639810.3010299956639811.66415826479593920.00.0
1080.3010299956639810.3010299956639811.63257718086242680.00.0
1090.3010299956639810.3010299956639811.6523777643839520.00.0
1100.3010299956639810.3010299956639811.7029078801472980.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.