Machine Learning Tutorial Python - 3: Linear Regression Multiple Variables
In this machine learning tutorial with python, we will write python code to predict home prices using multiple variable linear regression in python (using sklearn linear_model). Home prices are dependent on 3 independent variables: area, bedrooms and age. Pandas dataframe is used to fill missing values first and then use that dataset to train a multivariate regression model.You can use exercise at the end to consolidate your understanding on whatever you have learnt in this machine learning tutorial.
#MachineLearning #PythonMachineLearning #MachineLearningTutorial #Python #PythonTutorial #PythonTraining #MachineLearningCource #LinearRegression #sklearntutorials #scikitlearntutorials
Code: github.com/codebasics/py/blob...
(Exercise is at the end of the ipynb notebook so just open that file and read through)
Exercise solution: github.com/codebasics/py/blob...
Topics that are covered in this Machine Learning Video:
0:00 Linear Regression With Multiple Variables:
0:48 Data set
2:07 Linear Equation
3:28 Load Data in Pandas Data Frame
4:16 Data preeprocessing (Handle Missing Values)
6:17 Train Lemear Model
8:18 Predict home prices using trained model
11:35 Exercise to predict hired candidates salary based on few parameters
Topic Highlights:
1) Data Preprocessing Handle Missing Values
2) Linear Regression Using Multiple Variables
3) Train Lemear Model
4) Exercise to predict hired candidates salary based on few parameters
Do you want to learn technology from me? Check codebasics.io/?... for my affordable video courses.
Next Video:
Machine Learning Tutorial Python - 4: Gradient Descent and Cost Function: • Machine Learning Tutor...
Very Simple Explanation Of Neural Network: • Neural Network Simply ...
Populor Playlist:
Data Science Full Course: • Data Science Full Cour...
Data Science Project: • Machine Learning & Dat...
Machine learning tutorials: • Machine Learning Tutor...
Pandas: • Python Pandas Tutorial...
matplotlib: • Matplotlib Tutorial 1 ...
Python: • Why Should You Learn P...
Jupyter Notebook: • What is Jupyter Notebo...
To download csv and code for all tutorials: go to github.com/codebasics/py, click on a green button to clone or download the entire repository and then go to relevant folder to get access to that specific file.
Tools and Libraries:
Scikit learn tutorials
Sklearn tutorials
Machine learning with scikit learn tutorials
Machine learning with sklearn tutorials
🌎 My Website For Video Courses: codebasics.io/?...
Need help building software or data analytics and AI solutions? My company www.atliq.com/ can help. Click on the Contact button on that website.
#️⃣ Social Media #️⃣
🔗 Discord: / discord
📸 Dhaval's Personal Instagram: / dhavalsays
📸 Codebasics Instagram: / codebasicshub
🔊 Facebook: / codebasicshub
📱 Twitter: / codebasicshub
📝 Linkedin (Personal): / dhavalsays
📝 Linkedin (Codebasics): / codebasics
🔗 Patreon: www.patreon.com/codebasics?fa...
Пікірлер: 703
To learn AI concepts in a simplified and practical manner check our course "AI for everyone": codebasics.io/courses/ai-for-everyone-your-first-step-towards-ai Do you want to learn technology from me? Check codebasics.io/ for my affordable video courses.
@honeymilongton8401
2 жыл бұрын
hii sir if possible can you please post slides also sir
@sglanka4335
2 жыл бұрын
Sir i am your fan now, i finished my degree in statistics ,mathematics ,and computer scinece but we did not have any practise In machine learning , i am following you and try to learn in this very well and after that i want to build my own company , currently i am working as a combined maths teacher but i need to change my career as a data scientist , i love to learn from you sir
@Great_achievement
Жыл бұрын
Hello Do you do data analysis... I want to know the charges.. How can I approach you sir.
After reading that you do this tutorial after 9 to 6 job I really appreciate your work and now I can understand why you take time to make a new video. It's really hard to give weekend for making videos because we already have lot of other things to do at weekend. Thank you so much for all the effort you put it's really awesome.
You are gifted with a great skill of conveying difficult things in an easier and simpler manner! Excellent work!
@codebasics
3 жыл бұрын
Thank you! Cheers!
@narottamaswal3978
3 жыл бұрын
@@codebasics Sir if I take the same area, rooms and age given in the csv then why its not showing the same price as that ?
@limbadhiren
Жыл бұрын
@@narottamaswal3978 yaa median are different...
@edu_tech7594
4 ай бұрын
@@limbadhiren I got the median value 4
Hi there, i have watched a few of your videos on Pandas and LinearRegression since this morning and I must say, it is very easy to follow you. I appreciate you are not too fast allowing time to catch up. Thanks for the learnings.
Just wanted to thank you for your awesome teaching, keep up the good work! From all the content I've seen, yours is the most "hands-on" the perfect combination of theory and exercises applying said theory!
After going through many youtubers, tutors, I was not able to start with the ML concepts,coding. Your content is awesome, very easy to understand. Thanks for these videos & your time. Appreciated...
@codebasics
5 жыл бұрын
I am glad Ketan that this was useful to you.
This video was posted 6 years ago but it's still very helpful and very understandable, when people on KZread were talking about linear regression i thought building a model would be very hard but it seems a bit easier and also sir you have an excellent talent to teach harder things to people like me . Thank you very much .
Most unrated vedio for regression I watched 5 videos including nptel,'s and edureka but you are great deserves millions like
Thanks a lot - really helped me out here. So many videos overcomplicate things, but this was perfect for what I needed!
Great lectures.. You teach in one of the finest ways. I really appreciate your hard work and dedication towards these videos.
Only 3 videos in and I've learned a ton. Thank you so much!
@codebasics
5 жыл бұрын
Glad to hear that Anthony
Amazing videos!! Can't wait to watch upcoming ones on Machine Learning!
@meethamin427
2 жыл бұрын
yes
You are the best machine learning teacher in KZread. I discovered you so let but i hope i will cover up my project.
Thanks so much for this video, worked perfectly. You teach better than most teachers that have ever tried to teach me to code in my life .
@codebasics
3 жыл бұрын
Glad it helped meow!
I like the way you are explaining terms and logic. I realty appreciate your effort. Please share more video like this. Don't stop to make more video on machine learning. keep it up
@codebasics
5 жыл бұрын
Soham thanks for the comment, yes I am continuing ml series with deep learning now
@travelclimb
4 жыл бұрын
@@codebasics very helpful! Thank for the videos and playlist
Thank you for your efforts to explain us all these concepts in a soft way. I really appreciate
sir, you have explained ML in such a easy way..thanks
Thank you! Here's a comment to boost your KZread algorithm! You deserve it.
Hey, first of all thank you for the great tutorials. I'd like to point out one thing. Regression with multiple variables is "Multiple Regression" and not "Multivariate regression", unless we are predicting more than 1 outcome. Since in the video you are predicting only the price, i.e., only one output, it's "Multiple Regression".
@jamestanaka686
3 жыл бұрын
Yes, this video is about univariate multiple linear regression. I am actually looking for multivariate case.. I have a question here that is multivariate case just a repeated method of univariate case i.e. doing univariate iteratively for multiple DVs is equivalent to multivariate case?
@shahbazpathan1228
3 жыл бұрын
I spent half an hr to clear this confusion. Indeed, it is a multiple regression.
you are genius sir i learnt today many things my institute should watch your videos that how to teach students swiftly.. thanks a lot sir continue helping us...
I learnt so many things in this tutorial ,Thank you.It is great tutorial.
Thank you SO much for providing this video for free!
This is a great tutorial... I am starting my ML journey and your tutorial helped me learn in an easy way. Thank you
For the exercise, to change the object numbers to int, we can also use the Lambda function as follows: df.experience = df.experience.map(lambda x:w2n.word_to_num(x))
@VikasSharma-ck1wx
4 жыл бұрын
this snippet is not working throwing an error for using word 2 number file and showing error with word_to_num method
@priyanshunegi
3 жыл бұрын
Thanks buddy..👍
@SS-rz6rp
2 жыл бұрын
@Jai Sharma try this: df.experience=df.experience.apply(w2n.word_to_num)
@kakumanigayatri5701
2 жыл бұрын
@@SS-rz6rp still showing same error. i think this is due to NaN. will you pls explain this. i am confused
@Fatima-gw7sm
2 жыл бұрын
@@kakumanigayatri5701 what type error?
I spent so many hours trying to find answers and you answered all my questions in the video. Thank you very much! Excellent explanation!
@codebasics
3 жыл бұрын
Great to hear Elenie!
@jayvardhanjagarwal8973
3 жыл бұрын
Sir u know what is wrong here. When u predict price for area=3000, badroom=3 and age=40 then it will be 44000 (approximately) but when u change the age=15 in this. Then price 100% less then 56000. But your prize is increased in this case which is abnormal. Can u explain it.
@dulangikanchana8237
3 жыл бұрын
@@jayvardhanjagarwal8973 when the house is older the price of house value decreases.so that is why for area=3000, bedroom=3 and age=40 then predicted price will be 444,400 but when house is bit younger at same other features area=3000, bedroom=3 and age=15, predicted house price is 615,000. Yet i his actual data set for the features area=3000,age-15.bedroom=4, the actual price is 565,000, which is less than his predicted value for a house which is 15 years old,yet 3 bedrooms, as his model has a bit skewness.we cant expect models to be 100% accurate.but when they like over 80% accurate we use such models for our work purposes as they are fairly good models,difficult to get as such 80% or more accuracy
@meethamin427
3 жыл бұрын
hey did you solve the problem ?? can u please send me the code , I am having problem to change the experience column in string to int
I very much like this tutorial. Thank you so much for providing this tutorial. :)
Coolest personality of Machine Learning Knowledge. Thanx sir. Stay Blessed Always. A lot of prayers for you.
7:44 reg.coef_ output => array([ 3 coefficients ])
This man teach in very easy way, while I'm so confused with linear and multiple regression, it give me a satisfied answer and rielf so, thanks❤ 😇
Great tutorial, really clear and easy to understand!!
Your videos are saviour and i was trying to learn ML from different sources but still find your tutorials the best. You have nice & crisp explanations. One humble request please upload more videos on ML.
@arrahman100
5 жыл бұрын
@@codebasics I pray for good health and will wait for more videos..Happy Diwali!!
Very helpful, very clear! Thank you so much!
It would be nice to show the R^2 and which independent variable is effecting the dependent variable the most. This would allow people to know which variable to focus on when buying a house. I’ve never used Panda but it’s a simple line of code in R.
Awesome examples brother with explanation - :)
Exercise result: reg.predict([[2,9,6]]) >>>array([[53205.96797671]]) reg.predict([[12,10,10]]) >>>array([[92002.18340611]]) Note : my result is little bit different from your "exercise_answer.ipynb" because you told to take meadian of test_score but did mean. your result: reg.predict([[2,9,6]]) >>>array([[53713.86677124]]) reg.predict([[12,10,10]]) >>>array([[93747.79628651]]) Thanks for this amazing tutorial
@eternalsgaming2467
3 ай бұрын
Can you tell how did you convert the experience string column to integer
@chetankumar5190
3 ай бұрын
@@eternalsgaming2467 from word2number import w2n df = pd.DataFrame(df) # Function to convert experience string to number and handle NaN def convert_experience(x): if pd.isna(x): return 0 # Replace NaN with 0 try: return w2n.word_to_num(x) # Convert text to number except ValueError: return 0 # Replace non-convertible strings with 0 # Apply the function to the 'experience' column df['experience'] = df['experience'].apply(convert_experience) # Print the DataFrame after conversion print(df)
@Tuoc_Nguyen
2 ай бұрын
@@eternalsgaming2467 import word2number word_list = df1.experience list_number = [] word_list = word_list.dropna() for word in word_list: number = w2n.word_to_num(word) list_number.append(number) df1.loc[~df1.experience.isna(), 'experience'] = list_number this is my way
@priyam4680
Ай бұрын
@@eternalsgaming2467 dfHiring['experience'] = dfHiring['experience'].apply(lambda x: w2n.word_to_num(x) if isinstance(x,str) else x) dfHiring['experience'] = dfHiring['experience'].fillna(0)
The videos are truly excellent! Although I rarely leave comments on educational videos, your concise video series has been incredibly beneficial to me. I appreciate the way you seamlessly integrate teaching with practical coding examples. Keep up the great work
Your lectures is so good. At first I faced some problems for the word to number function. Even after installation I write "from word2number import w2n" on my code, but it wasn't work. Then I restart my jupyter notebook & now it is working well. :D
you helped me with my final project. huge thanks
Thank You Very Much Sir You are saving the lives of lot of students ✨
These are really amazing video lectures for Machine Learning and start off with. Thank you.
Very well explained. Thank you sir!
You are really awesome.... Please make more videos..... I can easily understand your tutorial....
Thank you for the explanation, I have just started with machine learning in Python and it was really helpful.🙏 Just nitpicking being from math background, the value for the field NaN will be min 4, to make sense of the dataset. 😅
Thank you so much !!!!! very easy to learn from your tutorial.
Thank you sir. You are doing a great job. Keep inspiring us.
awesome job man you taught me in 10 minutes how to do something my professor couldnt teach me over a couple of lectures
@codebasics
3 жыл бұрын
I am happy this was helpful to you.
Amazing tutorial. Extremely easy to grasp. thankyou!
@codebasics
5 жыл бұрын
Karan, I am happy you liked the content.
Thank you so much! Pl. keep up the good work
Your all videos are fabulous....Keep it up & thanks for making such a amazing videos....
Thank you for this helpful tutorial, I like the way your style,crystal cear and easy to follow.
@codebasics
4 жыл бұрын
Dear, Thanks for your kind words. Stay in touch for more videos and share our channel if you really find it worth.
@shailypatel585
3 жыл бұрын
@@codebasics why we use median ??? why not mean?? ca i use somthing else instead of median?
Beautiful tutorial thanks much!
so well explained..the best tutorial in youtube for machine learning..made it so easy to understand
@codebasics
4 жыл бұрын
👍😊🙏
Great video. As per my understanding, Linear regression with multiple variables and multivariate regression are two different concepts. Linear regression with multiple variables deals with a single dependent variable and multiple independent variables, while multivariate regression deals with multiple dependent variables.
Thank you very much, sir. Really appreciated. Lots of love from Turkey.
@codebasics
3 жыл бұрын
I am happy this was helpful to you.
Thank you .. just got what exactly I need ... Thanks lot !!!
Very informative video... thank you
Thanks as always for teaching us Sensei
In an actual case in work, there are many columns variables more rows that could run into thousands of rows, close to a hundred columns in which the interaction is not obvious. Agreed the first step is data preparation, data cleansing all NaN, missing rows/column elements given such situation it would better to do a preliminary data exploration by data mining or designed experiment to see what interacts what for what. This is the only time you can actually write out the linear equation actually which are composed of independent variables that either reinforce the prediction (all positive polarity} or that contradict it (all negative polarity).
@irizk1
4 жыл бұрын
I agree with you... In real life data is much more complicated. Specially when we have multiple dependent variables as well instead only one....In real life scenarios thousands of variables (both independent/dependent) interact each other. To create a model for such a scenario is really challenging and benefit of AI can only be realized then....
very good contribution to the learners..Thank you so much..
Thank you for your help bro. I am waiting for your new video, please try to upload as much as possible.
awesome, thank you mai friend, i needed that
Thanks a ton!. This helped me a lot.
@codebasics
4 жыл бұрын
👍👍👍👍
another great video, thanks. I slightly disagree with example setting and how you solved it. I think that average would be better for test score, not median as in main tutorial with house pricing. But even assuming that median would be better, you don't have to floor the median in this example, as you did with bedrooms. Obviously, bedrooms cannot be 3.4 or 5.6, but median or average test scores, especially for building an accurate linear model - can and should be. Thus my answer is slightly different - 53205 and 92002. Though, it is more art than hard science (average vs median and whether to round the median or not) and your tutorial and example were great, as usual. PS Did not know about word2number - neat idea. Though they say it should not work with 3.6 i have not had any problems with it.
Wonderful tutorial Teach! Would like to know 'how to plot scatter plot from multiple independent variables and one dependent variable', which I think is the only missing piece in the video. Thanks in advance
Good job! Thank you!
Good job~ Thank you~ Big hug from China.
Hey, have you ever done mulvariate multiple regression with several dependent variables (statistics used MANOVA, MANCOVA)? Would like to see a video on that especially explanation of benefits over several ANOVAS.
The way you are explaining, means you love teaching. I am a teacher, and on the basis of my experience I must say that you should teach in engineering colleges may part time.
@helloworld2740
2 жыл бұрын
sir he is already teaching in colledge Thank you
Thank you so much for your very helpful tutorial. I have learned many more from your videos. Keep going, sir.
@codebasics
4 жыл бұрын
Sohag I am happy that this is helping you 😊
Actually got the clarity of the topic. Thank you for this video.
@shibojitbhattacherjee923
3 жыл бұрын
what's the mean_square_value you're getting?
Seriously sir its really soooo helpful for me, thank you sir for your hard work for us
Really awesome 😍
nice video helps a lot Thx !
Thanks for providing amazing video Now I got to know about that codebasics is one of the top Indian channel for data science because you were uploading quality video with God explainetion from starting only I have seen many people they create short video and they just explain very easy concept so that people will feel bored and they will more reach to their channel and video
9:00 Now, we can find the predicted price of a house using the values we obtained. We have the equation, price = m1*area + m2*bedrooms + m3*age + b Now that we know the coefficients, m1, m2, m3, and the intercept, b, we can find the price. The given, the values of the three features will give us the predicted price, will be saved in our object variable,
GREAT VIDEO SIR HELPING THOUSANDS
Thank you very much Sir. I am going to use this tutorial to handle a contract.
Good video, thank you!
Your instructions are very clear and easy to follow. It makes learning more easier and stress free.. thanks for helping..
@codebasics
3 жыл бұрын
😊🙏
great tutorial man. thank you
First, thank you so much for this video. Second, I would like to ask how to get the p-value, R squared and adjusted R squared? Thanks again.
Thank you Sir for this excellent video
Excellent approach U saved my time
@codebasics
3 жыл бұрын
Glad it helped
that's very good sir, thank you
got the same answer as given in exercise. thank u
Finally got the best machine learning tutorial please upload full machine learning series sir Thank u
@codebasics
5 жыл бұрын
good to hear you liked it Piyush.
Beautiful!
excellent delivery.
Hi, This works. First fill the blanks in the experience column with 'zero' ... and then use w2n.word_to_num df.experience = df.experience.fillna('zero') df.experience = df.experience.apply(lambda x: w2n.word_to_num(x))
@vidhanmaheshwari2082
4 жыл бұрын
Thanks @Sneha Datta , it helped.
@ankitgaur7695
3 жыл бұрын
Thanks a lot from where you got this code - " df.experience = df.experience.apply(lambda x: w2n.word_to_num(x))" why you have used "lambda x" it is not given in the original documentation at - pypi.org/project/word2number/ i also checked the word2number official code snippet at github managed by the original contributer "Akshay Nagpal" -- github.com/akshaynagpal/w2n/blob/master/word2number/w2n.py.
@jaishankerkhatri1288
2 жыл бұрын
This really helped a lot! Thanks :)
Thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou thankyou ❤️❤️❤️❤️❤️❤️❤️❤️❤️ watched all videos at a time ....before I feel like don't I understand these topics ..but u made this topic easy 💫❤️
@codebasics
3 жыл бұрын
Most welcome 😊 I am happy this was helpful to you.
thanks super upload!!
Hi Sir If you upload all slides which is already discussed in your course it will be great. Thanks
Please make a video on polynomial regression, and solving overfitting
Helped me so much. You make my understanding about linear regression like liquid.
@codebasics
3 жыл бұрын
Glad it was helpful!
Very helpful and appreciate your way of teaching
@codebasics
3 жыл бұрын
I am glad you liked it
nice video, it helps a lot for beginner like me, thank you very much :D
@codebasics
5 жыл бұрын
Great, this is indeed designed for beginners only.
Really nice tutorial.
Also, if one of the series has a boolean datatype, does the regression automatically convert the series to 1's and 0's?
excellent video...Please Keep making more videos!!
@codebasics
4 жыл бұрын
Hey Vandana, Thanks for your kind words. Stay in touch for more videos and share our channel if you really find it worth.
sir iam learning from your tutorial your really an amazing teacher. thank you very much sir
@codebasics
3 жыл бұрын
You are most welcome Jan Nisar