1. What is Machine Learning?

Machine learning gives computers the ability to learn from data without being explicitly programmed for every task.

Two major types of machine learning are:

  • Supervised Learning
  • Unsupervised Learning

2. Supervised and Unsupervised Learning

2.1 Supervised Learning

Supervised learning learns a mapping from input to output .

Each training example contains:

  • input
  • correct output or label

The algorithm learns from these correct pairs and tries to predict for a new input .

There are two major types of supervised learning:

Regression

Regression predicts a number from infinitely many possible values.

Examples:

  • Predicting a house price
  • Predicting temperature

Classification

Classification predicts a category from a small finite set of possible categories.

Examples:

  • Spam or not spam
  • Cat or dog
  • Benign or malignant tumor

Regression predicts numbers from many possible values, while classification predicts one of a limited number of categories.


2.2 Unsupervised Learning

In unsupervised learning, the data contains inputs , but there are no output labels .

The algorithm tries to find patterns or structures in the data by itself.

Common types include:

  • Clustering — groups similar data points together
  • Anomaly Detection — finds unusual data or events
  • Dimensionality Reduction — reduces the amount of data while keeping important information

3. Linear Regression Model

Linear regression is a supervised learning algorithm used for regression problems.

It fits a straight line to the training data.

For linear regression with one input feature:

where:

  • — input or feature
  • — actual output or target
  • — prediction
  • — parameter that controls the slope
  • — parameter that controls the y-intercept
  • — the model

The prediction is:

is the real target value, while is the value predicted by the model.

Training Set

The data used to train the model is called the training set.

A training example is written as:

where means the i-th training example.

The total number of training examples is written as:

For example:

  • → input of the first training example
  • → target of the first training example

The superscript is an index, not a power.


4. Cost Function

The cost function measures how well the model fits the training data.

For one training example, the prediction error is:

We square the error:

Then we calculate the average squared error over the whole training set.

The cost function for linear regression is:

This is called the squared error cost function.

The division by makes later derivative calculations simpler.

Goal

We want to choose parameters and that make:

as small as possible.

So the goal of training is:

A smaller cost usually means that the predictions are closer to the real target values.


5. Gradient Descent

Gradient descent is an algorithm used to minimize the cost function.

It repeatedly updates the parameters and .

Here, means assignment or update.

It means:

Take the old value and use it to calculate a new value.

The two parameters and should be updated simultaneously.


6. Learning Rate

is called the learning rate.

It controls how large each step of gradient descent is.

If is too small

Gradient descent takes very small steps.

It can still reach the minimum, but training will be very slow.

If is too large

Gradient descent may overshoot the minimum.

The cost may increase instead of decrease, and gradient descent may fail to converge or even diverge.

Therefore, we need to choose an appropriate learning rate.

As gradient descent gets closer to a minimum, the derivative becomes smaller, so the update steps also become smaller.


7. Derivatives

The derivative tells us the slope of the cost function and helps gradient descent decide which direction to move.

For linear regression:

and

If the derivative is positive, gradient descent decreases the parameter.

If the derivative is negative, gradient descent increases the parameter.

This moves the parameters toward a minimum of the cost function.


8. Gradient Descent for Linear Regression

Linear regression uses:

Model

Cost Function

Gradient Descent

Repeat these updates until convergence.

Convergence means that and no longer change very much after each update.

For linear regression with the squared error cost function, the cost function is convex.

A convex cost function has only one global minimum.

Therefore, with an appropriate learning rate, gradient descent can converge to the global minimum.


9. Overall Training Process

The basic process is:

Training Set

↓

Choose a Model

↓

Make Predictions

↓

Calculate the Cost

↓

Use Gradient Descent

Update and

↓

Repeat Until Convergence

↓

Get Trained Parameters and

The final trained model can then use a new input to make a prediction .