Created
November 9, 2017 01:53
-
-
Save 64lines/ba485d184891c06eb0c29e44f0872918 to your computer and use it in GitHub Desktop.
[PYTHON][SKLEARN] K-Fold Cross Validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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