【发布时间】:2020-11-19 16:26:50
【问题描述】:
【问题讨论】:
-
你有两个问题①正如 Quang Hoang 所说,你必须对两个向量进行排序,②你的预测看起来不对,我可以看到许多横坐标非常接近且纵坐标相差很大的点,这不是线性模型的结果……
标签: python pandas matplotlib scikit-learn linear-regression
【问题讨论】:
标签: python pandas matplotlib scikit-learn linear-regression
您可以对goldEarned 进行排序并绘制:
order = np.argsort(goldEarned.ravel())
plt.plot(goldEarned[order], kills_preds[order])
【讨论】:
您的问题的解决方案也可以是使用线性回归拟合的信息绘制一条新线!您将有一些权重 w1[x1] + w2[x2] ... +b(截距)。假设您在 X 数组中只有一个特征(kills)(只有一列)。您将得到一个由 y = w1[x1] +b 组成的简单直线方程。在这个方程 y:目标或/和预测中,x1 是特征,b 是截距。所以只需绘制它: 如果你还有什么疑惑,建议你看看 sci-kit 的学习文档https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html
points = np.linspace(np.min(kills), np.max(kills), 100) # create an array from original array
w1 = linreg.coef_ # save the coefficient of linear regression into w1
b = linreg.intercept_ # save the intercept of linear regression
#### add plot to your data scatter plot
plt.plot(points, (points*w1)+b , linestyle = '-', label = "fit")
【讨论】: