Linear Regression

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 8

LINEAR REGRESSION

Linear Regression Model

 Linear Regression is an supervised Machine Learning algorithm.

 predict the outcome of an event based on the independent


variable data points.

 Linear regression algorithm shows a linear relationship


between a dependent (y) and one or more independent (y)
variables, hence called as linear regression.
Linear Regression Equation
Linear regression can be expressed mathematically as:

y= a+ bx+ε

Here,
•Y= Dependent Variable .
•X= Independent Variable. 
•a= intercept of the line. 
•b= Linear regression coefficient (slope of the line).
•ε = random error.
Linear Regression line

A linear line showing the relationship between the dependent and independent
variables is called a regression line.

Types:
Positive Linear Relationship:If the dependent variable increases on the Y-axis
and independent variable increases on X-axis, then such a relationship is
termed as a Positive linear relationship.

Negative Linear Relationship:If the dependent variable decreases on the Y-


axis and independent variable increases on the X-axis, then such a relationship
is called a negative linear relationship.
Example
 Assum AB Company, there is a salary distribution table based on Year of Experience as
per below.
Scatter plot
 let’s plot the data set into the plot first:
Code
import pandas as pd
dataset = pd.read_csv('Salary_Data.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:,1].values
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=1/3, random_state=0)
from sklearn.linear_model import LinearRegression
egressor = LinearRegression()
regressor.fit(X_train, y_train)
import matplotlib.pyplot as plt
plt.scatter(X_train, y_train, color = 'red')
plt.plot(X_train, regressor.predict(X_train), color='blue')
plt.title('Salary vs Experience (Training set)')
plt.xlabel('Years of Experience')
plt.ylabel('Salary') plt.show()
The linear regression

You might also like