Linear Regression
Before getting started with deep learning, let's get started with a simple machine learning algorithm to understand the essentials of building a machine learning model using Python. We will start with the most commonly used machine learning algorithm, i.e. linear regression, in Python.
Linear regression is a machine learning algorithm that can show the relationship between an outcome (dependent variable) and a set of attributes (independent variables) and how they impact each other. It essentially shows how the variations in the outcome can be explained by each of the independent variables. In business, this outcome of interest could be predicting sales of a product, pricing, performance, risk, etc. independent variables are also referred to as explanatory variables, since they explain the factors that influence the outcome along with the degree of impact which is represented by the coefficients. These coefficients are the model parameters and are estimated by training the model using labeled data. In LR, the relationship between the dependent and independent variables is established by fitting the best line. As you saw in previous chapter, a single neuron can act as a linear regression model, where the best line can be represented by the equation \(Y\ =\ aX\ +b\) with \(Y\) being the dependent variable, \(a\) the slope of the line, \(X\)independent variable and \(b\) the intercept.
Python Code
A Python notebook always starts with importing required libraries. We will be using ScikitLearn library to split the data into train and test datasets and create a linear regression model:
from sklearn import linear_model
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error, r2_score