January 2019
Intermediate to advanced
294 pages
6h 43m
English
We can make use of cross-validation to find out which model is performing better by using the following code:
knn = KNeighborsClassifier(n_neighbors=20)print(cross_val_score(knn, X, y, cv=10, scoring='accuracy').mean())
The 10-fold cross-validation is as follows:
# 10-fold cross-validation with logistic regressionfrom sklearn.linear_model import LogisticRegressionlogreg = LogisticRegression()print(cross_val_score(logreg, X, y, cv=10, scoring='accuracy').mean())
Read now
Unlock full access