How does a machine learning algorithm learn? (with intuition and math that you already know )

For simplicity, let's imagine we want to predict house price, given house age and house area.

And we already have some data available like

house age = 3 years, area= 1000 sqft, price = 30K

house age = 5 years, area = 500 sqft, price = 25K        

We can learn from the above data how house prices relate to their age and area.

You can think of a machine learning algorithm as a math formula.

#Linear regression with p1 and p2 are slope

y = x 1* p1 + x2 * p2
        

Then in the above formula,

y becomes house price, x1 becomes house age, and x2 becomes house area.

We want to find the relation between y and x1, x2, which depends on p1 and p2.

In simple terms, when you train a machine learning model to predict house price given house age and house area data, you are essentially finding values for parameters p1 and p2.

Once you find appropriate values for p1 and p2, you have a trained machine learning model that understands house price given house age and area.

But how do we know we have found the correct values for p1,p2?

We can start with random values for p1 and p2, calculate house prices using the above formula

y_predicted = x 1* p1 + x2 * p2        

let's say the actual house price for a given house is y_actual, and the model predicted it as y_predicted.

error =  y_actual - y_predicted        

We want to find the model (values of p1,p2) such that the error is low.

But how do we move from random values p1,p2 towards values with a minimum error?

One of the things we learned during the 12th is derivative or Differentiation.

y =x^2 (x squared)        

what does dy/dx mean?

When differentiating y with respect to x we calculate how much y changes if I change x by 1 unit. In other words, we are trying to figure out at what rate x influences y.

If you look closely at the above formulas, the error depends on what values we choose for p1 and p2.

If we calculate the derivative of the error with respect to p1 and p2, we will know how the error changes if you change p1 and p2.

It will also tell you that an increase/decrease in the value of p1,p2 will increase/decrease error.

you can keep adjusting (increase/decrease) p1 and p2 values until you get the minimal error.

To know more, google search for gradient descent.

Once you find values with minimal error, that's the values you will use in the formula to predict house price.


house_price = house_age * best_p1 + house_area * best_p2
        

😎 And you just trained an ML algorithm for your data that can predict house prices given house age and area.

This was the simplified approach to show how math is used in ML.


To view or add a comment, sign in

More articles by Pradip Nichite

Others also viewed

Explore content categories