sklearn单变量回归预测

 

 

from sklearn import linear_model
import matplotlib.pyplot as plt

#特征值
X=[[1],[2],[3],[4],[5]]
#目标值
y=[10,20,30,40,50]

#测试值
X_test=[[3.45]]

#线性回归模型
regressor=linear_model.LinearRegression()

#模型训练
regressor.fit(X,y)

#用训练过的模型预测
y_test_pred=regressor.predict(X_test)


print("predition:",X_test,"--->",y_test_pred)

#可视化数据
plt.plot(X,y,linewidth=1,color="green")
plt.scatter(X_test,y_test_pred,c="red",s=100)
plt.show()

 

相关文章:

  • 2021-12-24
  • 2022-12-23
  • 2021-09-25
  • 2021-11-22
  • 2022-12-23
  • 2021-04-06
猜你喜欢
  • 2021-12-10
  • 2021-07-11
  • 2021-12-10
  • 2022-01-19
相关资源
相似解决方案