如何在此散点图中添加线性回归线?

时间:2020-04-12 16:36:06

标签: python matplotlib linear-regression

如何将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()

1 个答案:

答案 0 :(得分:0)

您可以尝试:

from numpy.polynomial.polynomial import polyfit

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