Skip to content

Instantly share code, notes, and snippets.

@NotHarshhaa
Created June 8, 2026 09:14
Show Gist options
  • Select an option

  • Save NotHarshhaa/ea0ac12336c182ec7366bc364a29701b to your computer and use it in GitHub Desktop.

Select an option

Save NotHarshhaa/ea0ac12336c182ec7366bc364a29701b to your computer and use it in GitHub Desktop.
ML Algorithms

"All machine learning algorithms" is a huge topic—entire university programs are built around it. The best way is to organize them into families and understand what problem each family solves.

1. What is Machine Learning?

Machine learning is the process of learning patterns from data instead of explicitly programming rules.

Traditional programming:

Rules + Data → Answers

Machine learning:

Data + Answers → Model

Then:

New Data + Model → Predictions

2. Main Categories of Machine Learning

Supervised Learning

You have inputs and correct outputs.

Example:

House Size Price
1000 sqft $100k
2000 sqft $200k

Goal: Predict future prices.


Unsupervised Learning

You only have data, no labels.

Example:

  • Customer purchase histories
  • No information about customer types

Goal: Discover hidden groups.


Reinforcement Learning

An agent learns by rewards and penalties.

Example:

  • Chess AI
  • Self-driving cars
  • Robotics

3. Supervised Learning Algorithms

A. Linear Regression

Predicts continuous values.

Example:

  • House prices
  • Stock trends
  • Sales forecasting

Formula:

genui{"math_block_widget_always_prefetch_v2":{"content":"y=mx+b"}}

Advantages:

  • Simple
  • Fast
  • Explainable

Disadvantages:

  • Only models linear relationships

B. Logistic Regression

Used for classification.

Example:

  • Spam vs Not Spam
  • Disease vs Healthy

Produces probabilities:

0.95 → Spam
0.05 → Not Spam

C. Decision Trees

Looks like a flowchart.

Example:

Income > 50k?
 ├─ Yes → Buy
 └─ No
      ├─ Age < 25?
      └─ Don't Buy

Advantages:

  • Easy to understand
  • Works with mixed data

Disadvantages:

  • Overfitting

D. Random Forest

Many decision trees combined.

Tree 1 → Yes
Tree 2 → No
Tree 3 → Yes

Final → Yes

Advantages:

  • Accurate
  • Robust

Disadvantages:

  • Harder to interpret

E. Support Vector Machine (SVM)

Finds the best boundary separating classes.

Used for:

  • Text classification
  • Image recognition
  • Bioinformatics

Advantages:

  • Effective on smaller datasets

Disadvantages:

  • Slow on large datasets

F. K-Nearest Neighbors (KNN)

Prediction based on nearby points.

Example:

5 nearest neighbors:
Dog Dog Dog Cat Dog

Prediction = Dog

Advantages:

  • Very simple

Disadvantages:

  • Slow on huge datasets

G. Naive Bayes

Based on probability and Bayes' theorem.

genui{"math_block_widget_always_prefetch_v2":{"content":"P(A\mid B)=\frac{P(B\mid A)P(A)}{P(B)}"}}

Used for:

  • Spam detection
  • Text classification
  • Sentiment analysis

Advantages:

  • Extremely fast

Disadvantages:

  • Strong assumptions

4. Ensemble Algorithms

These combine multiple models.

Bagging

Many models train independently.

Example:

  • Random Forest

Boosting

Models learn from previous mistakes.

Popular algorithms:

AdaBoost

Sequential improvement.

Gradient Boosting

Builds trees correcting previous errors.

XGBoost

One of the most famous ML algorithms.

Used heavily in:

  • Kaggle competitions
  • Finance
  • Business analytics

LightGBM

Faster version for large datasets.

CatBoost

Excellent for categorical features.


5. Unsupervised Learning Algorithms

A. K-Means Clustering

Groups similar points.

Example:

  • Customer segmentation

Output:

Cluster 1 → Students
Cluster 2 → Professionals
Cluster 3 → Retirees

B. Hierarchical Clustering

Builds a tree of clusters.

Useful when cluster relationships matter.


C. DBSCAN

Finds clusters of arbitrary shapes.

Good for:

  • GPS data
  • Spatial data

Can detect outliers automatically.


D. Gaussian Mixture Models (GMM)

Assumes data comes from multiple distributions.

Produces probabilities instead of hard assignments.


6. Dimensionality Reduction

When data has too many features.

PCA (Principal Component Analysis)

Finds the most important directions.

Used for:

  • Visualization
  • Noise reduction
  • Compression

t-SNE

Great for visualizing high-dimensional data.

Popular in research.


UMAP

Modern alternative to t-SNE.

Faster and often preserves structure better.


7. Deep Learning Algorithms

Deep learning uses neural networks.

Artificial Neural Networks (ANN)

Inspired by the brain.

Structure:

Input Layer
Hidden Layer
Output Layer

CNN (Convolutional Neural Networks)

Best for images.

Applications:

  • Face recognition
  • Medical imaging
  • Self-driving cars

Famous models:

  • LeNet
  • AlexNet
  • ResNet

RNN (Recurrent Neural Networks)

For sequences.

Applications:

  • Text
  • Speech
  • Time series

Problem:

  • Vanishing gradients

LSTM

Improved RNN.

Good at remembering long-term dependencies.

Applications:

  • Forecasting
  • NLP
  • Speech

GRU

Simplified LSTM.

Faster and often equally effective.


8. Transformer Models

The biggest breakthrough in modern AI.

Architecture based on attention.

Applications:

  • ChatGPT
  • Gemini
  • Claude
  • Translation
  • Coding assistants

Key concept:

Attention

The model learns what information matters most.

Famous transformer models:

  • GPT
  • BERT
  • T5
  • LLaMA

9. Reinforcement Learning Algorithms

Agent learns through rewards.

Q-Learning

Stores values for actions.

Used in:

  • Games
  • Robotics

Deep Q Networks (DQN)

Combines Q-learning and deep learning.

Famously used by DeepMind for Atari games.


PPO (Proximal Policy Optimization)

One of the most popular modern RL algorithms.

Used in:

  • Robotics
  • Large language model training

A3C / A2C

Parallel reinforcement learning methods.

Improve training speed.


10. Which Algorithms Matter Most in Industry?

If you're becoming an ML engineer, focus on these first:

Beginner

  1. Linear Regression
  2. Logistic Regression
  3. KNN
  4. Decision Trees
  5. Random Forest
  6. K-Means

Intermediate

  1. SVM
  2. PCA
  3. XGBoost
  4. LightGBM
  5. CatBoost

Advanced

  1. Neural Networks
  2. CNN
  3. LSTM
  4. Transformers
  5. PPO

Most Used in Real Jobs Today

  • XGBoost / LightGBM
  • Random Forest
  • Logistic Regression
  • Neural Networks
  • Transformers

A practical learning roadmap is:

Linear Regression → Logistic Regression → Decision Trees → Random Forest → XGBoost → Neural Networks → CNNs → Transformers

That progression covers the majority of concepts used in modern machine learning and AI systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment