How to Visualize Multiple Linear Regression in python

Krish Naik · Intermediate ·📄 Research Papers Explained ·7y ago

Key Takeaways

Visualizes multiple linear regression models using matplotlib for understanding relationships between variables

Full Transcript

well today we'll be seeing how we can actually create a visualization for a multiple linear regression model with the help of matplotlib previously I have already shown a lot of statements on a lot of problems or use cases on simple integration of multiple linear regression so one of the most frequent question was asked that how do we perform visualization how do we show a visualization from an equation now definitely we cannot suppose if in our dataset we have 100 times 100 different features of all that three features we cannot show those dimensions and visually but what we can do is that instead of whenever we have many number of features we can actually create a pair plot and try to steal the dimensions but for three dimension might not live has given a feature where we can see that dimension along the plane that's created from multiple linear regression so this particular problem statement is basically with respect to three features if you have three features in our data set how we can plot that three dimensional features we'll see if you have more than three three dimensions which should basically perform their plot and try to see how our data is actually distributed again it is very difficult to draw the plane for multiple dimensions but with respect to three dimension have done that so in this particular video what I'm going to do is that I'm just going to show you a simple multiple linear regression problem statement and then after creating the model we'll try to find out the test data output and then we will try to create a plane in a three dimensional so to begin with what I am going to do is that I am just going to create a simple X&Y features this is just like my 150 comma hundred roof each other I have as my dependent which I mean why I have one I'm just going to execute this tool before going ahead the output will look something like this let me just show you how the output will look like the output will look something like this where you have your plane and you can move this plane also if you want then see how our data is basically distributed and with the help of multiple linear regression I've actually created a plane which passes and the error you can see it is very very less basically what you use is basically the sum of square and it would study business for instance if you have to dimension just like a simple linear regression you can plot that by using it this is just like a damaged so let us just go ahead and see that what I have done in this particular problem statement this particular notebook file sorry this particular py file will be given will be uploaded in the link will be given in the description of this video you can download it from there and you can draw it for any number of problem statement I made it this code I generate in a generate way you just have to upload the data set and do it so here it is initially I am going to create my X and my data which is X is basically my dependent feature Y is basically my dependents each other then I am converting this into a data frame and for the X these two features I am just giving that giving the features as price and add spends like what is the price of the hat and what you got how much is the heart spend basically for that feature it's just a generate data set that I have created by my own and then my Y dataset is unbasic Elise aying it as sales so this is what I am doing for my F 2 so let me just take C to this truth each statement you can see that you can see or DF 2 and inside my DF you now you have three features price add spends and sends price and add spins are basically our independent feature sales is basically a dependency and after that what I am doing is that I am just importing madcraft lid and Here I am going to use the stock models not formula or API which will actually by using ordinary lease this is another way of applying multiple linear regression if you want use here in the formula you just have to give which are independent features like sales and always remember to give this particular symbol which indicates independent future plus expense is basically your funny scenes is basically your dependent and after the symbol you have all your dependency choose finally you just give the data set which you are stored in the end after that you just remodeled outfit and inside this parents this particular variable dot parents will basically be getting yard it is simply acquisition so as soon as I execute this you can see that there it is you can see that in and consoled you are having intercept price expense for efficient intercept is basically the point where your x-axis or y-axis this is you this is the price for efficient this is that relationship you have this the main part is the visualization stuff make sure you make this mesh great because what happens is that whenever you are drawing in 3d plot it will be expecting the x y&z value in the forest I always remember that when you are doing this much grade you provide the links where you use range space and in that you have to take the minimum price maximum price similarly minimum from nuuma max fine and maximum aspect the reason is that you are going to create a plane right so you need four corner points for that and then you will be joining those points up to that you create a data frame by using this mixer my sub which is which is the values of which is the array which is generated by instant downloads particularly and you can try to run and after that you are just doing a predict for the x value so whatever X data plane you have that you have created is predicting so once you Institute this this this is run perfectly fine then just try to convert this into an array because your math lottery will be expecting that intuitively even data friends can be provided but I am actually trying to do a reshape inside my project so because of that actually converting this into an array and finally my visualization part where I've used not dots either and inside you saw guard it dot add in the subplot this is the number of rows and columns that I want my prediction is 3d you provide this particular feature to indicate it is a 3d diagram and then you do the scatter plot of price I'd spends and sales with the Ranma and here this is for the transparency similarly you provide a dot plot under surface this is the main thing now here you have to actually give you X underscore value Y in the saucer and finally which you have converted into an array you are doing it to be shape of your Xserve which is your other features of x and y dot shape that's it and finally you give me the color if you want to give the color of something else letting me give like is for blue currently let me just give me none and then then you set up your ex label why label and Z label and finally execute this and here is the thing that has come so here you can see your 3d plot very precisely see it see the plane very nicely created you can rotate it and you can see from top bottom view however you want so this is how it looks from the top view similar you can scroll down and see from the left hand side right hand side and see it see the plane how clearly it shows you the plane from here and it is drawn between the points okay I'll let me just try to get some color if you want so I'll just give a loop and let's see here it is your blue paint plane has been really precise and showing it's good because this kind of diagrams are very interactive and you can actually visualize like how your plane has been drawn but it is very difficult to do more than three because those features are not have matplotlib so what we do is that you basically follow a pair plot and again in a two dimensional way we try to see oh this was on all about this particular medium guys I hope you like this particular video many people had asked me this person how to plot visualization for multiple linear regression so because of that I just researched a lot and I have actually come up and like this video please to subscribe this channel please share with your friends like comment and never give up keep on learning this will always help you you should always have that winning attitude I'll see you all in the next video have a great here thank you one at all plot less or

Original Description

Multiple Linear Regression is similar to simple linear regression but the major difference being that we try to establish linear relationship between one response variable and more than one predictor variables. For example suppose that a researcher is studying that how the housing prices are affected by area of the apartment and the demand supply gap in that region. The response variable is apartment price (Y) and the predictor variables are area of apartment (X1) and demand supply gap (X2). github link: https://github.com/krishnaik06/Visualize-Multiple-Linear-Regression You can buy my book on Finance with ML and DL using python from the below link amazon url: https://www.amazon.in/Hands-Python-Finance-implementing-strategies/dp/1789346371/ref=sr_1_1?keywords=Krish+naik&qid=1560843206&s=gateway&sr=8-1
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Krish Naik · Krish Naik · 51 of 60

1 Natural Language Processing|Stemming
Natural Language Processing|Stemming
Krish Naik
2 Natural Language Processing|BagofWords
Natural Language Processing|BagofWords
Krish Naik
3 Gaussian distribution or Normal Distribution in statisctics
Gaussian distribution or Normal Distribution in statisctics
Krish Naik
4 Natural Language Processing|TF-IDF for Machine Learning| Text Prerocessing
Natural Language Processing|TF-IDF for Machine Learning| Text Prerocessing
Krish Naik
5 Log Normal Distribution in Statistics
Log Normal Distribution in Statistics
Krish Naik
6 Covariance in Statistics
Covariance in Statistics
Krish Naik
7 Confusion matrix, Precision, Recall| Data Science Interview questions
Confusion matrix, Precision, Recall| Data Science Interview questions
Krish Naik
8 Tutorial 44-Balanced vs Imbalanced Dataset and how to handle Imbalanced Dataset
Tutorial 44-Balanced vs Imbalanced Dataset and how to handle Imbalanced Dataset
Krish Naik
9 Implementing a Spam classifier in python| Natural Language Processing
Implementing a Spam classifier in python| Natural Language Processing
Krish Naik
10 Tutorial 11-Exploratory Data Analysis(EDA) of Titanic dataset
Tutorial 11-Exploratory Data Analysis(EDA) of Titanic dataset
Krish Naik
11 Face Recognition using open CV and VGG 16 Transfer Learning
Face Recognition using open CV and VGG 16 Transfer Learning
Krish Naik
12 Pedestrian Detection using OpenCV from Videos
Pedestrian Detection using OpenCV from Videos
Krish Naik
13 Face and Eye Detection from Videos using HAAR Cascade Classifier
Face and Eye Detection from Videos using HAAR Cascade Classifier
Krish Naik
14 Reading, Writing and Displaying images with Opencv| OpenCV Tutorial
Reading, Writing and Displaying images with Opencv| OpenCV Tutorial
Krish Naik
15 OpenCV Installation | OpenCV tutorial
OpenCV Installation | OpenCV tutorial
Krish Naik
16 Face and Eye Detection from Images using HAAR Cascade Classifier
Face and Eye Detection from Images using HAAR Cascade Classifier
Krish Naik
17 Car Detection using HAAR Cascade and Opencv from Videos.
Car Detection using HAAR Cascade and Opencv from Videos.
Krish Naik
18 Using OpenFace for Face recognition in Keras
Using OpenFace for Face recognition in Keras
Krish Naik
19 OpenPose Tutorial with Tensorflow
OpenPose Tutorial with Tensorflow
Krish Naik
20 Multiple Linear Regression using python and sklearn
Multiple Linear Regression using python and sklearn
Krish Naik
21 Dimensional Reduction| Principal Component Analysis
Dimensional Reduction| Principal Component Analysis
Krish Naik
22 Movie Recommender System using Python
Movie Recommender System using Python
Krish Naik
23 TPR,FPR,FNR,TNR, Confusion Matrix
TPR,FPR,FNR,TNR, Confusion Matrix
Krish Naik
24 Precision, Recall and F1-Score
Precision, Recall and F1-Score
Krish Naik
25 Artificial Neural Network for Customer's Exit Prediction from Bank
Artificial Neural Network for Customer's Exit Prediction from Bank
Krish Naik
26 GridSearchCV- Select the best hyperparameter for any Classification Model
GridSearchCV- Select the best hyperparameter for any Classification Model
Krish Naik
27 RandomizedSearchCV- Select the best hyperparameter for any Classification Model
RandomizedSearchCV- Select the best hyperparameter for any Classification Model
Krish Naik
28 K Nearest Neighbor classification with Intuition and practical solution
K Nearest Neighbor classification with Intuition and practical solution
Krish Naik
29 K Means Clustering Intuition
K Means Clustering Intuition
Krish Naik
30 Create custom Alexa Skill- Lambda function- Part2
Create custom Alexa Skill- Lambda function- Part2
Krish Naik
31 Hierarchical Clustering intuition
Hierarchical Clustering intuition
Krish Naik
32 Implement Transfer Learning with a generic Code Template
Implement Transfer Learning with a generic Code Template
Krish Naik
33 Gender Classifier and Age Estimator using Resnet Convolution Neural Network
Gender Classifier and Age Estimator using Resnet Convolution Neural Network
Krish Naik
34 Unlock Your Application With Your Face using OpenCV
Unlock Your Application With Your Face using OpenCV
Krish Naik
35 Draw rectangle from webcam and sketch process it on a live feed
Draw rectangle from webcam and sketch process it on a live feed
Krish Naik
36 Complete Life Cycle of a Data Science Project
Complete Life Cycle of a Data Science Project
Krish Naik
37 How we can apply Machine Learning in Finance
How we can apply Machine Learning in Finance
Krish Naik
38 Deep Learning in Medical Science
Deep Learning in Medical Science
Krish Naik
39 How to switch your career to Data Science.
How to switch your career to Data Science.
Krish Naik
40 Linear Regression Mathematical Intuition
Linear Regression Mathematical Intuition
Krish Naik
41 Handle Categorical features using Python
Handle Categorical features using Python
Krish Naik
42 Machine Learning Algorithm- Which one to choose for your Problem?
Machine Learning Algorithm- Which one to choose for your Problem?
Krish Naik
43 DBSCAN Clustering Easily Explained with Implementation
DBSCAN Clustering Easily Explained with Implementation
Krish Naik
44 Curse of Dimensionality Easily explained| Machine Learning
Curse of Dimensionality Easily explained| Machine Learning
Krish Naik
45 Feature Selection Techniques Easily Explained | Machine Learning
Feature Selection Techniques Easily Explained | Machine Learning
Krish Naik
46 Tutorial 29-R square and Adjusted R square Clearly Explained| Machine Learning
Tutorial 29-R square and Adjusted R square Clearly Explained| Machine Learning
Krish Naik
47 Cross Validation using sklearn and python | Machine Learning
Cross Validation using sklearn and python | Machine Learning
Krish Naik
48 Handling Missing Data Easily Explained| Machine Learning
Handling Missing Data Easily Explained| Machine Learning
Krish Naik
49 Deploy Machine Learning Model using Flask
Deploy Machine Learning Model using Flask
Krish Naik
50 Deployment of Deep Learning Model using Flask
Deployment of Deep Learning Model using Flask
Krish Naik
How to Visualize Multiple Linear Regression in python
How to Visualize Multiple Linear Regression in python
Krish Naik
52 K Nearest Neighbour Easily Explained with Implementation
K Nearest Neighbour Easily Explained with Implementation
Krish Naik
53 Predicting Heart Disease using Machine Learning
Predicting Heart Disease using Machine Learning
Krish Naik
54 Predicting Lungs Disease using Deep Learning
Predicting Lungs Disease using Deep Learning
Krish Naik
55 Stock Sentiment Analysis using News Headlines
Stock Sentiment Analysis using News Headlines
Krish Naik
56 Random Forest(Bootstrap Aggregation) Easily Explained
Random Forest(Bootstrap Aggregation) Easily Explained
Krish Naik
57 Voting Classifier(Hard Voting and Soft Voting Classifier)
Voting Classifier(Hard Voting and Soft Voting Classifier)
Krish Naik
58 Credit Card Fraud Detection using Machine Learning from Kaggle
Credit Card Fraud Detection using Machine Learning from Kaggle
Krish Naik
59 Hyperparameter Optimization for Xgboost
Hyperparameter Optimization for Xgboost
Krish Naik
60 Tutorial 45-Handling imbalanced Dataset  using python- Part 1
Tutorial 45-Handling imbalanced Dataset using python- Part 1
Krish Naik

Related AI Lessons

I Spent Weeks Looking for a Research Gap Before I Realized I Was Searching the Wrong Way
Learn how to effectively find research gaps by changing your approach, a crucial skill for AI researchers and academics
Medium · AI
ICMI 2026 Reviews [D]
Learn how to interpret ICMI 2026 reviews and improve your paper's acceptance chances
Reddit r/MachineLearning
Workshop submission for main conference paper under review [D]
Learn how to navigate submitting a paper to a non-archival workshop before the final decision of a main conference like ECCV
Reddit r/MachineLearning
Kept context-switching between arxiv, OpenReview, GitHub, and HuggingFace for every paper, so I built this. Chrome extension + website with everything inline, plus citation graph + SPECTER2 neighbors. 3M papers, free, feedback welcome [P]
Streamline your research with a new Chrome extension and website that integrates 3M papers from arxiv, OpenReview, GitHub, and HuggingFace, including citation graphs and SPECTER2 neighbors, and provide feedback to improve it
Reddit r/MachineLearning
Up next
Beyond Big Vendors: ERP Systems Explained #shorts
Digital Transformation with Eric Kimberling
Watch →