cross_validate

In [ ]:
cross_validate(estimator,
               input_relation: (str, vDataFrame),
               X: list,
               y: str,
               metric: (str, list) = "all",
               cv: int = 3,
               pos_label: (int, float, str) = None,
               cutoff: float = -1,
               show_time: bool = True,
               training_score: bool = False,)

Computes the k-fold cross validation of an estimator.

Parameters

Name Type Optional Description
estimator
object
Vertica estimator having a fit method.
input_relation
str / vDataFrame
Input Relation.
X
list
List of the predictor columns.
y
str
Response Column.
metric
str / list
Metric used to do the model evaluation. It can also be a list of metrics.
  • all : The model will compute all the possible metrics.

For Classification:
  • accuracy : Accuracy
  • auc : Area Under the Curve (ROC)
  • best_cutoff : Cutoff which optimised the ROC Curve prediction.
  • bm : Informedness = tpr + tnr - 1
  • csi : Critical Success Index = tp / (tp + fn + fp)
  • f1 : F1 Score
  • logloss : Log Loss
  • mcc : Matthews Correlation Coefficient
  • mk : Markedness = ppv + npv - 1
  • npv : Negative Predictive Value = tn / (tn + fn)
  • prc_auc : Area Under the Curve (PRC)
  • precision : Precision = tp / (tp + fp)
  • recall : Recall = tp / (tp + fn)
  • specificity : Specificity = tn / (tn + fp)

For Regression:
  • max : Max Error
  • mae : Mean Absolute Error
  • median : Median Absolute Error
  • mse : Mean Squared Error
  • msle : Mean Squared Log Error
  • r2 : R-squared coefficient
  • r2a : R2 adjusted
  • rmse : Root Mean Squared Error
  • var : Explained Variance
cv
int
Number of folds.
pos_label
int / float / str
The main class to be considered as positive (classification only).
cutoff
float
The model cutoff (classification only).
show_time
bool
If set to True, the time and the average time will be added to the report.
training_score
bool
If set to True, the training score will be computed with the validation score.

Returns

tablesample : An object containing the result. For more information, see utilities.tablesample.

Example

In [3]:
from verticapy.learn.linear_model import LogisticRegression
model = LogisticRegression(name = "public.LR_titanic",
                           tol = 1e-4,
                           max_iter = 100, 
                           solver = 'Newton')

from verticapy.learn.model_selection import cross_validate
cross_validate(model, 
               input_relation = "public.titanic_clean", 
               X = ["age", "fare", "parch", "sex", "boat"], 
               y = "survived", 
               cv = 3)
Out[3]:
auc
prc_auc
accuracy
log_loss
precision
recall
f1_score
mcc
informedness
markedness
csi
time
1-fold0.98706392705925110.97549936147685230.97368421052631580.04650683316222950.97014925373134330.9489051094890510.96698398206205770.94007020133026540.93467023404421120.94550136640739970.92198581560283691.5210838317871094
2-fold0.99650349650349690.99404333359433060.98223350253807110.02689996251699690.98571428571428580.9650349650349650.97834721332479180.96153759977161460.95706683754492520.96602924634420710.95172413793103451.1832020282745361
3-fold0.99426760766239370.9880898317187060.97727272727272730.034805596370820.97656250.95419847328244280.9711328895280740.9485092616216950.94287771856546150.95417444029850750.93283582089552241.250831127166748
avg0.99261167707504730.9858775089299630.9777301467790380.036070797350015460.97747534648187640.95604618260215290.97215469497164120.95003902090785830.94487159671819930.95523501768337140.93551525814313131.318372329076131
std0.0049328437443088820.0094678669490359140.0042929620227915740.0098644763805809180.0078225649043079820.0082221397628975260.0057501148645894010.0108151477828604890.0113306497897526430.0103049542438071170.0150491359119668230.1787802806596699
Rows: 1-5 | Columns: 13
In [5]:
# Adding the train result

res_test, res_train = cross_validate(
                           model, 
                           input_relation = "public.titanic_clean", 
                           X = ["age", "fare", "parch", "sex", "boat"], 
                           y = "survived", 
                           cv = 3,
                           metric = "auc",
                           training_score = True)
display(res_test)
auc
time
1-fold0.9949644225506291.060049057006836
2-fold0.98657092344578751.4258790016174316
3-fold0.9940854671478491.1313872337341309
avg0.99187360438142181.205771764119466
std0.0046132374184377350.1939269988009226
Rows: 1-5 | Columns: 3
In [6]:
display(res_train)
auc
time
1-fold0.99050144945414261.060049057006836
2-fold0.99510982424190821.4258790016174316
3-fold0.9907648848326831.1313872337341309
avg0.99212538617624461.205771764119466
std0.0025879533371958260.1939269988009226
Rows: 1-5 | Columns: 3