Classical Machine Learning Foundations
learning the core algorithms and concepts behind predictive modeling
Core Concepts Covered
- Supervised vs. unsupervised vs. reinforcement learning
- Linear & logistic regression, decision trees, and SVMs
- Clustering and model evaluation metrics
Local Setup Recommendation
To execute and experiment with the code cells below on your local machine, ensure you have set up your isolated virtual environments and scientific libraries by following the detailed protocols in Unit 03: Environment Setup or run them in Google Colab.
1. Taxonomy of Machine Learning
Machine Learning algorithms are broadly categorized based on the nature of the training data and feedback loops they receive:
• Supervised Learning: The model is trained on labeled historical examples containing both features and explicit targets. If the target is a continuous real number (like predicting house prices), it is a Regression problem. If the target is a discrete label (like classifying an email as *Spam* or *Inbox*), it is a Classification problem.
• Unsupervised Learning: The dataset contains no target labels. The model's objective is to autonomously discover hidden structures, correlations, or natural groupings inside the input features (such as customer segmentation clustering).
• Reinforcement Learning: An autonomous agent learns optimal decision-making policies by taking actions within an environment to maximize a scalar feedback reward over time (such as training an autopilot or a game-playing engine).
2. Core Linear Models: Regression and Classification
• Linear Regression: Models a linear relationship between features and a continuous target . We define the prediction as and optimize parameters by minimizing the Sum of Squared Errors (SSE) loss function:
• Logistic Regression: Used for binary classification. Instead of outputting unbounded continuous values, it passes the linear combination through the Sigmoid (logistic) Function to map any real number to a probability value strictly between 0 and 1:
,
The model is optimized by minimizing the Binary Cross-Entropy loss function, which penalizes predictions that diverge from actual class labels.
# Practical implementation of Linear and Logistic regressions using Scikit-Learn
from sklearn.linear_model import LinearRegression, LogisticRegression
import numpy as np
# Linear Regression: Predict continuous outputs
X_reg = np.array([[1], [2], [3], [4]])
y_reg = np.array([2.1, 3.9, 6.1, 8.0])
reg_model = LinearRegression().fit(X_reg, y_reg)
print("Linear Regression Slope (w):", reg_model.coef_[0].round(2))
print("Linear Regression Intercept (b):", reg_model.intercept_.round(2))
# Logistic Regression: Classify binary categories
X_clf = np.array([[1], [2], [5], [6]])
y_clf = np.array([0, 0, 1, 1])
clf_model = LogisticRegression().fit(X_clf, y_clf)
print("Logistic Prediction for x=1.5 (Class):", clf_model.predict([[1.5]])[0])
print("Logistic Probabilities for x=3.5 (P(0), P(1)):", clf_model.predict_proba([[3.5]])[0].round(2))Linear Regression Slope (w): 1.98
Linear Regression Intercept (b): 0.08
Logistic Prediction for x=1.5 (Class): 0
Logistic Probabilities for x=3.5 (P(0), P(1)): [0.5 0.5]3. Non-Linear Models: SVMs, Decision Trees, and K-Means
When datasets are complex and cannot be separated by simple straight lines, we use non-linear models:
• Support Vector Machines (SVMs): Finds an optimal decision hyperplane that maximizes the Margin (the perpendicular distance) between different classes. The closest boundary coordinates of each class are the Support Vectors.
• The Kernel Trick (Intuitive Analogy): Imagine drawing a circle of red dots on a sheet of paper, surrounded by a larger ring of blue dots. You cannot draw a straight line on that 2D paper to separate them. However, what if you 'pop' the center of the paper upward, pushing the red dots into 3D space? You can now pass a flat 2D sheet of glass (a linear hyperplane) horizontally between the floating red dots and the flat blue dots. The Kernel Trick is a mathematical shortcut that allows SVMs to project low-dimensional data into higher-dimensional spaces where they become linearly separable, without ever needing to compute the expensive high-dimensional coordinates explicitly!
• Decision Trees & Random Forests: Decision Trees recursively partition the feature space by making sequential splits that maximize Information Gain (reducing Gini Impurity or Shannon Entropy). To prevent a single tree from overfitting, a Random Forest trains hundreds of independent trees on random subsets of samples and features (bagging), averaging their votes.
• K-Means Clustering: An unsupervised algorithm that partitions unlabeled data into distinct clusters. It starts with random centroids, assigns points to the nearest centroid, updates centroids, and repeats until convergence. We evaluate clustering quality using the Silhouette Score (measuring how close a point is to its own cluster compared to others, on a scale from to ).
4. Classification Metrics and Model Evaluation
To evaluate our models, we construct a Confusion Matrix tracking True Positives (), False Positives (), True Negatives (), and False Negatives (). From these, we calculate crucial evaluation metrics:
• Accuracy: Overall proportion of correct predictions: .
• Precision: Out of all positive predictions, how many were actually positive? Highly critical when false positives are expensive (e.g., spam filters):
• Recall (Sensitivity): Out of all actual positive samples, how many did the model find? Highly critical when false negatives are dangerous (e.g., medical diagnoses):
• -Score: The harmonic mean of Precision and Recall, providing a robust evaluation metric for highly imbalanced datasets:
Hands-On Kaggle Challenge #1
Titanic: Machine Learning from Disaster
The most famous starter classification challenge on Kaggle! Predict survival outcomes on the Titanic using classification models (like Support Vector Machines, Logistic Regression, or Decision Trees) and submit your predictions to get ranked on the live leaderboard.
Hands-On Kaggle Challenge #2
House Prices: Advanced Regression Techniques
The classic starter regression challenge! Predict sales prices of residential houses using advanced regressions and tree-based ensembles (like Random Forests or Gradient Boosting) and submit your predictions.
Interactive Practice Quiz
Test your understanding with instant feedback
Which of the following describes the mathematical output range of the Sigmoid activation function ?
If a cancer diagnostic model must minimize the danger of missing actual positive cancer cases (False Negatives), which metric should we prioritize maximizing?
Under which task category does 'K-Means Clustering' fall, given that the input dataset has no target label columns?
What is the primary role of the Support Vector Machine (SVM) algorithm?
Compute the -Score for a classification model that achieves a Precision of and a Recall of :
What is the core mathematical purpose of the 'Kernel Trick' inside Support Vector Machines?
How do Decision Trees choose split points during training?
What is the core mechanism of the Random Forest ensemble model?
Which of the following describes the meaning of a Silhouette Score of in K-Means clustering?
The loss function minimized by standard Linear Regression is called:
Further Readings
Explore these highly recommended external references to deepen your understanding
