Machine Learning

Types & Key Concepts

Supervised, unsupervised, and reinforcement learning types plus core ML terminology and concepts.

Types of Machine Learning

High-level Overview

Different ML problems require different learning paradigms. At a high level, we categorize ML algorithms by how they learn from data and what kind of feedback they receive.

  • Supervised Learning: learn from labeled input–output pairs.
  • Unsupervised Learning: discover structure in unlabeled data.
  • Semi-Supervised Learning: mix of small labeled and large unlabeled data.
  • Reinforcement Learning: learn by interacting with an environment via rewards.

Think of supervised learning as learning with an answer key, unsupervised learning as exploring without a teacher, and reinforcement learning as learning by trial and error with rewards and penalties.

Supervised Learning

In supervised learning, each training example comes with a label. The algorithm learns a mapping from inputs \(X\) to outputs \(y\).

Regression Examples
  • Predicting house prices from features (size, location, rooms).
  • Forecasting sales given marketing spend.
  • Estimating medical costs from patient data.
Classification Examples
  • Spam vs non‑spam email detection.
  • Fraudulent vs normal transactions.
  • Image classification (cat vs dog).
Simple supervised learning in scikit‑learn
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42
)

model = LogisticRegression()
model.fit(X_train, y_train)
accuracy = model.score(X_test, y_test)

Unsupervised Learning

Unsupervised learning works with unlabeled data. The goal is to discover patterns, structure or groupings in the data.

Clustering
  • Customer segmentation in marketing.
  • Grouping similar news articles.
  • Image compression with K‑Means.
Dimensionality Reduction
  • PCA to reduce features before modeling.
  • t‑SNE or UMAP for visualization.
K‑Means clustering example
from sklearn.cluster import KMeans

kmeans = KMeans(n_clusters=3, random_state=42)
clusters = kmeans.fit_predict(X)

print(kmeans.cluster_centers_)

Semi-Supervised Learning

Semi‑supervised learning sits between supervised and unsupervised learning. It uses a small amount of labeled data together with a large amount of unlabeled data.

When is it useful?
  • Labeling data is expensive (medical images, legal documents).
  • You have thousands of unlabeled examples, but only a few labels.

Reinforcement Learning

In Reinforcement Learning (RL), an agent interacts with an environment. It takes actions, receives rewards and tries to maximize cumulative reward over time.

  • State \(s_t\): current situation.
  • Action \(a_t\): choice made by the agent.
  • Reward \(r_t\): feedback from the environment.
  • Policy \(\pi\): strategy that maps states to actions.

Classic RL applications include game playing (Chess, Go), robotics, recommendation systems and dynamic pricing.

Core Machine Learning Concepts & Terminology

Datasets, Features & Labels

A typical ML dataset can be represented as a matrix \(X\) (rows = samples, columns = features) and a target vector \(y\) (labels).

  • Sample / Instance: a single row of data (e.g., one customer, one transaction).
  • Feature: an input variable (age, income, number of clicks).
  • Label / Target: what we want to predict (price, churn yes/no).
samples features labels tabular data

Training, Validation & Test Sets

We split the dataset to estimate how well our model will perform on unseen data:

  • Training set: used to fit the model parameters.
  • Validation set: used for model selection and hyperparameter tuning.
  • Test set: used once at the end to report final performance.
Rule of thumb: never use your test data to make modeling decisions. That leads to optimistic and unreliable metrics.

Overfitting vs Underfitting

Models must balance fit and simplicity:

  • Underfitting: model is too simple, cannot capture the pattern (high bias).
  • Overfitting: model memorizes noise in training data (high variance).
  • Just right: low training error and low validation error.

Loss Functions & Evaluation Metrics

During training, we minimize a loss function. After training, we report metrics that are easier to interpret.

  • Regression: MSE, RMSE, MAE, \(R^2\).
  • Classification: Accuracy, Precision, Recall, F1‑Score, ROC‑AUC.