Polynomial Regression in Machine Learning | Easy Explanation with Python In this video, we cover what is Polynomial Regression, how it works, how it’s different from Linear Regression, etc. We also build a Polynomial Regression model in Python using sklearn and visualize our results. This video is perfect for beginners who are learning Machine Learning Tutorials! TimeStamps: 00:00:00- Introduction 00:00:14- Polynomial Regression? 00:00:40- Equations 00:01:27- Example 00:02:15- Quadratic Polynomial Regression Equation 00:02:53- Python example 00:13:25- Polynomial Regression Advantages 00:13:40- Polynomial Regression Disadvantages 00:13:54 - Conclusion 👍 Like, Share, and Subscribe for more videos on: Python | SQL | Artificial Intelligence | Generative AI | Machine Learning 🔔 Hit the bell icon to stay updated with our upcoming videos! 🔴 Subscribe to our channel to get video updates. Hit the subscribe button above: https://goo.gl/6ohpTV Do not miss: Machine Learning- https://youtube.com/playlist?list=PLQtyrrKdUiv3x1vNumlRJlxI1EyqEXbRA&si=_zEDO3fPNxIcU11B Python Tutorials - https://youtube.com/playlist?list=PLQtyrrKdUiv2p1IEmuXRZu4F2P87mt4as&si=rmuRuSDzf6YpsTKf Generative AI (GenAI) - https://youtube.com/playlist?list=PLQtyrrKdUiv2Xd4Dp_N4gJAy_hP8Mpy4N&si=GYNXt6e_2ckwWXSq SQL - https://youtube.com/playlist?list=PLQtyrrKdUiv2p1IEmuXRZu4F2P87mt4as&si=OiDkstzQRAuX5WDo #polynomial regression #sklearn #beginners #tutorial #supervisedlearning #machinelearning
Full Transcript
[Music] Welcome back everyone. We are at day six of our machine learning series. In today's video, we are going to learn about polomial regression. So let's get started. What is polomial regression? Polomial regression is an extension of linear regression where the relationship between the dependent variable and independent variable is more or less nth degree polomial. In many real world scenarios, the relationship between variables is often nonlinear. Polomial regression helps us to model this kind of cob data points by adding higher degree power of x. Polomial regression equation. The equation of linear regression is y = b 0 + b1 x + e where x is the independent variable, y is the dependent variable, b 0 and b1 are the coefficients, e is the error. Similarly, the equation of polomial regression is y = b 0 + b1 x + b2 x² + b3 x cq plus bn xn plus error where x is the independent variable, y is the dependent variable, b 0, b1 to bn are the coefficients of polomial, n is the degree of the polomial and e is the error. Example, let's consider an example of predicting house prices where we analyze the relationship between the price of the house and the size of the house. The relationship between these two factors might not be linear. So let's see this table. Here we have two parameters. One is house size and the other is house price. As soon in this table we see from 20 square m to 70 square m the price of the house increases very fast. Whereas after 70 the price of the house slows down. Now let's plot this in graph. So this is our data. When we see these data points we realize that a linear or the straight line won't fit well in this situation. Therefore for this type of data we need polomial regression. Quadratic polomial regression equation. Now let's apply polomial regression to model the relationship between the size of the house and the price of the house. Suppose if we try a quadratic model that is degree= to 2 which include both linear and the quadratic terms for better fit. The quadratic polinomial regression equation is y = to b 0 + b1x + b2 x². So by using this polomial regression equation it allow the cob to bend and fit the data better. In this way, it will capture the nonlinear progression of the house price and its size. Now let's implement this and see in the Python code. Now let's practice polomial regression in Jupyter notebook. So has polomial regression. At first we'll import libraries. So import libraryies import numpy as np. So numpy is used to create data arrays and it is for numerical operation. Another is import uh mattplot li do pip plot as plt. So mattplot lib dotpipplot will help to visualize the data and fitted line. Next is I will write from sklearn dot linear model import linear regression. So in this case we will import linear regression which is the regression model from scikitlearn. Another is from sklearn dot preprocessing uh sorry import polomial features. So here we import polomial features class from the sklarn preprocessing model in scikitlon. The next step is to create the data set. So create data set the one parameter we have is house price right house price and then I will represent is x and then np dot array here and I will give the data like 20 30 40 50 60 70 80 90 and then close this parenthesis and then I will reshape and -1 comma 1 and parentheses. So x is the house size which is our uh sorry this is house size. Okay. So x is the house size which is our input and this is independent variable and another is house price that is y equals to np dot array and then I will give the values like 155 190 20, 220, 245, and then 260, and then 265, 270, and closing the parenthesis. So, so this is Y where we store our house prices. So these are the data and this uh dot reset minus one comma 1. This code will receive the data into a column vector. The next step is to transform features into polomial degrees like transforming uh features into polomial polomial and then the degree is let's say 2. So I will write poly equals to polomial features and then I will mention the degree equals to two. So this line means we are creating a polomial features object named poly. degree equals to 2 means it is for quadratic and it will use like 1 comma x² and if it is three then it's for cubic model. So we will use like 1 comma x² x cube. But if it is 1 then it is for linear. And the next line is x poly equals to poly uh dot fit transform and then x. So this will transform input data into polinomial form. Next step is to train the model. So train the model. Model equals to linear uh regression and then this. So this line will create a linear regression model object. Even though we are doing polomial regression, we'll still use linear regression because technically polomial regression is equal to linear regression on polomial features. And then another is I will write model dot feet and then uh I'll give sorry x poly and then y. So this fit means to train the model. Another step is to make prediction. So prediction y [Music] pred prediction equals to model dot predict and then x only. So after training the model, the model has learned the best equation for our data and this dotpredict is used to make prediction using that equation. Another step is to visualize. So has visual lies. So plot dot scatter and then x comma y comma and then I will give color equals to blue comma label equals to um actual data and then close the parenthesis. So this scatter plots the actual data points and in the blue dots and another is plt dot plot and then x comma y grid and then color equals to red and then label equals to polomial regression. So this dot plot will draw the regression line predicted by the model in red. And then plot dot x label and equals to like house size and in square meter. S² m and then okay this x label is for labeling x-axis another is for labeling y-axis y label and this is like house price and in $1,000 and okay now let's do plt.end present and then plt dot so okay this so will display the plot now let's run this code and see what is the result here is error xore pulley okay this one poly.fit transform x. So here is the error I think f r mm. Yeah. So yeah this is the result. See we get the curve line. But if the you know degree of the polomial is one let's see and run. See we get the linear line. So it does not cover all of the data points. That's why we do the polinomial regression like this. Polomial regression advantages more flexible that means it is more flexible than linear regression better fit. It is better fit as it can capture nonlinear trends in the data. Polomial regression disadvantages complex. They are more complex and computationally expensive for highderee polomials. Overfitting highderee polomials can bend too much and fit noise. Okay, that's all for polomial regression. We understand polomial regression is an extension of linear regression for nonlinear relationships and it works by adding high powers of input features. Therefore, it is a powerful method for handling nonlinear data in machine learning. In the next episode, we'll learn about logistic regression. Thank you for watching. If you like this video, do not forget to like, share, and subscribe my channel. See you in the next video.
Original Description
Polynomial Regression in Machine Learning | Easy Explanation with Python
In this video, we cover what is Polynomial Regression, how it works, how it’s different from Linear Regression, etc. We also build a Polynomial Regression model in Python using sklearn and visualize our results. This video is perfect for beginners who are learning Machine Learning Tutorials!
TimeStamps:
00:00:00- Introduction
00:00:14- Polynomial Regression?
00:00:40- Equations
00:01:27- Example
00:02:15- Quadratic Polynomial Regression Equation
00:02:53- Python example
00:13:25- Polynomial Regression Advantages
00:13:40- Polynomial Regression Disadvantages
00:13:54 - Conclusion
👍 Like, Share, and Subscribe for more videos on:
Python | SQL | Artificial Intelligence | Generative AI | Machine Learning
🔔 Hit the bell icon to stay updated with our upcoming videos!
🔴 Subscribe to our channel to get video updates.
Hit the subscribe button above: https://goo.gl/6ohpTV
Do not miss:
Machine Learning- https://youtube.com/playlist?list=PLQtyrrKdUiv3x1vNumlRJlxI1EyqEXbRA&si=_zEDO3fPNxIcU11B
Python Tutorials - https://youtube.com/playlist?list=PLQtyrrKdUiv2p1IEmuXRZu4F2P87mt4as&si=rmuRuSDzf6YpsTKf
Generative AI (GenAI) - https://youtube.com/playlist?list=PLQtyrrKdUiv2Xd4Dp_N4gJAy_hP8Mpy4N&si=GYNXt6e_2ckwWXSq
SQL - https://youtube.com/playlist?list=PLQtyrrKdUiv2p1IEmuXRZu4F2P87mt4as&si=OiDkstzQRAuX5WDo
#polynomial regression #sklearn #beginners #tutorial #supervisedlearning #machinelearning