Skip to content

Instantly share code, notes, and snippets.

@64lines
Last active November 6, 2017 19:56
Show Gist options
  • Select an option

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

Select an option

Save 64lines/e6df34e7755e217766fc546dacfc240a to your computer and use it in GitHub Desktop.
[PYTHON][SKLEARN] Linear Regression Predictions
# 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