ML Algorithms

What Are Machine Learning Algorithms?

Machine learning algorithms are methods that learn patterns from data and use those patterns to make predictions or decisions.

Algorithm Examples

Linear Regression — Predict house prices

Logistic Regression — Detect spam emails

Decision Trees — Approve or reject loans

Random Forests — Detect fraud

K-Nearest Neighbors — Recommend products

Support Vector Machines — Classify images

Linear Regression

Linear Regression is used for regression problems where the goal is to predict a numerical value.

Examples
  • House prices
  • Temperatures
  • Sales forecasts
  • Revenue predictions
Advantages & Limitations

Advantages — Simple, fast, interpretable

Limitations — Assumes linear relationships, sensitive to outliers

Logistic Regression

Logistic Regression is used for classification problems. Even though it has "regression" in the name, it predicts categories using probabilities.

Examples
  • Spam or Not Spam
  • Fraud or Not Fraud
  • Disease or No Disease
  • Approved or Denied
Advantages & Limitations

Advantages — Fast, easy to interpret, great for binary classification

Limitations — Struggles with complex decision boundaries

Decision Trees

Decision Trees make predictions by asking a sequence of questions. Each answer leads to another branch until the model reaches a decision.

Example

Is income greater than $50,000?

Yes → Check credit score

No → Reject loan

Decision Trees are easy to understand because they resemble flowcharts.

Random Forests

Random Forests combine many decision trees together. Instead of relying on one tree, the model uses many trees and combines their predictions.

Example
  • Tree 1 → Approve
  • Tree 2 → Approve
  • Tree 3 → Reject

Final Prediction — Approve (majority vote)

Random Forests reduce overfitting and usually outperform a single decision tree.

K-Nearest Neighbors

K-Nearest Neighbors (KNN) makes predictions based on the closest examples in the dataset.

Example

New customer compared to nearest neighbors

  • Neighbor 1 → Premium
  • Neighbor 2 → Premium
  • Neighbor 3 → Basic

Prediction — Premium

Support Vector Machines

Support Vector Machines (SVMs) classify data by finding the best boundary between groups.

Goal

Find the best separating boundary between classes.

Example — Separate spam emails from non-spam emails.

Strength — Effective in high-dimensional datasets with complex boundaries.

Classification vs Regression

RegressionClassification
Predicts numbersPredicts categories
House priceSpam or Not Spam
TemperatureFraud or Not Fraud
Sales forecastCat or Dog

Algorithm Comparison

AlgorithmBest ForMain Idea
Linear RegressionPredicting numbersFinds a best-fit line
Logistic RegressionBinary classificationPredicts probabilities
Decision TreesExplainable decisionsUses question-based splits
Random ForestsHigher accuracyCombines many trees
KNNSimilarity-based predictionUses nearest examples
SVMSeparating classesFinds best boundary

Choosing the Right Algorithm

Decision Guide

Predict a number → Linear Regression

Predict yes/no → Logistic Regression

Explainability matters → Decision Trees

Accuracy matters → Random Forests

Similar examples should have similar labels → KNN

Separating classes clearly is important → SVM

Practice Prompt

Choose the best algorithm for each problem:

Problems to Solve
  • Predicting house prices
  • Detecting spam emails
  • Explaining loan approval decisions
  • Classifying customers based on nearby similar customers
  • Separating two difficult classes with a boundary

Need Help?

Ask the AI if you need help understanding any machine learning algorithm.