Guest User

Untitled

a guest
May 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. from sklearn.linear_model import LinearRegression
  2. from sklearn.model_selection import train_test_split
  3. model=LinearRegression()
  4. y=y.reshape(-1,1) # reshaping the data
  5. x=x.reshape(-1,1)
  6. #spliting into test/train with a test size of .3 or 30 samples.
  7. x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,shuffle=True)
  8. model.fit(x_train,y_train) # fitting the model
  9. print(model.score(x_test,y_test)) # get the r2 score
  10. p=model.predict(x) # generate a prediction from the model using the original input
  11. plt.plot(x,p,c='b',label='prediction')
  12. plt.legend()
Add Comment
Please, Sign In to add comment