A blog for computer science passionates.

Showing posts with label Algorithms. Show all posts
Showing posts with label Algorithms. Show all posts

Thursday, 11 June 2020

Hello Friends,
Welcome to passionforcs!!!

In previous article, we have seen what is cost function? if you haven't checked please find to get the detail about the cost function and make it clear.

In this article, we are going to learn formula of cost function. How to calculate cost function?

Let's briefly revise once what is cost function? cost function is the function to check whether the model works well or not. To check whether the model performs well or not we have hypothesis, i.e. our prediction. Now the question is How to get hypothesis?


Now, you can get your prediction through the above equation. But here the question is what is theta (ϴ)?

So the answer is, ϴ is an additional parameter.
Now we have one more question, i.e. why? what is the need of the additional parameter?
Let me give you an example so you can get easily,

Consider our previous example, stock price prediction now we just analyze the stock or share price and make our prediction. We can set an input feature vector or simply consider one input feature only here, the input is opening price, closing price, high and low price etc. etc. but additional parameter that we need in this example is our money i.e. how much amount you want to invest? through which we can get how much profit or loss I will have? this investment is additional parameter we can say because it depends on us i.e. investor.

NOTE: Human brain predict like the above example.

Now, let's consider the formula of cost function.
Cost function for linear regression

the above formula is the formula of cost function of linear regression. This is also known as squared error cost function.
Here, 1/2 * m -  m is number of samples in data or training set. 1/2 is used because when we take derivative of cost function to update the parameter during gradient descent at that time square (2 in the power) get cancelled with 1/2 multiplier thus derivation is cleaner.

Sigma (𝚺) - represents the sum.

hϴ(x(i)) - hypothesis prediction of input x at ith index. (hypothesis value of h(x) if we use single value)

y(i) - the actual label value for the input x at ith index.

Just subtract actual value i.e. y from hypothesis prediction (predicted value) i.e. h(x) and square the achieved result.

This is just the calculation of cost function with MSE i.e. Mean Squared Error. We will learn more with example.

Till then try to get some cost by putting some values of x and theta.

Stay Safe Anywhere. :)

Wednesday, 27 May 2020

Hello Friends!!!
Welcome to passionforcs,

Once upon a time I played a game especially puzzle and I tried to solve it. And of course, I solved :) (Kidding) but I solved, and my friend asked me how much time did you spent to solve this puzzle? And I got stuck & went in deep thinking of Machine Learning.

When we train our model, at that time also we should think about how our model performs? we can do this by using cost function to check whether our model performs well or not. Our hypothesis is valid and true so that the model gets the appropriate prediction or not.
In simple words the main usage of the cost function is after getting the prediction, how far or close our predicted values are from the actual values (i.e. label y).

Let's first prove these words by using the simple example.

Suppose our model predict a price of a share A, So the price of the share A for today is around 410 this is the prediction and the actual value of the share A is 415 so the difference between the actual value and predicted value is 5, but if our predicted value is 450 and actual price is 400 of the share A then the difference between these two is 50.

When the difference is 5 we can say our model works fine for the share A, but when the difference is too high such as 50, our model doesn't predict well.

This is the cost function. When we build a model, we have to check the cost function to find whether our model performs well or not. A cost of a good model should be minimum.
Difference between predicted and actual value of Share Price
NOTE: THIS FIGURE IS NOT PERFECT, THIS IS JUST AN EXAMPLE TO SHOW THE ACTUAL CONCEPT.

So, through the above figure, we can get that blue dot is actual value, red square is predicted values and dark blue triangle is the difference but if difference is too big, the model doesn't predict well.

Hope you enjoy this article, Stay Home, Stay Safe.


Sunday, 16 February 2020

Hello Friends!!!

This is the third algorithm, here I am going to share the support vector machine one more classification algorithm there are more classification algorithms I recommend you to refer these articles Logistic Regression and Naive Bayes classifiers to get proper ideas about classification algorithms.

SVM is really a very simple algorithm that works more accurately with less computational work. Actually, the support vector machine is a model works on a supervised learning technique, it works on both regression and classification. And generally suitable for binary classification. SVM is used to separate N - Dim hyperplane. For Example, if we have labeled data such as an image is a cat or not a cat. Here, we have two different labels Cat and Not and SVM Separates these labels on a hyperplane.
Fig. SVM Separates Labels


The above figure shows that the SVM separates the 2D hyperplane. In the above example, we have two labels blue dots represent Cat label and the orange triangle represents Not a Cat label. And in the above figure, one can see the separation of two different labels.

So, That's it you can get easily what is the meaning of Support Vector Machine? In the next article, we will learn more about SVM.