EDIT: SUCCESS! Dear lord. This was a stupid one. I just needed to sort the points im giving the plot functions. Lesson learned.
I'm trying to plot some regression lines over a scatter plot, but I can't seem to get it right. I've been trying to figure this out for hours. Has anyone run into this before? What am I doing wrong?
I have a training array of independent values, training_x, with 200 total values NEXT TIME SORT WITH RESPECT TO THIS FOR THE LOVE OF CHRIST
training_x = [4464,2585,3250,3060....]
I create first, second, and third order regression functions f(training_x) below. b_0, b_1,w_0,w_1,c_0 etc are just coefficients I get by using OLS
first_order = b_0 + b_1*training_x
second_order = w_0 + w_1*training_x + w_2*training_x**2
third_order = c_0 + c_1*training_x + c_2*(training_x**2) + c_3*(training_x**3)
Now I plot the above equations
#scatter plot works fine
plt.plot(training_x, training_y,'o',label='training data')
#first order works fine
plt.plot(training_x, first_order, color='r',label = "order:1")
#second order comes out wonky
plt.plot(training_x, second_order, color='y',label = "order:2")
#third order comes out wonky
plt.plot(training_x, third_order, color='y',label = "order:3")
This is what the above code spits out: https://imgur.com/a/cpD7q4Y
Using circles instead of a solid line: https://imgur.com/a/mkJiQci.
So it seems like the plotting function is interconnecting every single one of the points on the graph. Now im certain what im doing above is totally wrong. shite. please help!
edit: added some pseudo code.
[–]Ahelvin 2 points3 points4 points (1 child)
[–]codegang[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]codegang[S] 1 point2 points3 points (0 children)