IITP · Semester ISummaries · Quizzes · Assignments

Lecture summary

Advance Machine Learning

12 Sep 2026 · 09:251h 27m3 parts

Source: IITP-big-files\Sem-1\AML\Lectures\2026-09-12 0925 Advance Machine Learning\summary\notes.md

Overview

This class focused on the foundational concepts of supervised learning, specifically regression versus classification problems. It introduced the core algorithm of simple linear regression, covering its mathematical formulation, parameter derivation, and practical application. The session emphasized understanding the process from data exploration and feature selection to model training and prediction, setting the stage for implementation.

Learning outcomes

  • Distinguish between supervised, unsupervised, and reinforcement learning.
  • Identify whether a problem is regression or classification based on the target variable.
  • Explain the purpose and components of simple linear regression (slope, intercept).
  • Calculate the slope (β₁) and intercept (β₀) for a simple linear regression model using given formulas.
  • Select a suitable independent variable for regression using correlation analysis.

Core concepts

Supervised Learning

A type of machine learning where the model learns from labeled data (input-output pairs). It matters because it is the basis for predictive tasks like forecasting and categorization, forming the core of this lecture's focus on regression.

Regression vs. Classification

Regression predicts a continuous numerical value (e.g., price), while classification predicts a discrete class label (e.g., spam/not spam). Distinguishing between them is the first step in choosing the correct algorithm and evaluation metrics for a given problem.

Simple Linear Regression

An algorithm that models the linear relationship between one independent variable (x) and one dependent variable (y) using a best-fit line. It is foundational for understanding how models learn parameters from data to make predictions.

Correlation

A statistical measure ranging from -1 to 1 that quantifies the linear relationship between two variables. It is crucial for feature selection in linear regression, as the independent variable with the highest correlation to the target is typically chosen.

Model Training and Prediction

Training is the process of using known data (X, y) to calculate the model parameters (β₀, β₁). Prediction involves using these learned parameters with new input data (x) to estimate an output (ŷ). This encapsulates the end-to-end machine learning workflow.

Formulas and maths

  • Linear Model Equation: y = β₀ + β₁x
    Symbols: y is the predicted dependent variable; β₀ is the intercept; β₁ is the slope; x is the independent variable.
    Used when: Defining the relationship between variables or making a prediction after training.

  • Slope (β₁) Formula 1: β₁ = Σ(xᵢ - x̄)(yᵢ - ȳ) / Σ(xᵢ - x̄)²
    Symbols: xᵢ, yᵢ are individual data points; x̄, ȳ are the means of x and y.
    Used when: Calculating the slope from training data using deviations from the mean.

  • Slope (β₁) Formula 2 (alternative): β₁ = [nΣ(xy) - Σx Σy] / [nΣ(x²) - (Σx)²]
    Symbols: n is the number of data points; Σ denotes summation.
    Used when: Calculating the slope directly from sums of the data.

  • Intercept (β₀) Formula: β₀ = ȳ - β₁x̄
    Symbols: ȳ is the mean of y; β₁ is the slope; x̄ is the mean of x.
    Used when: Calculating the intercept after the slope is known.

Worked examples

  • Prediction Example: Given a linear equation y = 1.5x + 2 and a new input x = 5, the predicted output is y = 1.5*5 + 2 = 9.5.
  • Mean Calculation: For independent variable values like 10, 15, 12, 13, 4, 31, if the mean (x̄) is 29, then the deviation for the first value is xᵢ - x̄ = 10 - 29 = -19.
  • Correlation Selection: In a car price dataset, correlation scores with price were analyzed: Symboling (-0.082), Wheelbase (0.58), Length (0.69), Width (0.75), Engine size (0.87). Engine size, with the highest correlation of 0.87, was chosen as the independent variable (x) for predicting price (y).

