Last active
November 6, 2017 19:56
-
-
Save 64lines/e6df34e7755e217766fc546dacfc240a to your computer and use it in GitHub Desktop.
[PYTHON][SKLEARN] Linear Regression Predictions
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 LinearRegression | |
| from sklearn.linear_model import LinearRegression | |
| # Create the regressor: reg | |
| reg = LinearRegression() | |
| # Create the prediction space | |
| prediction_space = np.linspace(min(X_fertility), max(X_fertility)).reshape(-1,1) | |
| # Fit the model to the data | |
| reg.fit(X_fertility, y) | |
| # Compute predictions over the prediction space: y_pred | |
| y_pred = reg.predict(prediction_space) | |
| # Print R^2 | |
| print(reg.score(X_fertility, y)) | |
| # Plot regression line | |
| plt.plot(prediction_space, y_pred, color='black', linewidth=3) | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment