Secular Party of Australia

A party who really want more secularism, or in more simple terms, really don’t like religion and want to try and remove it from everywhere they can. But turns out they kind of just end up a little…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Simple Implementation of Linear Regression

in Python

Regression analysis is a form of predictive modelling technique which correlate the relationship between a dependent and independent variable (s). This technique is used for finding the effective relationship between the variables. Regression analysis is an important tool for data analysis and modelling. Here, we fit a curve or line to the data points in such a way that the differences between the distances of data points from the curve or line is reduced.

Linear regression is the most simplest form of regression. In this technique the dependent variable is continuous in nature and independent variable(s) can be continuous or discrete. The relationship between dependent variable and independent variables is linear in nature. Linear Regression establishes a relationship between dependent variable (Y) and one or more independent variables (X) using a best fit straight line also known as regression line. When you have only one dependent variable and only one independent variable it is called as simple linear regression and when you have one dependent variable and and one or more independent variables it is called as multiple linear regression.

It is represented by the equation given below;

Implementation of linear regression in python is the most simplest way for quick understanding of linear regression in just few lines of code. For implementing linear regression in python we will be using scikit-learn library.

For installation:

We also need numpy to perform calculations, pandas to import the dataset which is in csv format and matplotlib for data visualization and regression line. We will use the Linear Regression class to perform the linear regression.

Now import the data set;

Now let’s perform linear regression;

Here (­1,1) is calculation of dimensions of all(­1) the rows in one(1) column. linear is object created of the class Linear Regression. Also two variables X and Y are best fitted in the object and prediction is done.

Now let’s plot the linear regression line from the prediction;

Here we are done with simple linear regression where we had only one independent variable (X) and one dependent variable (Y).

Add a comment

Related posts:

Climate Change and Veganism

One of the biggest food trends of 2018, veganism, has taken by the storm as hundreds of people are adopting a meat-free diet by the minute. Some do it for the ‘gram’ while others are becoming aware…

Starting Points

How often do we wish we could become better people and yet stay trapped in our old habits and patterns? We attempt to change by sheer force of will or by riding a Jesus high. The problem is that it…

Why pursuing MBBS in Russia can be proved as a great opportunity for Indian medical students.

When medical aspirants are keen to pursue MBBS, they work extremely hard and put in huge efforts to anyhow fulfill their dreams of becoming a surgeon. In the field of education and profession…