【问题标题】:How do I add a linear regression line to this scatter plot?如何在此散点图中添加线性回归线?
【发布时间】:2020-04-13 00:50:14
【问题描述】:

如何将ML模型生成的线性回归线添加到散点图中?

pickle_in=open("student-model.pickle","rb")
linear=pickle.load(pickle_in)

acc=linear.score(x_test, y_test)
print(f"accuracy= {round(acc*100,2)}%")

#comment: for scatter plot
style.use("ggplot")
p="G1"
pyplot.scatter(data[p],data["G3"])
pyplot.xlabel(p)
pyplot.ylabel("Final Grade")
pyplot.show()

【问题讨论】:

标签: python matplotlib linear-regression


【解决方案1】:

你可以试试:

from numpy.polynomial.polynomial import polyfit

b, m = polyfit(x, y, 1)
pyplot.plot(x, b + m * x, '-')

【讨论】:

  • 它没有用。错误是:“TypeError:x 的预期一维向量”
猜你喜欢
  • 2016-02-24
  • 2012-06-27
  • 1970-01-01
  • 2021-01-28
  • 2016-11-01
  • 1970-01-01
  • 2015-01-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多