How do add the linear regression line generated by the ML model to the scatter plot?
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()
You can try:
from numpy.polynomial.polynomial import polyfit
b, m = polyfit(x, y, 1)
pyplot.plot(x, b + m * x, '-')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.