 # Linear Regression

## Machine Learning – 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. Linear regression performs the task to predict a dependent variable value (y) based on a given independent variable (x). So, this regression technique finds out a linear relationship between x (input) and y(output). Hence, the name is Linear Regression.
In the figure above, X (input) is the work experience and Y (output) is the salary of a person. The regression line is the best fit line for our model.

Hypothesis function for Linear Regression : While training the model we are given :
x: input training data (univariate – one input variable(parameter))
y: labels to data (supervised learning)

When training the model – it fits the best line to predict the value of y for a given value of x. The model gets the best regression fit line by finding the best θ1 and θ2 values.
θ1: intercept
θ2: coefficient of x

Once we find the best θ1 and θ2 values, we get the best fit line. So when we are finally using our model for prediction, it will predict the value of y for the input value of x.

Cost Function (J):
By achieving the best-fit regression line, the model aims to predict y value such that the error difference between predicted value and true value is minimum. So, it is very important to update the θ1 and θ2 values, to reach the best value that minimize the error between predicted y value (pred) and true y value (y).  Cost function(J) of Linear Regression is the Root Mean Squared Error (RMSE) between predicted y value (pred) and true y value (y).

To update θ1 and θ2 values in order to reduce Cost function (minimizing RMSE value) and achieving the best fit line the model uses Gradient Descent. The idea is to start with random θ1 and θ2 values and then iteratively updating the values, reaching minimum cost.

Last Updated on October 24, 2021 by admin

## Python – os.path.dirname() methodPython – os.path.dirname() method

Python | os.path.dirname() method OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality. os.path module is sub module of OS module in Python

## Get unique values from a column in Pandas DataFrameGet unique values from a column in Pandas DataFrame

In this article, we will explore different methods to extract unique values from a column in a Pandas DataFrame. The unique values in a column can provide valuable insights and help in various data analysis tasks. Method 1: Using the

## Comparing dates in PythonComparing dates in Python

Comparing dates in Python Comparing dates is quite easy in Python. Dates can be easily compared using comparison operators (like <, >, <=, >=, != etc.). Let’s see how to compare dates with the help of datetime module using Python. Code #1

## Unpacking a Tuple in PythonUnpacking a Tuple in Python

Unpacking a Tuple in Python Python Tuples In python tuples are used to store immutable objects. Python Tuples are very similar to lists except to some situations. Python tuples are immutable means that they can not be modified in whole program. Packing and

## Socket Programming with Multi-threading in PythonSocket Programming with Multi-threading in Python

Socket Programming with Multi-threading in Python Socket Programming-> It helps us to connect a client to a server. Client is message sender and receiver and server is just a listener that works on data sent by client.   What is

## Python – Converting all strings in list to integersPython – Converting all strings in list to integers

Python | Converting all strings in list to integers Interconversion between data types is facilitated by python libraries quite easily. But the problem of converting the entire list of string to integers is quite common in development domain. Let’s discuss

## Private Methods in PythonPrivate Methods in Python

Private Methods in Python Encapsulation is one of the fundamental concepts in object-oriented programming (OOP). It describes the idea of wrapping data and the methods that work on data within one unit. This puts restrictions on accessing variables and methods

## Reading an excel file using Python openpyxl moduleReading an excel file using Python openpyxl module

Reading an excel file using Python openpyxl module Openpyxl is a Python library for reading and writing Excel (with extension xlsx/xlsm/xltx/xltm) files. The openpyxl module allows Python program to read and modify Excel files. For example, users might have to go