我试图使用两个数组来练习要在哪里绘制它们-首先查看它们,然后创建一个线性回归模型,然后拟合数据并对其进行预测。
最后,我想绘制将它们分开的线性回归线,但我不能-它不能绘制。这是我的代码:
k_true = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
k_pred = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,21]
plt.scatter(k_true,k_pred)
model = LinearRegression()
model.fit([k_true],[k_pred])
predictor = model.predict([k_pred])
plt.scatter(k_true,k_pred)
plt.plot([k_true],predictor,color="red")