我一直在使用scikitlearn进行线性回归的教程。代码可以正常工作,现在我想通过提供新的输入来预测新的输出。我使用了学生分数和学习时间数据集。 这是代码:
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)
答案 0 :(得分:1)
prediction = regression_model.predict(X)
请阅读文档: http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html