Questions asked in class

  • Q: What is the difference between accuracy and F1 score?
    A: Accuracy = number of correct predictions ÷ total predictions = (TP + TN) / (TP + TN + FP + FN). F1 score is the harmonic mean of precision and recall, requiring understanding of the confusion matrix.
  • Correction: the "percentage difference between predicted and actual" wording used in class is loose. For classification, accuracy is the share of correct predictions.
  • Q: Can you confirm cross-entropy is used to measure error for classification?
    A: Yes, 100%. Cross-entropy measures error in classification.
  • Q: Is it possible to share the notebook prior to call so we can execute?
    A: No, execution is not the immediate focus. Understanding the concept is more important. Materials will be provided later.
  • Q: I thought slope is the (y mean - y i) divided by (x mean - x i).
    A: That ratio also describes the relationship. The given formulas are standard and can be verified online.
  • Q: If we already have x and y then why we are required to find [the line]?
    A: We use the known x and y (training data) to calculate β₀ and β₁ to create the model. This model can then predict y for new, unseen x values.
  • Q: Could you please explain how the formula for beta1 is derived?
    A: Yes, 100%. You need to memorize it. The formulas for slope and intercept are fixed.
  • Q: Can you re-explain why we are choosing engine size?
    A: We check the correlation score via a heatmap. Our dependent variable is price. Engine size has the highest correlation (0.87) with price, so it is chosen.
  • Q: Is calculating beta 0, beta 1 for every feature actually finding the correlation?
    A: No. Correlation score is only used for finding/choosing the independent variable. Beta 0 and beta 1 are for the linear regression model itself.

Key takeaways

  • Supervised learning uses labeled data (input-output pairs) for training.
  • Regression predicts continuous values; classification predicts discrete classes.
  • Simple linear regression models the relationship as y = β₀ + β₁x.
  • The slope (β₁) is calculated as Σ(xᵢ - x̄)(yᵢ - ȳ) / Σ(xᵢ - x̄)² or [nΣ(xy) - Σx Σy] / [nΣ(x²) - (Σx)²].
  • The intercept (β₀) is calculated as ȳ - β₁x̄.
  • Linear regression requires numeric data.
  • Correlation (range: -1 to 1) measures linear relationship strength and is used for feature selection.
  • The independent variable with the highest correlation to the target should be selected for simple linear regression.
  • Model training finds β₀ and β₁ from training data (X, y).
  • The trained model (defined by β₀, β₁) is used to predict y for new x.
  • Accuracy and F1 score are evaluation metrics for classification models.
  • Cross-entropy is an error measure for classification problems.

Exam-style questions

  1. Given a small dataset of (x, y) pairs, calculate the slope (β₁) and intercept (β₀) for the simple linear regression line.
    Outline: Calculate x̄ and ȳ. Compute Σ(xᵢ - x̄)(yᵢ - ȳ) and Σ(xᵢ - x̄)². Apply formula β₁ = Σ(xᵢ - x̄)(yᵢ - ȳ) / Σ(xᵢ - x̄)². Then calculate β₀ = ȳ - β₁x̄.

  2. A dataset has a target variable 'price' and features 'engine size' (corr=0.87) and 'length' (corr=0.69). Which feature should be used as the independent variable in a simple linear regression model to predict price, and why?
    Outline: Choose 'engine size'. In simple linear regression, you select the single independent variable with the highest absolute correlation to the dependent variable to model the strongest linear relationship.

  3. Describe the step-by-step process, from raw data to prediction, for building a simple linear regression model.
    Outline: 1) Load and explore data. 2) Ensure target (y) and feature (x) are numeric. 3) Select the feature (x) with highest correlation to y. 4) Calculate x̄ and ȳ from training data. 5) Compute β₁ using the slope formula. 6) Compute β₀ = ȳ - β₁x̄. 7) The model is now defined. 8) For a new x, predict y using y = β₀ + β₁x.

Glossary

  • Supervised Learning - Learning from labeled input-output data.
  • Regression - A predictive modeling task with a continuous numerical output.
  • Classification - A predictive modeling task with a discrete class output.
  • Independent Variable (Feature) - The input variable (x) used to make predictions.
  • Dependent Variable (Target) - The output variable (y) to be predicted.
  • Linear Regression - An algorithm that models a linear relationship between one independent and one dependent variable.
  • Slope (β₁) - The coefficient representing change in y per unit change in x.
  • Intercept (β₀) - The predicted value of y when x is 0.
  • Correlation - A measure of the linear relationship between two variables, ranging from -1 to 1.
  • Training Data - The dataset used to train (calculate parameters for) the model.
  • Prediction - Using a trained model to estimate an output for new input data.

Follow-ups

  • Detailed explanation of confusion matrix, precision, recall, and F1 score promised for the classification segment.
  • Full implementation of linear regression—both mathematical calculation and using scikit-learn—to be covered.
  • Explanation of how to derive the slope (β₁) formula is not covered; students are to memorize it.
  • Assignment will be provided very soon.
  • The process of calculating β₀ and β₁ for the chosen feature (engine size) will be completed in the next class.
  • The instructor will share notes and code later.