Table of Contents
- Introduction to Multiple linear regression
- Problem Statement
- Code walkthrough
- Video Tutorial
1 Introduction to Multiple linear regression
- Multiple linear regression is quite similar to simple linear regression wherein Multiple linear regression instead of the single variable we have multiple-input variables X and one output variable Y and we want to build a linear relationship between these variables.
- In Simple linear regression (Y) = b0+b1X1
- In multiple linear regression (Y) = b0+b1X1+b2X2+b3X3……….bnXn
- Here the X1, X2, X3…..XN are independent variable and the output variable is called dependent
2 Problem Statement
- Dataset consisting of 4columns R&D, administration, and marketing are independent variables and profit is our dependent variable.
- So we need to find out profit based on the amount spent on R&D administration and marketing so
3 Code walkthrough
Imported the all necessary libraries Matplotlib which will be used for plotting the second one is pandas for reading dataset.
Imported my data set using read CSV function and initialized x and y variables with R&D, administration, marketing spend, and profit respectively
- split the data set into a training set and test set we will be using a function called train test split which will split a 5/6 th dataset into a training set and 1/6 th to test.
- After splitting the data into training and testing sets finally the time is to train our algorithm for that we need to import the linear regression class and then we will be instantiating a regressor
- Once that is done we will call up the fit function giving it the parameters as x-train and y train the training data
- After training is done model will return you the best fit for the particular data and then you can get all the intercept and the theta values you can
- We can get the intercept from the arguments if you call the regressor. intercept_ we will get B0 value if you call regressor.coefficient
Predictions on x test:
- We predicted all my testing data set using the predict function
- predict function give us all the predicted Y values and then we have tried comparing it with our actual values and our predicted values