Prerequisite: Linear Regression
Linear Regression is a machine learning algorithm based on supervised learning. It performs a regression task. Regression models a target prediction value based on independent variables. It is mostly used for finding out the relationship between variables and forecasting. Different regression models differ based on – the kind of relationship between dependent and independent variables, they are considering and the number of independent variables being used.
This article is going to demonstrate how to use the various Python libraries to implement linear regression on a given dataset. We will demonstrate a binary linear model as this will be easier to visualize.
In this demonstration, the model will use Gradient Descent to learn. You can learn about it here.
Step 1: Importing all the required libraries
Step 2: Reading the dataset
You can download the dataset here.
Step 3: Exploring the data scatter
Step 4: Data cleaning
Step 5: Training our model
Step 6: Exploring our results
The low accuracy score of our model suggests that our regressive model has not fitted very well to the existing data. This suggests that our data is not suitable for linear regression. But sometimes, a dataset may accept a linear regressor if we consider only a part of it. Let us check for that possibility.
Step 7: Working with a smaller dataset
We can already see that the first 500 rows follow a linear model. Continuing with the same steps as before.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course