# Machine Learning Tutorial Python – 2: Linear Regression Single Variable

## 48 thoughts on “Machine Learning Tutorial Python – 2: Linear Regression Single Variable”

1. yash watwani says:

It is giving a error in reg_predict —
ValueError: Expected 2D array, got scalar array instead:
array=3300.
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

2. Deepak Gupta says:

what if we use print(reg.predict(arr)) where arr = np.array(2600) then output should be 550000 but answer is coming 533664.38356164 ? can you tell me how ?

3. Muralidharan G says:

plt.xlabel('Year')
plt.ylabel('Income per Capital in US \$')
plt.scatter(df.year,df.income,color = 'red', marker = '+')

reg = linear_model.LinearRegression()
reg.fit(df[['year']],df.income)
reg.predict(2020)

df output

df
Out[36]:
year income
0 1970 3399.299037
1 1971 3768.297935
2 1972 4251.175484
3 1973 4804.463248
4 1974 5576.514583
5 1975 5998.144346
6 1976 7062.131392
7 1977 7100.126170
8 1978 7247.967035

I am getting below error,
Expected 2D array, got scalar array instead:
array=2016.

4. Rahul B says:

where is the path?

5. Skk Kks says:

Keep it up its going very ,very good.Thank you.

6. hfe18 says:

For beginners like it's ideal tutorial,not too fast not to slow

7. Thanh Ngô says:

It is very easy to understand . Thanks you so much @codebasics

8. P korouei says:

Amazing
Thank you

9. nirmal jha says:

10. karthik lv says:

Exercise prediction for 2020 is 41288.69 \$ , yes?

11. Ali Dakhil says:

Very nice

12. Abhishek Raj says:

In year 2019, per capita income of Canada will be 40460 USD.
Is this true?

13. Sunny shailendra says:

i am learning through your videos and its really a solid content for learning.

14. Sushil Kumar says:

15. Somorup Banerjee says:

16. Amritha Nair says:

why is area given as a list of list

17. Yemane Alem says:

Great man thanks alot.

18. Pankesh Patel says:

Thanks for the tutorial!! just a small feedback — You may want to discuss functions and its parameters — the fit(X, y) and predict(X)

p = reg.predict(d)
I am getting error, thanks for answering

20. Maria J. Villacreses says:

great vid!

21. vj sreenivasan says:

Thanks for all the informative videos..
Very interesting & awesome Lectures for beginners!
Machine Learning made simple and exciting

Cna you do this with train_test_split method? And also how do we calculate R square, mean variance and score. Please advise. Thanks.

23. atul bhardwaj says:

Thank you very much for opening the door to what looks like a daunting task of hands-on machine learning. You made it so easy and refined. Kudos!

24. Vipul Shah Gupta says:

Great video indeed! good way of explaining the logic..keep uploading these type of video.

25. Manikandan R says:

I got my Hope from your example only. thanks a lot bro.. subscribed too..

26. rajsamant1 says:

You teach free better than many trainers who takes good amount as fee..thank you sir

27. Mai P says:

WONDERFUL! THANKS A LOT! SUBBED TO YOU

28. Codex says:

wow( 100% (understand & working) )

29. Deepanshu Aggarwal says:

Canana per capita income (US\$) in 2020 comes this 41288.69409442

30. Sumit singh says:

Saw various video but definitely you have explained in the best possible way ,
Can you please provide how to calculate R square or something like that

31. 04nikunj says:

Thank you !!

JUST THANK YOU !!!

Why Area is taken as 2D array in fit(df[['area']],df.price)

They are amazing…..

33. irmscher9 says:

The best tutorial on Machine Learning on Youtube so far! Thank you!

34. pavithra TG says:

import pandas as pd
from sklearn import linear_model
reg1=linear_model.LinearRegression()
reg1.fit(dc[['year']],dc.percapitaincome)
reg1.predict([[2020]])

35. Hrithik Sharma says:

lesson is great it would more fun if in the excercise you give them to make simple linear regression model with just numpy

36. Syed Mannawar Hussain says:

Thanks for excellent tut 🙂

37. Aayush Agarwal says:

Where is the CSV file stored??

38. vinodkumar vicky says:

for 2020

39. George Smith says:

first of all i want to congratulate you on your good tutorials. However I have a problem with scikit-learn-0.20.2. When I reach the reg.predict(3300) I get ValueError: Expected 2D array, got scalar array instead:
array=3300.

40. Jainmiah Sk says:

I don't want to take names but most of the youtube channels for Machine Learning (beginners) are not clear and specific. I fell in love with ''CODE BASICS''. Sir, I'm ready to take your machine learning course will you provide it ?.

41. Sumit Malik says:

reg.predict(3000) did not worked, checked comments and got the answer, Special Thanks to Tutor and all others

42. Subin Nair says:

Dear sir ,
when we enter : d["prices"] = p
why doesn't the prices column get added to "area.csv" file as "d" represents the same flie (and also contains prices column in the output shown) ?
Can you kindly explain this ?

43. Vikas Bansode says:

I have read and watch a lot of article & video on Google and YouTube, every one explained what is machine learning,ML Types,
their algorithms and blah blah.. but actually no one explained how to do it. this is a great channel I found very very useful where everything is explained in very simple way. Thank you very much

44. zero study says:

Man. i've Hope Every one can explain like you!
I would happy to do my homework if my teacher can Explain this crystal clear
2020 net income =41288.69409442 anyone?
what you get?

45. Arun Pani says:

Outputs are showing on Jupyter. May I know why ?

46. mohamed khaled says:

what does mean fit()? when you ignore the fit() method and use predict() method give error in video you said means training but what does mean what actually does?

47. himanshu shekhar says: