1. Home
  2. Explore
  3. Computer Science
  4. Machine Learning Models Overview

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Machine Learning Models Overview

Every Major Machine Learning Model Explained

Introduction to Machine Learning

Machine learning is the practice of giving computers a large amount of data and allowing them to slowly figure out patterns and make predictions, rather than hard-coding every instruction. All machine learning can be divided into two broad categories: supervised learning and unsupervised learning.

Supervised Learning

In supervised learning, the model is trained on labeled data — for every input, there is a correct answer provided. The model learns by comparing its predictions to the correct answers and adjusting itself until it gets better. This is analogous to studying with an answer key: the student knows the right answers and practices until they can produce them independently.

Within supervised learning, there are two main types of tasks:

  • Regression: Predicting a continuous numerical value — the output can be any number along a range. Examples: predicting house prices, forecasting temperature, estimating salary.

  • Classification: Predicting a discrete category — the output is one of a fixed set of options, with no in-between. Examples: spam detection (spam / not spam), medical diagnosis (malignant / benign), image recognition (cat / dog).

Unsupervised Learning

In unsupervised learning, the model is given data without labels and must discover patterns and structure on its own. There is no "answer key." The model looks at raw data and finds natural groupings, relationships, or simplifications. For example, given a million customer transactions, unsupervised learning can automatically identify distinct groups such as big spenders, occasional browsers, and discount hunters — without being told those groups exist.


Supervised Learning Models

Linear Regression

Linear Regression is the simplest regression model. It finds the best-fitting straight line through a scatter plot of data points. The goal is to predict an output YYY (the dependent variable) based on an input XXX (the independent variable). For instance, predicting exam scores from hours studied: each student becomes a point on a graph, and the line is drawn to minimize the distance between all points and itself.

The equation for simple linear regression is:

Y^=β0+β1X\hat{Y} = \beta_0 + \beta_1 XY^=β0​+β1​X
  • Y^\hat{Y}Y^: predicted output

  • β0\beta_0β0​: intercept — where the line crosses the Y-axis

  • β1\beta_1β1​: slope — how much YYY changes for every one-unit increase in XXX

  • XXX: input feature

Multiple linear regression extends this to several features:

Y^=β0+β1X1+β2X2+⋯+βnXn\hat{Y} = \beta_0 + \beta_1 X_1 + \beta_2 X_2 + \dots + \beta_n X_nY^=β0​+β1​X1​+β2​X2​+⋯+βn​Xn​

Each XXX represents a different independent variable (e.g., hours studied, hours slept, assignments completed), and each β\betaβ coefficient tells how much that feature contributes to the prediction.

Linear Regression is best used when predicting a continuous numerical value with a clear relationship between inputs and output.

Logistic Regression

Despite its name, Logistic Regression is used for classification, typically binary classification (yes/no, true/false, 0/1). For example, predicting whether a patient has a disease based on age, blood pressure, and cholesterol.

The core idea: take the linear regression equation and pass it through a sigmoid function, which produces an S-shaped curve that squishes the output to a value between 0 and 1. This output is interpreted as a probability.

Y^=11+e−(β0+β1X1+⋯+βnXn)\hat{Y} = \frac{1}{1 + e^{-(\beta_0 + \beta_1 X_1 + \dots + \beta_n X_n)}}Y^=1+e−(β0​+β1​X1​+⋯+βn​Xn​)1​

If the model outputs 0.85, it is 85% confident the patient has the disease. A cutoff (usually 0.5) determines the final classification: above 0.5 is "yes," below is "no."

Logistic Regression is best used for binary classification when the relationship between inputs and output is relatively straightforward.

Naïve Bayes

Naïve Bayes is a classification algorithm built on Bayes' Theorem and a "naïve" assumption: all input features are completely independent of each other. This means one feature has no influence on another.

Bayes' Theorem formula:

P(A∣B)=P(B∣A)⋅P(A)P(B)P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)}P(A∣B)=P(B)P(B∣A)⋅P(A)​

In plain terms: take what you already believed P(A)P(A)P(A), update it based on new evidence P(B∣A)P(B|A)P(B∣A), and you get a smarter, more informed probability P(A∣B)P(A|B)P(A∣B).

For text classification (e.g., spam detection), the algorithm scans each word independently, asks "given that this email is spam, how likely is this word?" multiplies all probabilities together, and compares the result for spam vs. not spam. The class with higher probability wins.

Naïve Bayes is best used when a fast, lightweight classifier is needed — especially on text data, where it performs reliably with low computational overhead.

K-Nearest Neighbors (KNN)

K-Nearest Neighbors (KNN) classifies a new data point by looking at the kkk closest points in the training data and taking a majority vote (for classification) or the average (for regression). The idea is simple: to predict what something is, look at what's around it.

  • Classification: The predicted class is the most common class among the kkk nearest neighbors.

  • Regression: The predicted value is the average of the neighbors' values.

Distance between points is typically measured using Euclidean distance (straight-line distance) in feature space.

The value of kkk is chosen by the user (e.g., k=3k=3k=3, k=5k=5k=5). A smaller kkk makes the model more sensitive to noise; a larger kkk makes it smoother.

KNN is best used when the dataset is small and relationships between data points are based on similarity.

Support Vector Machines (SVM)

Support Vector Machines (SVM) is a classification algorithm that finds the best possible boundary — called a hyperplane — that separates two classes of data. The goal is not just any boundary, but the one with the maximum margin: the largest distance between the hyperplane and the nearest data points from each class.

Those closest data points are called support vectors — they "hold up" the boundary.

When data is not linearly separable, SVM uses the Kernel Trick: it transforms the data into a higher dimension where a hyperplane can separate the classes. This is analogous to lifting dots off a flat table into 3D space so a flat plane can separate them perfectly.

SVM works best when there is a clear margin of separation between classes and when dealing with high-dimensional data (e.g., text classification, image recognition).


Tree-Based Models

Decision Trees

A Decision Tree is a tree-like structure of yes-or-no questions that leads to a prediction. It repeatedly splits the data into smaller groups based on the most informative feature at each step, until it reaches a final answer.

  • Root node: the first split at the top, the most important one.

  • Leaf nodes: the final nodes at the bottom where predictions are made.

  • Internal nodes: decision points that split based on a feature.

For example, a bank might use a Decision Tree to predict loan approval: start with income level, then credit score, then employment status — each split narrows down the risk profile until a final decision (approve / reject) is reached.

Decision Trees are most useful when interpretability matters — the student can literally follow the branches and see exactly how each prediction was made.

Random Forest

A Random Forest is an ensemble of many Decision Trees. Instead of relying on one tree, it builds hundreds and lets them vote. This approach of combining multiple models is called ensemble learning.

Random Forest introduces two key twists:

  1. Random data sampling: Each tree is trained on a random subset of the training data, so each tree sees a slightly different version.

  2. Random feature selection: At each split, each tree considers only a random subset of the features.

These tricks force diversity among the trees, and their individual mistakes cancel out when voting — leading to more robust predictions.

Random Forest is best used when you need high accuracy and robustness, especially on structured data, without much tuning.

XGBoost

XGBoost (Extreme Gradient Boosting) is a powerful algorithm that builds trees sequentially — each new tree learns from the mistakes of the previous one. This is the core idea of boosting.

The "gradient" part refers to using gradient descent to minimize a loss function (a measure of how wrong the model's predictions are). Each new tree is built in the direction that reduces the error the most.

Unlike Random Forest, which builds trees independently, XGBoost focuses each tree on the errors of the previous one, leading to very high predictive performance.

XGBoost is best used when maximum predictive performance is needed on structured, tabular data — it is a top performer in many machine learning competitions.


Neural Networks

Neural Networks (Multilayer Perceptron)

Neural Networks are loosely inspired by the human brain. They consist of layers of interconnected nodes (neurons):

  • Input layer: data enters the network; each node represents one feature (e.g., age, income, pixel value).

  • Hidden layers: layers between input and output where the actual learning happens — the network detects patterns by adjusting the connections between nodes.

  • Output layer: the final prediction is produced.

Each connection between neurons has a weight — a number that determines how much influence one node has on the next. During training, the network adjusts these weights to minimize prediction errors, gradually improving.

Neural Networks are best used when the data is complex and high-dimensional (images, audio, text) — they excel at discovering patterns traditional algorithms cannot find.

Convolutional Neural Networks (CNN)

Convolutional Neural Networks (CNNs) are designed specifically for data with a grid-like structure — most commonly images. While a regular neural network treats every input equally, a CNN understands that nearby pixels are related and should be processed together.

The core operation is convolution: the network slides a small filter across the image, scanning it piece by piece to detect patterns like edges, shapes, and textures.

  • Early layers: detect simple patterns (edges, corners).

  • Deeper layers: combine simple patterns into complex ones (eyes, ears, faces).

This is like going from recognizing individual letters to words to full sentences.

CNNs are best used when data has spatial structure — they are the go-to choice for image recognition, video analysis, and medical imaging.

Transformers

Transformers are an AI architecture that processes entire sequences at once (e.g., whole sentences) rather than one word at a time. They have revolutionized natural language processing and power virtually all modern large language models (ChatGPT, Gemini, etc.).

The key innovation is self-attention: instead of processing words sequentially, the transformer looks at the entire sequence simultaneously and figures out which words are most relevant to each other. This allows it to understand long-range relationships and context.

For example, in "The trophy didn't fit in the suitcase because it was too big," a transformer can correctly determine that "it" refers to the suitcase, while older sequential models struggled.

Transformers are best used for tasks involving sequences — language understanding, translation, summarization, and any problem where long-range context matters.

Generative Adversarial Networks (GANs)

Generative Adversarial Networks (GANs) are designed to generate entirely new data (images, audio, video, text) through a two-player game between two neural networks:

  • Generator: creates fake data that looks as realistic as possible.

  • Discriminator: examines data and decides whether it is real or fake.

The two networks are trained simultaneously in competition: as the discriminator gets better at spotting fakes, the generator must improve to fool it. Over time, the generator becomes so good that the discriminator can no longer tell the difference.

This is analogous to an art forger and an art detective: the forger produces fake paintings, the detective learns to spot them, and the forger must improve, round after round.

GANs are best used when the goal is to generate new, realistic data — deepfakes, AI art, synthetic data generation, and photo-realistic image synthesis (e.g., generating thousands of fictional human faces).


Unsupervised Learning Models

K-Means Clustering

K-Means Clustering is an unsupervised algorithm that finds natural groups (clusters) in unlabeled data. The user specifies the number of clusters (kkk), and the algorithm divides the data into that many groups.

Each cluster is defined by a centroid — the center point of that cluster. The algorithm works iteratively:

  1. Assign every data point to the nearest centroid.

  2. Recalculate the centroids as the mean of all points in each cluster.

  3. Repeat until cluster assignments stop changing.

For example, a retail company could use K-Means to group customers into clusters based on purchasing behavior (big spenders, occasional browsers, discount hunters) for targeted marketing.

K-Means is best used to discover natural groupings in unlabeled data — common in customer segmentation, data exploration, and pattern discovery.

Principal Component Analysis (PCA)

Principal Component Analysis (PCA) is an unsupervised technique for dimensionality reduction. It takes a dataset with many features and compresses it into fewer features while retaining as much important information as possible.

PCA finds the directions in the data where the most variation exists — called principal components — and projects the data onto those directions. The first principal component captures the largest variance, the second captures the next largest (orthogonal to the first), and so on.

Under the hood, PCA computes a covariance matrix to identify these directions of maximum variance. This is like taking the perfect selfie — finding the angle that captures the most information.

PCA is best used when dealing with high-dimensional data: reducing complexity before feeding into another model, visualizing data in 2D or 3D, or image compression. If a model is struggling with too many features, PCA is often the first tool to reach for.


Reinforcement Learning

Reinforcement Learning (RL) is about learning through trial and error. The core idea involves three components:

  • Agent: the learner making decisions.

  • Environment: everything the agent interacts with.

  • Reward: feedback signal — a score the agent receives after an action, indicating whether the action was good or bad.

The agent's goal is to maximize total reward over time. It does not need to be told the right answer — it discovers optimal behavior through exploration and feedback, similar to training a dog with treats.

Over thousands or millions of iterations, the agent learns a policy — a strategy for choosing actions in any given situation to maximize reward.

Reinforcement learning is best used for sequential decision-making problems: robotics, autonomous vehicles, game playing (e.g., AlphaGo), and any scenario where an agent must learn from its own actions and delayed rewards.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent