Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
Add Comment
Please, Sign In to add comment