Skip to content

Instantly share code, notes, and snippets.

@64lines
Created November 9, 2017 01:53
Show Gist options
  • Select an option

  • Save 64lines/ba485d184891c06eb0c29e44f0872918 to your computer and use it in GitHub Desktop.

Select an option

Save 64lines/ba485d184891c06eb0c29e44f0872918 to your computer and use it in GitHub Desktop.
[PYTHON][SKLEARN] K-Fold Cross Validation
# Import necessary modules
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import cross_val_score
# Create a linear regression object: reg
reg = LinearRegression()
# Perform 3-fold CV
cvscores_3 = cross_val_score(reg, X, y, cv=3)
print(np.mean(cvscores_3))
# Perform 10-fold CV
cvscores_10 = cross_val_score(reg, X, y, cv=10)
print(np.mean(cvscores_10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment