Skip to content

Instantly share code, notes, and snippets.

@b00033811
Last active May 21, 2018 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b00033811/aec894e45a01971fba32d4fdf54e1940 to your computer and use it in GitHub Desktop.
Save b00033811/aec894e45a01971fba32d4fdf54e1940 to your computer and use it in GitHub Desktop.
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
model=LinearRegression()
y=y.reshape(-1,1) # reshaping the data
x=x.reshape(-1,1)
#spliting into test/train with a test size of .3 or 30 samples.
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,shuffle=True)
model.fit(x_train,y_train) # fitting the model
print(model.score(x_test,y_test)) # get the r2 score
p=model.predict(x) # generate a prediction from the model using the original input
plt.plot(x,p,c='b',label='prediction')
plt.legend()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment