In my last blog, I explained Linear Regression as follows:-
Y = h(X)
And we mentioned that in case of Linear Regression both h(X) and Y are known and we train an algorithm so that we can 1. Organize the content into shorter paragraphs to improve readability and make it easier for the readers to follow along. Breaking down the information into smaller, digestible chunks can enhance the overall flow of the text.
2. Incorporate visual aids such as diagrams, charts, or graphs to supplement the explanation of concepts like the cost function and linear regression. Visual representations can help clarify complex ideas and make the content more engaging for the audience.
3. Provide concrete examples or case studies to illustrate how linear regression and the cost function are applied in real-world scenarios, such as predicting sales based on historical data. Practical examples can enhance the content's relevance and demonstrate the discussed concepts' practical implications. Predict Y accurately for a new X sample from our test set.
"Cost Function" also called the "Error Function" is Linear Regression is the measure of the error incurred between the value we predicted of the object via the training algorithm and the actual value of the sample. Hence the term cost comes into place. In simple words, it is described as the difference.
(Predicted Value of test Sample - Actual Value of Test Sample)
To explain this concept further, we consider a set of training data represented by the following notations:-
m | Number of Training Examples |
X's | Input Variable |
Y's | Output Variable |
(x,y) | one instance of m (1 training example) |
| ith set of training example |
Problem:- We want to predict the sales of a product based on the previous sales pattern. Some of the parameters we can consider for this problem would be:-
Past Sales.
Economic Trends.
Inflation.
Competitor rates.
Sales pattern based on ad campaigns and other modes of publicity.
All the above will form the different variables of our hypothesis.
Formally, the cost function will be the standard deviation of the predicted values on the entire set from actual values.
The above equation represents what is known as the "Cost Function" or the "Squared Error Cost Function".
For simplicity, let's consider this hypothesis to be of a single variable. This would be called "Univariate Linear Regression". Hence our hypothesis will look like this:-
A simplified version of the above equation will be if we consider theta-0=0 then the function will be a straight line passing through the origin as in the figure below. This forms the "simplified version of the cost function (Intuition-1)".
We have to choose the values of theta's in a way that the difference below is the minimum.
In the second case, we keep the parameters theta-0 and theta-1 be non-zero. This forms the "simplified version of the cost function (Intuition-2)".
Below is a graphical representation of how density estimation takes place around different sets of values for theta-0 and theta-1. This leads to a displacement density graph similar to the one below. It is an approximation for representation.
The Cost Function is the part of one of most significant algorithms in Linear Regression which is called the Gradient Descent Algorithm. The goal of Gradient Descent algorithm is to keep changing the values of theta-0 and theta-1 for minimization of cost function. Understanding the core concept of cost function is the basis of our very first Machine Learning algorithm which we will see in the next blog.
Till then keep visiting and let me know your thoughts on what I can improve and explain better so it helps you. You can connect with me on (2) Priyadarshani Pandey | LinkedIn OR email priyadarshani.pandey@techconceptz.com
Comments