0

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()
Andreas Rossberg
  • 34,518
  • 3
  • 61
  • 72
  • right before the show, you can say `pyplot.plot(x,y)` – gnahum Apr 12 '20 at 16:37
  • Does this answer your question? [How to overplot a line on a scatter plot in python?](https://stackoverflow.com/questions/19068862/how-to-overplot-a-line-on-a-scatter-plot-in-python) – Laurent LAPORTE Apr 12 '20 at 16:44
  • Since you seem to be new to Stack Overflow, you should read [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Sheldore Apr 12 '20 at 17:48

1 Answers1

0

You can try:

from numpy.polynomial.polynomial import polyfit

b, m = polyfit(x, y, 1)
pyplot.plot(x, b + m * x, '-')
Laurent LAPORTE
  • 21,958
  • 6
  • 58
  • 103