Welcome to the 9th part of our machine learning regression tutorial within our Machine Learning with Python tutorial series. We’ve been working on calculating the regression, or best-fit, line for a given dataset in Python. Previously, we wrote a function that will gather the slope, and now we need to calculate the y-intercept.
https://pythonprogramming.net
Tweets by Sentdex
https://www.facebook.com/pythonprogramming.net/
https://plus.google.com/+sentdex
yes now i understand what is this , love from india
Lovely
thank you for share
It feels like you need to learn Math first, before diving into this?
I hope you make vids about translating mathematic or statistical equations into python functions. I’m looking forward to seeing it.
Nice vids by the way.
I’m new to coding. I wrote code in google document and. Nothing happening.
My Python doesn't like , dtype = np.float64 It shows: TypeError: unsupported operand type(s) for ^: 'numpy.float64' and 'int'
Hello sentdex, I tried same code whatever u explained in Jupyter but not getting the best fit line due to this error in below syntax
plt.plot(xs,regression_line) ValueError: setting an array element with a sequence. help me out.
suddenly started giving me more floating points value after adding intercept to return of the method
➜ Regression python algo1.py
-15.268707483
➜ Regression python algo1.py
0.428571428571
➜ Regression python algo1.py
(0.42857142857142866, 4.0)
I did not understand the ""regression_line = [(m*x)+b for x in xs]"" part .
Does it create a list/array of values of y for each value of x?
I cannot take people seriously who start a conversation with a question they don't expect an answer to. Btw: I won't tell you 'what is going on'.
I'm having problems reproducing the best fit slope equation with some values.
For example, if I use y = 2*x:
xs = np.array([1,2,3,4,5, 6])
ys = np.array([2,4,6,8,10,12])
using the slope equation from the video gives a wrong answer, while adding the value 0 to xs and ys gives the right one.
I ended up using another approach:
def best_fit_slope_and_intercept(xs, ys):
X = xs – xs.mean()
Y = ys – ys.mean()
m = X.dot(Y) / (X.dot(X))
b = ys.mean() – m*xs.mean()
return m, b
found here:
https://math.stackexchange.com/questions/2565098/vector-notation-for-the-slope-of-a-line-using-simple-regression/2642719#2642719
and to check if it's okay:
from scipy.stats import linregress
print(linregress(xs, ys))
booom
great vid. i wish you could explain the math behind the formula and why it works a bit more though.
just to say that every 6th grader is basically a data scientist/machine learner since one does that stuff in high school 🙂 Seriously, (as you already pointed out) linear regression is not a machine learning technique but a fundamental statistical tool (so are PCA, decision trees etc.) Every scientist uses that stuff every day and might have never heard of machine learning. Great tutorial anyway!!!
Is there any way to do the regression line using numpy. I have read that using for loops or list comp is significantly slower than using numpy due to the vectors in numpy.
great videos Harrison! My data science professor recommended your channel to me and this is like the 6th or 7th series I've been watching! Keep up the good work! You are such a great teacher!
Man, congratulations for your job, that's too good! I'm learning a lot with your videos and I hope you continue making good videos as this one ? thnks
Awesome video series man, thank you!
i have tried predicting some more point and i found that it is on the same line..so then it is correct or prediction is done according to regression line..i am not getting so please reply
I don't know what's funnier. The fact that you messed up m*x as M8x, or the fact that I typed that along with you not even thinking about it.
cool u made it easy but what is the use of from matplotlib import style and style.use……
Thanks sentdex! I'm just starting to explore machine learning and your tutorials are perfect. Really enjoying them
Your really awesome intelligent and Thanks a lot to share knowledge on Machine learning with Python.
I really appreciate for the content being taught and the way they are taught.
I think that the coding tutorials(starting ones) would have been better understood if these(ep 7,8,9) were taught first.
Isnt R better to make regressions ?