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

问题描述 投票:0回答:1

如何将由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 ml
1个回答
0
投票
from numpy.polynomial.polynomial import polyfit b, m = polyfit(x, y, 1) pyplot.plot(x, b + m * x, '-')
© www.soinside.com 2019 - 2024. All rights reserved.