January 2019
Intermediate to advanced
390 pages
9h 16m
English
Using cross-validation can also help in reducing the problem of overfitting. In k-fold cross-validation, data is divided into k-subsets, called folds. Then it trains and evaluates the model k-times; each time, it picks one of the folds for validation and the rest for training the model. We can perform the cross-validation when the data is less and training time is small. scikit provides a cross_val_score method to implement the k-folds. Let classifier be the model we want to cross-validate, then we can use the following code to perform cross-validation on 10 folds:
from sklearn.model_selection import cross_val_score accuracies = cross_val_score(estimator = classifier, X = X_train,\ y = y_train, cv = 10)print("Accuracy Mean ...Read now
Unlock full access