Module 1
Module 1
(CSE3008)
Dr. G V Sivanarayana
Assistant Professor Senior
❖ Provide understanding of techniques, mathematical concepts, and algorithms used in machine learning
to facilitate further study in this area.
❖ Provide understanding of the limitations of various machine learning algorithms and the way to evaluate
performance of machine learning algorithms.
❖ Practice software implementation of different concepts and algorithms covered in the course.
Gradient Descent, Convex optimization. Basics of Statistical Decision Theory - Regression, Linear
Regression, Multivariate Regression.
Module - II
Dimensionality Reduction and Introduction to Classification: 7 hours
Subset Selection, Shrinkage Methods-Ridge, Lasso, PCA, LDA, Classification, Linear Classification, Logistic
Regression, K-Nearest Neighbor learning, Bias- Variance, Tradeoff.
Decision Trees, Regression Tree, Decision Trees - Stopping Criterion & Pruning, Loss functions, Decision
Trees Multiway Splits, Missing Values, Decision Trees - Instability, Example, Evaluation Measures,
Bootstrapping & Cross Validation, Class Evaluation Measures, ROC curve, MDL, Ensemble Methods -
Bagging, Committee Machines and Stacking, Ensemble Methods – Boosting- Gradient Boosting, Random
Forests..
Module - IV
SVM and Bayesian Network & Naïve Bayes: 9 hours
Single & Multiclass classification - SVM- formulation, Interpretation & Analysis, SVM for Linear Separable
Data, SVM Kernels, Hinge Loss Functions; Naive Bayes, Bayesian Networks.
ANN- Introduction, Neural Network Representations, Problems for Neural Network Learning, Perceptron’s,
Multilayer Networks and Backpropagation Algorithm.
Module - VI
Unsupervised Learning: 7 hours
References :
1. Aurelien Geron, Hands-On Machine Learning With Scikit-Learn and Tensorflow, O’Really publication 2019.
2. Shai Shalev-Shwartz and Shai Ben-David, Understanding Machine Learning, Cambridge University Press. 2017.
3. Tom M. Mitchell, Machine Learning, McGraw Hill, 2017.
4. M Narasimha Murty, Introduction to Pattern Recognition and Machine Learning, World Scientific Publishing Company,
2015.
After successful completion of the course the student will be able to:
❖ Understand the basic mathematics required for the machine learning concepts to solve various problems.
Distinguish classification and regression problems and apply to real world problems.
❖ Understand the concept behind neural networks for learning non-linear functions.
Laboratory -- -- 25%
Module - I
Introduction - Regression: 7 hours
Gradient Descent, Convex optimization. Basics of Statistical Decision Theory - Regression, Linear
Regression, Multivariate Regression.
➢ “Learning is any process by which a system improves performance from experience.” -Herbert Simon
➢ Definition by Tom Mitchell (1998):
Machine Learning is the study of algorithms that
-- improve their performance P
-- at some task T
-- with experience E
A well-defined learning task is given by < P, T, E >.
➢ Arthur Samuel, a pioneer in the field of artificial intelligence and computer gaming, coined the term “Machine
Learning”. He defined machine learning as – “Field of study that gives computers the capability to learn without
being explicitly programmed”.
✓ A Machine Learning system learns from historical data, builds the prediction models, and whenever it receives
new data, predicts the output for it. The accuracy of predicted output depends upon the amount of data, as the
huge amount of data helps to build a better model which predicts the output more accurately.
✓ Datasets
✓ Training Data: Data used to train model. your model actually sees(both input and output) and learn from.
✓ Validation Data: The part of data which is used to do a frequent evaluation of model, fit on training dataset along
with improving involved hyper-parameters.
✓ Testing Data: Once our model is completely trained, testing data provides the unbiased evaluation. After
prediction, we evaluate our model by comparing it with actual output present in the testing data.
✓ In machine learning, training data is the data you use to train a machine learning algorithm or model.
✓ Training data requires some human involvement to analyze or process the data for machine learning use.
✓ Training datasets can include text (words and numbers), images, video, or audio. And they can be available to you
in many formats, such as a spreadsheet, PDF, HTML, or JSON.
✓ When labeled appropriately, your data can serve as ground truth for developing an evolving, efficient machine-
learning formula.
✓ The features in your training data and the quality of labeled training data will determine how accurately the
machine learns to identify the outcome, or the answer you want your machine learning model to predict.
✓ The quality and quantity of your training data determine the accuracy and performance of your machine learning
model.
✓ The validation set is used to evaluate a given model, but this is for frequent evaluation.
✓ We, as machine learning engineers, use this data to fine-tune the model hyper-parameters. Hence the model
occasionally sees this data, but never does it “Learn” from this.
✓ We use the validation set results, and update higher level hyper-parameters. So the validation set affects a
model, but only indirectly.
✓ The validation set is also known as the Dev set or the Development set. This makes sense since this dataset
helps during the “development” stage of the model.
✓ The system creates a model using labeled data to understand the datasets and learn about each data, once the
training and processing are done then we test the model by providing a sample data to check whether it is
predicting the exact output or not.
➢ Classification
➢ Regression
✓ The aim of a supervised learning algorithm is to find a mapping function to map the input variable(x) with the output
variable(y). Y = f(x)
✓ With the help of supervised learning, the model can predict the output on the basis of prior experiences.
✓ In supervised learning, we can have an exact idea about the classes of objects.
✓ Supervised learning model helps us to solve various real-world problems such as fraud detection, spam
filtering, etc.
✓ Supervised learning cannot predict the correct output if the test data is different from the training dataset.
Supervised Learning
Classification O/P is Discrete. Ex: Spam detection
✓ Unsupervised learning uses unlabeled data to find patterns in the data, such as inferences or clustering of data
points.
✓ The goal of unsupervised learning is to find the underlying structure of dataset, group that data according to
similarities, and represent that dataset in a compressed format.
✓ The system doesn’t figure out the right output, but it explores the data and can draw inferences from datasets to
describe hidden structures from un -labelled data.
✓ Unsupervised learning is used for more complex tasks as compared to supervised learning because, in
unsupervised learning, we don't have labeled input data.
✓ Unsupervised learning is preferable as it is easy to get unlabeled data in comparison to labeled data.
✓ Unsupervised learning is intrinsically more difficult than supervised learning as it does not have corresponding
output.
✓ The result of the unsupervised learning algorithm might be less accurate as input data is not labeled, and
algorithms do not know the exact output in advance.
Unsupervised Learning
Association
✓ Problems where you have a large amount of input data (X) and only some of the data is labeled (Y) are called
semi-supervised learning problems.
✓ The most basic disadvantage of any Supervised Learning algorithm is that the dataset has to be hand-labeled
either by a Machine Learning Engineer or a Data Scientist. This is a very costly process, especially when dealing
with large volumes of data.
✓ The most basic disadvantage of any Unsupervised Learning is that it’s application spectrum is limited.
✓ In this type of learning, the algorithm is trained upon a combination of labeled and unlabeled data.
✓ It is a Machine Learning algorithm that allows software agents and machines to automatically determine the
ideal behavior within a specific context to maximize its performance.
✓ It does not have labelled dataset or results associated with data so the only way to perform a given task is to
learn from experience.
✓ Reinforcement learning can, therefore, help in industrial automation as well as the gaming sector primarily.
✓ In Reinforcement Learning, the agent learns automatically using feedbacks without any labeled data, unlike
supervised learning.
✓ Since there is no labeled data, so the agent is bound to learn by its experience only.
✓ Imagine that you were dropped off at an isolated island! What would you do?
✓ Panic? Yes, of course, initially we all would. But as time passes by, you will learn how to live on the island.
You will explore the environment, understand the climate condition, the type of food that grows there, the
dangers of the island, etc.
✓ This is exactly how Reinforcement Learning works, it involves an Agent (you, stuck on the island) that is put
in an unknown environment (island), where he/she must learn by observing and performing actions that
result in rewards.
✓ Cost function: The average (or total) loss over the entire dataset (or mini-batch), which is what we actually
minimize during training (e.g., Mean Squared Error as the average of individual losses).
✓ Error rate (or misclassification rate) is usually the proportion of incorrect predictions in classification tasks
(e.g., 1 - accuracy, or percentage of wrong labels).
➢ Regression is a fundamental supervised learning technique in machine learning used to model and analyze the
relationship between a dependent variable (target) and one or more independent variables (features).
➢ The main goal of regression analysis is to plot a line or curve that best fit the data and to estimate how one variable
affects another.
➢ Its primary goal is to predict continuous numerical values.
Examples:
• What will the house price be based on its size and location?
• What will be the temperature tomorrow?
𝜕𝐽
𝐺=
𝜕𝜃
3. Weight update equation: w = w – η . G
Here, η is a learn_rate which should not be too high or low to skip or not at all converging to min point.
4. Repeat steps 2 to 3 until it becomes a constant change.
Example:
Then:
1 Epoch = model sees all 1000 samples once So, if you train for 10 epochs,
• Within one epoch, there will be: total iterations = 10 epochs × 10 iterations
1000 samples ÷ 100 batch size = 10 = 100 updates
So, one epoch = 10 iterations
✓ A model uses a loss function that quantifies the error between the predicted output and the ground truth for a given
training sample.
✓ When model is trained in practice, many images are used to compute a loss before the network weights are
updated. Therefore, the Mean Squared Error (MSE) for a number of training images.
✓ The number of images used to update the weights is referred to as the batch size (better batch size of 32 is
default). The processing of a batch of images is referred to as an “iteration.”
✓ Optimization process is used to update the weights in a neural network. Fortunately, there is a principled way to
tune the weights of a model called gradient descent.
weight to get closer to the optimum value indicated by Wo. So we would need to move in a direction opposite from the sign of the
gradient.
✓ On the other hand, if our current weight estimate, We1 > Wo (as shown in the plot to the right), the gradient would be positive,
and we would need to reduce the value of the current weight to get closer to the optimum value of Wo.
✓ let’s assume that the current weight is We1, which has a value of 0.38, learning rate of .01 and that the slope of the loss function at
the point We1 is equal to -.55. Using the update equation above, we can easily compute a new estimate for the weight which we will
refer to as We2.
▪ Uses small subsets of data (e.g., 32, 64 samples). Here n = B (B = Batch Size)
1
➢ Where L = 𝑀𝑆𝐸 = 𝑛 σ𝑛𝑖=1(𝑦 − 𝑦)
ො 2
✓ Most machine learning problems can be recast as optimization problems over specific objective functions.
✓ In gradient descent, one tries to minimize the loss function of the neural network by moving the parameters
along the negative direction of the gradient.
ഥ whereas for
✓ For single-layer networks like the perceptron, gradient-descent is done only with respect to W,
larger networks, all parameters in the network need to be updated with backpropagation.
✓ Running all examples at once to compute gradients is impractical. However, at the start of training, even small
samples can give a good estimate of the gradient direction, making stochastic gradient descent (SGD) and its
variants effective for optimization.
✓ Since the loss function of most optimization problems can be expressed as a linear sum of the losses with respect
to individual points [ ], it is easy to show the following:
✓ In this case, updating the full gradient with respect to all the points sums up the individual point-specific effects.
✓ Stochastic Gradient Descent (SGD) speeds up the learning process by updating the model based on a single
or small batch of data points at a time, rather than the whole dataset.
✓ Stochastic Gradient Descent (SGD) updates the model quickly but with less precise gradients, making it faster
but less accurate than traditional gradient descent.
✓ Mini-batch Stochastic Gradient Descent (SGD) strikes a balance between stability, speed, and memory usage.
✓ In this method, computations involve matrices instead of vectors, both during forward and backward
propagation.
✓ If the batch size is too small, it leads to constant overhead and inefficient computation. Larger batch sizes
(usually in the range of a few hundred) don’t significantly improve gradient accuracy.
✓ Powers of 2 (like 32, 64, 128, or 256) are commonly chosen because they often provide the best
computational efficiency on most hardware. Mini-batch SGD is widely used in neural network training for this
reason. SCOPE, VIT-AP GVSN 53
Gradient Problems
Vanishing Gradient
✓ Vanishing gradient is a scenario in the learning process of neural networks where model doesn’t learn at all.
✓ It is due to when gradient becomes too small, almost vanishes leads to weights got stuck and never reach the
optimal value for minimal loss(global minima).
✓ Thus network not able to learn and converge, especially during chain rule differentiation, back-propagating
from last to initial layer may lead to no updates of weights at all.
Exploding Gradient
✓ Exactly opposite to vanishing gradient when model keeps on learning, weights keep on updating large but
model never gets converged.
✓ Computes gradient (loss) with respect to weights which becomes extremely large in the earlier layers in such a
way that it explodes.
SCOPE, VIT-AP GVSN 54
Figure:A Figure:B
Figure:C
𝑛
Step 2: Predicted Values 1 𝜕𝐽 1
= −1.5 − 2.3 − 3.2 = (𝑦ෝ𝑖 − 𝑦𝑖)
3 𝜕𝑐 𝑛
𝑦ො = 0𝑥 + 0 = 0 𝑖=1
So predictions: 𝑦ො = 0, 0, 0
−7
= = −2.333
Step 3: Errors 3
𝑦ො − 𝑦 = 0 − 1.5, 0 − 2.3, 0 − 3.2
= −1.5, −2.3, −3.2
SCOPE, VIT-AP GVSN 57
Step 5: Gradient with Respect to 𝑚 :
𝜕𝐽 1
= 𝑛 σ𝑛𝑖=1(𝑦ෝ𝑖 − 𝑦𝑖 ) xi
𝜕𝜃
1
= 3 −1.5 1 + −2.3 2 + −3.2 3
1
= −1.5 − 4.6 − 9.6
3
Parameter Updates(After One Iteration)
−15.7
= = −5.233 𝜕𝐽
3 𝑐new = 𝑐𝑜𝑙𝑑 − 𝛼 𝜕𝑐
x y
Cost Function: 𝐽(𝑥, 𝑦) = 𝑥2 + 2𝑦2 + 2𝑥𝑦 1 2
2 3
o Initial point: 𝑥0 𝑦0 = 2 1
3 5
o Learning rate: 𝛼 = 0.1
o Perform 2 iterations Initial values: 𝑤=0, 𝑏=0
Learning rate: 𝛼=0.05
Perform two iteration
➢ A cost function: 𝐽 𝑤 = 𝑤 2
✓ This ensures that local minima are global minima, making optimization reliable and efficient (e.g., via
gradient descent or specialized solvers).
✓ Optimization means finding the best parameters that make the error as small as possible. It's like
searching for the lowest point in a valley.
✓ A convex shape is like a smooth bowl or U-shape. No matter where you start, if you roll downhill (using
math tricks like gradient descent), you always end up at the very bottom—the absolute best spot.
✓ In non-convex cases (wavy hills and valleys), you might get stuck in a small dip that's not the deepest.
Example: f(x)=3x+5
Right-Hand Side (RHS)
Left-Hand Side (LHS):
RHS = 𝜆𝑓 𝑥1 + 1 − 𝜆 𝑓 𝑥2
LHS = f (λx1+(1−λ)x2)
= 𝜆 3𝑥1 + 5 + 1 − 𝜆 3𝑥2 + 5
= 3 𝜆𝑥1 + 1 − 𝜆 𝑥2 + 5
= 3𝜆𝑥1 + 5𝜆 + 3 1 − 𝜆 𝑥2 + 5 1 − 𝜆
= 3𝜆𝑥1 + 3 1 − 𝜆 𝑥2 + 5
= 3𝜆𝑥1 + 3 1 − 𝜆 𝑥2 + 5
LHS = RHS
Hence: 𝑓 𝜆𝑥1 + 1 − 𝜆 𝑥2 = 𝜆𝑓 𝑥1 + 1 − 𝜆 𝑓 𝑥2
So, 𝑓 𝑥 = 3𝑥 + 5 is a convex function.
𝑓(𝑥) = 𝑥2 + 3𝑥 + 5
𝑑
First Derivative: 𝑓 ′ 𝑥 = 𝑑𝑥 𝑥 2 + 3𝑥 + 5 = 2𝑥 + 3
𝑑
Second Derivative: 𝑓 ′′ 𝑥 = 𝑑𝑥 2𝑥 + 3 = 2
Conclusion
𝑓 ′′ 𝑥 = 2 > 0 for all 𝑥
Hence,
𝑓 𝑥 is a convex function
✓ This is convex because it's a quadratic function with a positive semi-definite shape (like a bowl).
∥ 𝛽 ∥1 = σ ∣ 𝛽𝑗 ∣ :L1 norm
✓ Loss Function: It is a mathematical measure of error between predicted and actual values.
✓ Decision Rule: it is a mechanism or algorithm that is used to minimize the loss function.
✓ Risk: It is the expected value of the loss function over the entire data distribution that we assume exists due
to pre-existing bias in the dataset.
✓ Bias: Error from simplistic assumptions. High bias models underfit the data.
✓ Variance: Error from sensitivity to training data. High variance models overfit the data.
✓ Irreducible error: Noise inherent in the data that no model can eliminate.
Bias:
✓ Bias is the algorithm’s tendency to consistently learn the wrong thing by not taking into account all the
information in the data. For the model to be accurate, bias needs to be low.
✓ If there are inconsistencies in the dataset like missing values, less number of data tuples or errors in the
input data, the bias will be high.
For a model to be ideal, it’s expected to have low variance, low bias and low error.
SCOPE, VIT-AP GVSN 72
✓ The bias-variance trade-off is fundamental to understanding how to optimize model performance.
✓ The bias-variance trade-off is a key concept in machine learning that explains the balance between a model’s
complexity and its ability to generalize to new data.
✓ It’s about finding the perfect spot where a model performs well on both the training data and unseen data
(test data).
✓ Regression analysis is a statistical method to model the relationship between a dependent (target) and
independent (predictor) variables with one or more independent variables.
✓ More specifically, Regression analysis helps us to understand how the value of the dependent variable is
changing corresponding to an independent variable when other independent variables are held fixed.
✓ Regression is a supervised learning technique which helps in finding the correlation between variables and
enables us to predict the continuous output variable based on the one or more predictor variables.
✓ In Regression, we plot a graph between the variables which best fits the given datapoints, using this plot, the
machine learning model can make predictions about the data.
✓ In simple words, "Regression shows a line or curve that passes through all the datapoints on target-predictor
graph in such a way that the vertical distance between the datapoints and the regression line is minimum."
✓ Dependent Variable: The main factor in Regression analysis which we want to predict or understand is called
the dependent variable. It is also called target variable.
✓ Independent Variable: The factors which affect the dependent variables or which are used to predict the
values of the dependent variables are called independent variable, also called as a predictor.
✓ Underfitting and Overfitting: If our algorithm works well with the training dataset but not well with test
dataset, then such problem is called Overfitting. And if our algorithm does not perform well even with training
dataset, then such problem is called underfitting
➢ Cost Function
➢ Gradient Descent
➢ Model Performance
✓ Linear regression is a statistical regression method which is used for predictive analysis.
✓ It is one of the very simple and easy algorithms which works on regression and shows the relationship
between the continuous variables.
✓ Linear regression shows the linear relationship between the independent variable (X-axis) and the
dependent variable (Y-axis), hence called linear regression.
✓ Predictive modelling method to investigate the mathematical relationship between an independent
variable(predictor –x) and a continuous (float value) dependent variable (outcome-y), E.g., y = mx + c.
✓ Predictor shows the changes in the Dependent variable (y-axis) when the changes in explanatory variables
occur on the x-axis. It uses current information about a phenomenon to predict its future behavior.
✓ Simple Linear Regression: If a single independent variable is used to predict the value of a numerical
dependent variable, then such a linear regression algorithm is called Simple Linear regression.
✓ Multiple Linear Regression: If more than one independent variable is used to predict the value of a
numerical dependent variable , then such a linear regression algorithm is called “Multiple Linear Regression”.
Cost Function:
✓ The Cost Function is used to find the accuracy of the mapping function, Which maps the input variable to the
output variable. This mapping function is also known as “Hypothesis Function”.
✓ Mapping Function: Mapping to the input variables to output variables.
✓ For Linear Regression, we use the MSE cost function, which is the average of squared error occurred between
the predicted values and actual values.
Gradient Descent:
✓ Gradient Descent used to minimize the MSE by calculating the gradient of the cost function.
✓ A regression Model uses gradient descent to update the coefficients of the line by reducing the cost function.
✓ It is done by a random selection of Values of Coefficient and then iteratively update the values to reach the
minimum cost function.
✓ The goodness of Fit determines how the line of regression fits the set of observations.
✓ The process of finding the best model out of various models is called optimization.
✓ Mean Absolute error (MAE) − It is the average of the absolute difference between predicted values and true
values.
✓ Mean Squared error (MSE) − It is the average of the square of the difference between actual and estimated
values.
✓ Median Absolute error − It is the median value of the absolute difference between predicted values and true
values.
✓ Root mean square error (RMSE) − It is the square root value of the mean squared error (MSE).
✓ R2 (coefficient of determination) Score − the best possible score is 1.0, and it can be negative (because the
model can be arbitrarily worse).
✓ Mean absolute percentage error(MAPE) − It is the percentage equivalent of mean absolute error (MAE).
➢ Parameters: 𝜃0 , 𝜃1
1 2
➢ Cost function: 𝐽 𝜃0 , 𝜃1 = σ𝑚 ℎ𝜃 𝑥 𝑖
−𝑦 𝑖
2𝑚 𝑖=1
➢ Goal: minimize 𝐽 𝜃0 , 𝜃1
SCOPE, VIT-AP GVSN 88
We adjust the line using:
1. Cost Function
Measures how far predictions are from actual values.
2. Gradient Descent
This optimization algorithm updates the slope and intercept:
Mapping to 𝑦 = 𝑚𝑥 + 𝑐
Model: Price = 0.04 × 𝑆𝑖𝑧𝑒 + 0 Linear regression form Example meaning
(y) Price
𝑦 −𝑦 28−20 8
Find slope (m): 𝑚 = 𝑥2−𝑥1 𝑚 = 700−500 = 200 = 0.04 (x) Size
2 1
(m) 0.04 (slope)
(c) 0 (intercept)
Find intercept (c): Use 𝑦 = 𝑚𝑥 + 𝑐
Take any point (500, 20): 20 = 0.04 500 + 𝑐
Final equation: Price = 0.04 × 𝑆𝑖𝑧𝑒 + 0
𝑐 = 20 − 20 = 0
Mapping to 𝑦 = 𝑚𝑥 + 𝑐
Model: Sales = 10 × (Temp) − 100 Linear regression form Example meaning
(y) Sales
𝑦 −𝑦 150−100 50
Find slope (m): 𝑚 = 𝑥2−𝑥1 𝑚= = = 10 (x) Temperature
2 1 25−20 5
(m) 10 (slope)
(c) -100 (intercept)
Find intercept (c): Use 𝑦 = 𝑚𝑥 + 𝑐
Take any point (20, 100): 100 = 10 20 + 𝑐
Final equation: Sales = 10 × (Temp) − 100
𝑐 = 100 − 200 = −100
Example: let's say a person decides to buy a car. Then before coming up with a decision, we will look at few
aspects such as price, looks, maintenance, size, color, engine model, fuel capacity, mileage capacity, etc..
✓ The cost function in multivariate regression measures how well the prediction of the model matches the
actual values (observed data). By minimizing this error during model training, you can ultimately
improve the model’s accuracy.
✓ Mean Squared Error (MSE) is one of the most common cost functions for regression tasks. By
penalizing large errors more significantly than smaller ones, it encourages the model to make precise
predictions.
✓ By using techniques like parameter tuning, you can reduce MSE, thereby improving the model’s
accuracy over iterations.
✓ Selection of Features: It is the process of choosing the most relevant variables that contribute to
predicting the outcome. Through feature selection, you can avoid redundant features that can degrade the
model’s performance.
✓ Feature Normalizing: Features in your dataset may have different units or scales (e.g., age and marital
status), which can affect the regression analysis. Use techniques like min-max scaling or standardization
to scale the features so that they are all on a similar scale.
✓ Selecting Loss Function and Hypothesis: The loss function measures how well the model’s predictions
align with the actual outcomes. A common loss function is Mean Squared Error (MSE), which penalizes
larger errors more heavily.
✓ Reducing the Loss Function and Analyzing the Hypothesis Function: The loss function is reduced
using optimization techniques like Gradient Descent. After training, you have to analyze the model to see
if it makes sense logically and aligns with expectations. Gradient Descent iteratively minimizes the loss
function by updating parameters in the direction of the steepest descent.
✓ The objective is to model the target variable as a weighted sum of the input features, allowing for
prediction based on these relationships. It is widely used for continuous outcome variables.
✓ Multivariate linear regression in machine learning is calculated using the following formula.
𝒚 = 𝜷𝟎 + 𝜷𝟏 ∙ 𝒙𝟏 + 𝜷𝟐 ∙ 𝒙𝟐 + 𝜷𝟑 ∙ 𝒙𝟑 +∙∙∙∙∙ +𝜷𝒏 ∙ 𝒙𝒏 + 𝜺
1. Prepare the data: Collect your predictors (X) and target (y).
2. Add intercept column: Column of 1s to X.
3. Compute matrices:
▪ Xᵀ . X (dot product of transpose and X)
▪ Invert it: (Xᵀ . X)⁻¹
▪ Xᵀ . y
▪ Multiply: β = (Xᵀ . X)⁻¹ (Xᵀ . y)
4. Result: First value = intercept (β₀), rest = coefficients.
➢ Hours studied has the strongest positive effect (+5 points per hour, holding others constant).
➢ Attendance helps (+3 points per %).
➢ Sleep has a strong negative coefficient (data artifact—more sleep correlates with fewer hours studied here).
➢ Height is the main driver (+1.12 kg per cm, holding age constant).
➢ Age has a small positive effect (+0.09 kg per year).