Reputation: 138
I have been following tutorial on linear regression with scikitlearn.The code works perfectly and now i wanna predict new output by giving a new input.I have used student score and Study hour data set. Here's the code:
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
data=pd.read_csv("/home/crpsm/Pycharm/DataSet/student_scores.csv")
data.plot(x="Hours",y="Scores",style="o")
plt.title("Score-Hour")
plt.xlabel('Hours ')
plt.ylabel('Percentage ')
x=data.iloc[:,:-1]
y=data.iloc[:,1]
x_train,x_test,y_train,y_test=train_test_split(x,y,train_size=0.55,random_state=5)
regression_model=LinearRegression()
regression_model.fit(x_train,y_train)
print(regression_model.coef_)
print(regression_model.intercept_)
regression_model.predict(X_test)
Upvotes: 0
Views: 166
Reputation: 105
prediction = regression_model.predict(X)
Please read the docs: http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html
Upvotes: 1