【问题标题】:Not giving a perfect linear regression没有给出完美的线性回归
【发布时间】:2020-11-13 13:39:13
【问题描述】:

我正在尝试通过 scikit 模块绘制线性回归,但它给出了错误的回归。

x=b[['year']]
y=b['pf_score']
l=LinearRegression().fit(x,y)
plt.plot(x,y,'bx')
plt.plot(x,l.coef_*x+l.intercept_,'r-')
plt.show()

【问题讨论】:

    标签: python machine-learning scikit-learn linear-regression


    【解决方案1】:

    尽量不要直接使用线性回归模型的系数。最好使用提供的功能。这样的事情应该可以工作:

        x = b[['year']]
        y = b['pf_score']
        l = LinearRegression().fit(x,y)
        plt.scatter(x, y, 'bx')
        plt.plot(x, l.predict(x), color='blue', linewidth=3)
        plt.show()
    

    您可以通过 scikit-learn 找到有关 Linear Regression Example 的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-19
      • 2020-06-10
      • 2012-06-27
      • 1970-01-01
      • 2020-08-26
      • 2017-12-16
      • 2020-11-12
      • 2012-07-28
      相关资源
      最近更新 更多