A blog for computer science passionates.

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.


Tuesday, 19 May 2020

Hello Freinds!!!
Welcome to passionforcs,

In this article, we are going to learn one more flow breaking (jumping) statement i.e. continue. continue statement is another flow breaking statement.
continue statement skips an iteration, when continue occurs control directly transfers to the condition for the next iteration.
How Continue Statement Works?
In the above example, we can see that when the value of i divides by 2 and gets the reminder 0, continues the loop i.e. skips that iteration otherwise it prints the value of i. when the value of i equals 6 the loop terminates and at last it prints Bye...Bye...

We have one more form of continue statement i.e. continue with label. same as break with label. For example,


In the above example the values of i and j multiplied only for odd numbers when for even numbers it skips the iteration. Try these examples to get more clarity. Happy Coding... :)

Tuesday, 5 May 2020

Hello Friends!!!

Welcome to passionforcs,
In this article, we are going to learn flow breaking statements. In Java, there are three different flow breaking statements such as, break, continue, and return.

Lets' understand the break statement is used to break the entire code block. We use break statement with switch statements to break the case statement. Even we can use the break statement to break the loop and we can use a break like goto (in C programming). Let's understand more about the different types of a break statement.

break with a switch statement that we have seen in one of the previous articles.

The second form of break statement is break the looping statements. The break statement is used to break the loop, it immediate terminates the loop and control moves to the next statement.
Syntax,
break
For example,

The third form of a break statement is to use the break statement like goto statement in C programming. Java does not support the goto statement but it works the way goto statement works.
Syntax,
break label;
Here label is any valid label name.

For example,
Refer the above code and you can get that break label works when condition returns true. i.e. when condition is true, break statement break the labeled statement and control goes to the next statement.
Try these examples and let me know whether you get the break statement or not. Till then Happy Coding...:) In the next article we will learn about continue the next jumping statement.

Saturday, 2 May 2020

Hello friends!!!
Welcome to passionforcs,

In this article, we are going to discuss different flavors of for loop, in the previous article we have already seen that what is looping and how many looping statements are there? and basic syntax of looping statements but we can use for loop differently and we can play with the same syntax of for loop let's understand How?

As we know the main syntax of for loop is something like,
for(init;condition;increment/decrement)
{
   //code block
}

If we want to make for loop infinite we can use the syntax below
for(;;)
{
    //code block
}

If we have a counter variable and is already initialized we can use the syntax below
for(;condition;increment/decrement)
{
    //code block
}

If we want to use for loop like while loop we can use the below syntax
for(;condition;)
{
    //code block
    //increment/decrement
}
when we use the above syntax the counter variable should have to be initialized and we have to add increment or decrement inside the loop

So, we can use for loop with different syntax. try to perform different program with these different syntaxes, Happy Coding... :)