Class 9 – Multiple Linear Regression
Implementation of Multiple Linear Regression model using Python.
To implement MLR using Python, we have below problem.
Problem Description:
We have a dataset of 50 start-up companies. This dataset contains five main information. R&D Spend, Administration Spend, Marketing Spend, State, and Profit for financial Yaar. Our goal is to create a model that can easily determine which company has a maximum profit and which is the most affecting factor for the profit of a company.
Since we need to find the Profit, so it is the dependent variable and the other four variables and independent variables, the main steps of deploying the MLR model.
1. Data Pre-processing Steps.
2. Fitting the MLR model to the training set.
3. Predicting the result of the test set.
Step 1: Data Pre-processing step:
Importing Libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
data_set= pd.read_csv("Startups.csv")
data_set.head()
Extracting dependent and independent Variables:
X = data_set.iloc[:,:-1]
y = data_set.iloc[:,4]
X
Encoding dummy variables:
states = pd.get_dummies(X["State"],drop_first=True)
# Drop the state column
X = X.drop('State',axis=1)
# Concat the dummy variables
X = pd.concat([X,states],axis=1)
X
--------------------------------------------------
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.25,random_state=0)
-----------------------------------------
Test set:
y_test
x_test
Training Set
x_train
y_train
NOTE: In MLR, we will not do feature scaling as it is taken care by the library, so we don’t need to do it manually.
Step 2: Fitting our MLR model to the Training Set.
# Fitting Multiple Linear Regression to the Training set
from sklearn.linear_model import LinearRegression
LR = LinearRegression()
LR.fit(x_train,y_train)
Step 3: Prediction of Test set results.
# Predicting the Test Set results
y_pred = LR.predict(x_test)
-------------------------------------
y_pred
y_test
-----
from sklearn.metrics import r2_score
score=r2_score(y_test,y_pred)
score
print('Train Score: ', LR.score(x_train, y_train))
print('Test Score: ', LR.score(x_test, y_test))
To check the comprehensive table with statistical info generated by statsmodels.
import statsmodels.api as sm model = sm.OLS(y, X).fit() predictions = model.predict(X)
print_model = model.summary() print(print_model)
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Class 9 – Multiple Linear Regression», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.