Boise, Idaho, Photo by Alden Skeie on Unsplash

Cross Validation

K-Fold Cross Validation Explained…

K-Fold Cross Validation

K-Fold Cross Validation in Scikit-Learn

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20)
from sklearn.linear_model import LinearRegression
linreg = LinearRegression()

linreg.fit(X_train, y_train)
y_predict_test = linreg.predict(X_test)
from sklearn.metrics import mean_squared_error, make_scorer
from sklearn.model_selection import cross_val_score

mse = make_scorer(mean_squared_error)

5fold_cv_results = np.mean(cross_val_score(linreg, X, y, cv=5, scoring=mse))

Data Scientist, Data Educator, Blogger https://www.linkedin.com/in/seyma-tas/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store