session: "6103-advanced-ml/2026-09-19 0925 Advance Machine Learning"
title: "Advance Machine Learning"
date: "2026-09-19 09:25"
duration: "1h 16m"
language: "en"
model: "deepseek-ai/DeepSeek-V3.2"
parts: 2
transcript_chars: 52251
generated: "2026-11-23T01:51:54+05:30"
Advanced Machine Learning
Overview
This class covered the fundamentals of linear regression, building on previous introductory concepts. It focused on the mathematical derivation of the simple linear regression model, including calculating the slope and intercept. The session applied these concepts to a real dataset (automobile.csv) to predict car price using engine size, evaluated the model using R-squared, and introduced practical implementation with scikit-learn. This forms the foundational regression module within the broader machine learning course.
Learning outcomes
- Define and explain the components of a simple linear regression model (y = β₀ + β₁x).
- Calculate the slope (β₁) and intercept (β₀) for a given dataset using their formulas.
- Select an appropriate independent variable (predictor) by analyzing correlation with the target.
- Fit a best-fit regression line to data points.
- Evaluate a regression model using the R-squared metric.
- Distinguish between Sum of Squares Regression (SSR), Sum of Squares Error (SSE), and Sum of Squares Total (SST).
Core concepts
Linear Model
A model that assumes a linear relationship between an independent variable (x) and a dependent variable (y), expressed as y = β₀ + β₁x. It matters because it is the simplest form of regression and the foundation for more complex models. It connects directly to model fitting and evaluation.
Slope (β₁) and Intercept (β₀)
The slope (β₁) represents the rate of change of y with respect to x, while the intercept (β₀) is the predicted value of y when x is zero. They are crucial as they uniquely define the regression line. They are calculated from the data and are central to making predictions.
Correlation for Feature Selection
Correlation measures the strength and direction of the linear relationship between two variables. It matters because the independent variable with the highest correlation to the target is typically chosen as the predictor to build a more effective model. This connects to the initial data exploration and model setup phase.
R-squared (R²)
A statistical measure that represents the proportion of the variance in the dependent variable that is predictable from the independent variable. It matters as it is the primary metric for evaluating the goodness-of-fit in regression models. It connects model evaluation to the concepts of SSR, SSE, and SST.
Sum of Squares (SSR, SSE, SST)
These decompose the total variance in the data: SSR (Regression) explains variance from the model, SSE (Error) captures unexplained variance, and SST (Total) is the total variance. They matter because they quantify model performance and are directly used to calculate R-squared. They connect the mathematical model to its evaluation.
Formulas and maths
- Regression Line: \( y = \beta_0 + \beta_1 x \)
- \( y \): Dependent/Target variable.
- \( \beta_0 \): Intercept.
- \( \beta_1 \): Slope.
- \( x \): Independent/Predictor variable.
- Used to model the linear relationship and make predictions.
- Slope (β₁): \( \beta_1 = \frac{\Sigma[(x_i - \bar{x})(y_i - \bar{y})]}{\Sigma[(x_i - \bar{x})^2]} \)
- \( x_i, y_i \): Individual data points.
- \( \bar{x}, \bar{y} \): Means of x and y.
- Used to calculate the rate of change in the linear model.
- Intercept (β₀): \( \beta_0 = \bar{y} - \beta_1\bar{x} \)
- \( \bar{y} \): Mean of y.
- \( \beta_1 \): Slope.
- \( \bar{x} \): Mean of x.
- Used to calculate the baseline value of y when x is zero.
- R-squared: \( R^2 = 1 - \frac{SSE}{SST} \)
- \( SSE \): Sum of Squares Error.
- \( SST \): Sum of Squares Total.
- Used to evaluate the goodness-of-fit of a regression model.
- Sum of Squares Error (SSE): \( SSE = \Sigma(y_i - \hat{y}_i)^2 \)
- \( y_i \): Actual value.
- \( \hat{y}_i \): Predicted value.
- Used to quantify the total prediction error/variance.
- Sum of Squares Total (SST): \( SST = \Sigma(y_i - \bar{y})^2 \)
- \( y_i \): Actual value.
- \( \bar{y} \): Mean of y.
- Used to quantify the total variance in the target variable.
- Sum of Squares Regression (SSR): \( SSR = \Sigma(\hat{y}_i - \bar{y})^2 \)
- \( \hat{y}_i \): Predicted value.
- \( \bar{y} \): Mean of y.
- Used to quantify the variance explained by the regression model.
Worked examples
1. Automobile Dataset Example:
- Target (y): Car price.
- Predictor (x): Engine size (chosen due to highest correlation with price: 0.87).
- After calculating slope and intercept, a best-fit line was plotted (engine size vs. price).
- Model evaluation yielded an R-squared value of 76% (0.76).
2. Hand-Calculation Example 1:
- Data points: (2,4), (3,5), (5,7), (7,10), (9,15).
- Calculated slope (m or β₁): 1.518.
- Calculated intercept (c or β₀): 0.305.
- Regression equation: \( y = 1.518x + 0.305 \).
- Prediction for x=8: \( y = 1.518*8 + 0.305 = 12.45 \).
- Error calculation for x=2: Actual=4, Predicted=3.3, Error=0.67.
3. Hand-Calculation Example 2:
- Calculated slope (m): \( 13/10 = 1.3 \).
- Calculated intercept (c): \( 5.5/5 = 1.1 \).
- Regression equation: \( y = (13/10)x + (5.5/5) \).
- Prediction for x=10: \( y = 14.2 \).
Questions asked in class
- Q: Where can we see the implementation in a practical scenario?
- A: Practically everywhere, e.g., stock market price prediction. Linear regression can be used to predict any continuous value.
- Q: If training is not accurate, which parameter can we change to reduce total error?
- A: In this basic algorithm, there is no hyperparameter tuning. The coefficients (β₁ and β₀) are derived mathematically from the dataset. To improve the model, you need to correct the dataset itself.
- Q: Do β₀ and β₁ always change when we rerun the model?
- A: No, β₀ and β₁ will not change if the dataset remains the same because the calculation is purely mathematical. They change only if the dataset changes.
- Q: How is training happening? Is it only one iteration?
- A: In this simple example, it is a single iteration. In more advanced machine learning, iterations would update β₀ and β₁ multiple times, but here we focus on the single mathematical calculation.
- Q: How do we decide accuracy in regression?
- A: In regression, we use R-squared, not accuracy. Accuracy is a metric for classification problems.
- Q: Can we use multiple independent variables?
- A: Yes, that is multiple linear regression. You can use more features alongside engine size.
- Q: How to create a heat map?
- A: Use a library (e.g., seaborn) with
sns.heatmap(data.correlation()). - Q: Does the correlation heat map change if we train the data multiple times?
- A: No, heat map is for data pre-processing; it remains the same for all iterations.
- Q: Is it possible that the highest-correlation feature gives a poor result on test data, but the second-best gives a better result?
- A: Yes, it might be possible. Machine learning involves trial and error; the highest correlation is correct 99.99% of the time, but not 100%.
- Q: In the code, are predictor and target used for both training and testing?
- A: In this demonstration, the same data was used for both, but the correct approach is to split data into train/test sets (e.g., 70% train, 30% test).
- Q: What is the role of a confusion matrix?
- A: Confusion matrix is used for classification problems, not regression.
Key takeaways
- The simple linear regression model is defined as \( y = \beta_0 + \beta_1 x \).
- The slope (\( \beta_1 \)) and intercept (\( \beta_0 \)) are calculated directly from the data using closed-form formulas.
- The independent variable (predictor) is chosen based on the highest correlation with the dependent variable (target).
- R-squared is the primary evaluation metric for regression models, calculated as \( 1 - (SSE / SST) \).
- SSE measures unexplained variance, SST measures total variance, and SSR measures explained variance.
- In the automobile example, engine size (correlation 0.87) predicted price with an R-squared of 0.76.
- For a given dataset, the calculated β₀ and β₁ are fixed and do not change unless the data changes.
- Training in this context is a single, mathematical calculation, not an iterative optimization process.
- A correlation heatmap is a pre-processing tool and does not change with model training iterations.
- The highest-correlation feature is not guaranteed to yield the best model on unseen test data.
- Proper model evaluation requires splitting data into separate training and testing sets.
- A confusion matrix is not used for evaluating regression models.
Exam-style questions
1. Given the data points (1,2), (2,3), (4,6), calculate the slope (β₁) and intercept (β₀) for the linear regression model.
- Outline: Calculate means of x and y. Apply the formula for β₁: Σ[(xᵢ - x̄)(yᵢ - ȳ)] / Σ(xᵢ - x̄)². Then calculate β₀ using β₀ = ȳ - β₁x̄.
2. A linear regression model on a dataset yields an SSE of 45 and an SST of 180. Calculate the R-squared value and interpret what it means.
- Outline: Use R² = 1 - (SSE/SST) = 1 - (45/180) = 0.75. Interpretation: The model explains 75% of the variance in the target variable.
3. When building a simple linear regression model to predict house price, you find that 'square footage' has a correlation of 0.82 with price, and 'number of bedrooms' has a correlation of 0.76. Which feature should you choose as your independent variable, and why?
- Outline: Choose 'square footage' because it has the highest correlation with the target variable (price), which is the standard heuristic for selecting a predictor in simple linear regression.
Glossary
- Best-fit line - The linear line that best approximates all data points in a scatter plot.
- Correlation - A measure of the strength and direction of the linear relationship between two variables.
- Dependent/Target variable - The output variable to be predicted in a model.
- Independent/Predictor variable - The input feature used to predict the target variable.
- Intercept (β₀ or c) - The point where the regression line crosses the y-axis.
- Linear regression - A method to model the relationship between a dependent variable and one or more independent variables using a linear approach.
- R-squared (R²) - A statistical measure that shows the proportion of variance in the dependent variable explained by the independent variable(s).
- Slope (β₁ or m) - The rate of change of the dependent variable with respect to the independent variable in a linear model.
- Sum of Squares Error (SSE) - The sum of squared differences between actual and predicted values.
- Sum of Squares Regression (SSR) - The sum of squared differences between predicted values and the mean of the target.
- Sum of Squares Total (SST) - The sum of squared differences between actual values and the mean of the target.
Follow-ups
- The Jupyter notebook (ipynb file) from the previous class is incomplete and will be uploaded after this live session.
- Assignment details will be clarified in a Tuesday class by another instructor.
- Students should use an 88-page Python notes document (version 2) for code, as the Jupyter notebook will not be uploaded.
- Assignment 1 will be available from September 22nd and will cover topics taught before linear regression.
- Instructor plans to upload PPT and Jupyter notebook files after class.
Exam verification — corrections & additions
- R² range: R² = 1 − SSE/SST lies between 0 and 1 for a model with an intercept on the training data.
- R² vs adjusted R²: adding a feature never decreases R²; adjusted R² can decrease because it penalises extra features. Common exam trap.
- MSE vs SSE: MSE = SSE/n, so MSE is preferred — it does not depend on the size of the data set.
- Full 80-question answer key:
C:\PORJECTX\aml-import\AML-FINAL-EXAM-ANSWER-KEY.md