top of page
Inaugurated by IN-SPACe
ISRO Registered Space Tutor

S3-SA5-0127

What is Cost Functions?

Grade Level:

Class 10

AI/ML, Data Science, Physics, Economics, Cryptography, Computer Science, Engineering

Definition
What is it?

A Cost Function is like a scorekeeper that tells us how 'wrong' our predictions or models are compared to the actual results. It measures the difference between what we expected and what truly happened, helping us understand if our method is working well.

Simple Example
Quick Example

Imagine you are trying to guess the price of a plate of samosas at your local chai shop. If you guess ₹20, but the actual price is ₹25, the 'cost' of your guess is how far off you were, which is ₹5. A Cost Function helps calculate this 'off-ness' for many such guesses.

Worked Example
Step-by-Step

Let's say we predict a student's marks (P) based on their study hours, and we want to see how good our prediction is compared to their actual marks (A).

Step 1: Student A's Actual Marks (A) = 80, Predicted Marks (P) = 75.

Step 2: Calculate the difference: Difference = A - P = 80 - 75 = 5.

Step 3: To make sure positive and negative differences don't cancel out (and to penalize larger errors more), we often square the difference: Squared Difference = (Difference)^2 = 5^2 = 25.

Step 4: Student B's Actual Marks (A) = 70, Predicted Marks (P) = 72.

Step 5: Calculate the difference: Difference = A - P = 70 - 72 = -2.

Step 6: Square the difference: Squared Difference = (-2)^2 = 4.

Step 7: If we want the 'Total Cost' for both students, we add their squared differences: Total Cost = 25 + 4 = 29.

Answer: The total cost (or error) for these two predictions is 29.

Why It Matters

Cost functions are super important in fields like AI/ML and Data Science because they guide computers to learn and make better decisions, like predicting weather or recommending movies. Engineers use them to optimize designs, and economists use them to understand market trends, leading to exciting careers in AI development, data analysis, and robotics.

Common Mistakes

MISTAKE: Only looking at the simple difference (Actual - Predicted) without squaring or taking absolute value. | CORRECTION: Always square the difference or take its absolute value to ensure that negative errors don't cancel out positive errors, giving a misleading 'zero' total error.

MISTAKE: Assuming a high cost value means the model is good. | CORRECTION: A high cost value usually means the model's predictions are far from the actual values, indicating a poor model. The goal is to minimize the cost.

MISTAKE: Confusing 'Cost Function' with 'Profit Function'. | CORRECTION: A Cost Function measures error or loss that we want to minimize, while a Profit Function measures gain that we want to maximize.

Practice Questions
Try It Yourself

QUESTION: Your model predicted the price of a cricket bat as ₹1200, but the actual price was ₹1150. What is the squared error (cost) for this prediction? | ANSWER: (1150 - 1200)^2 = (-50)^2 = 2500

QUESTION: A delivery app predicts a food delivery will take 30 minutes. It actually takes 35 minutes. What is the absolute error (cost) for this prediction? | ANSWER: |35 - 30| = 5 minutes

QUESTION: For two predictions, the actual values were 10 and 15. The predicted values were 8 and 16. Calculate the total squared error (cost). | ANSWER: (10 - 8)^2 + (15 - 16)^2 = (2)^2 + (-1)^2 = 4 + 1 = 5

MCQ
Quick Quiz

Which of the following best describes the goal when using a Cost Function?

To maximize its value

To keep its value constant

To minimize its value

To ignore its value

The Correct Answer Is:

C

The goal of a Cost Function is to measure how much error a model has. To make the model better and more accurate, we want to reduce or minimize this error, so we minimize the cost function's value.

Real World Connection
In the Real World

In apps like Swiggy or Zomato, companies use cost functions to improve their estimated delivery times. If their prediction is 30 minutes but the actual time is 45 minutes, a cost function helps them quantify this 'error'. By minimizing this cost over millions of deliveries, they can make their predictions more accurate, leading to happier customers and more efficient operations.

Key Vocabulary
Key Terms

ERROR: The difference between a predicted value and an actual value. | PREDICTION: A guess or estimate made by a model. | ACTUAL VALUE: The true or observed value. | MINIMIZE: To make something as small as possible. | OPTIMIZE: To make something as effective or functional as possible.

What's Next
What to Learn Next

Now that you understand Cost Functions, you can explore 'Gradient Descent'. Gradient Descent is a powerful technique that uses cost functions to actually 'teach' machines how to find the best possible predictions, taking you deeper into the world of AI and machine learning.

bottom of page