Artificial Intelligence
Any technique that makes a computer behave in a way that seems intelligent — pattern recognition, decision making, language understanding, recommendations.
- Machine Learning is a branch of artificial intelligence that enables algorithms to uncover hidden patterns within datasets, allowing them to make predictions on new, similar data without explicit programming for each task.
- ML models can be deterministic, probabilistic, or combine aspects of both
Types of learning
1) Supervised Learning
It is an approach where a model is trained on labeled data, meaning each input has a corresponding correct output, so the model learns to map inputs to outputs.
Algorithms
1) Classification:
Predicting a category label, such as spam detection in emails.
- Logistic Regression
- Decision Tree
- Random Forest
- Support Vector Machine (SVM)
- K-Nearest Neighbors (KNN)
- Naive Bayes
- Gradient Boosting (XGBoost, LightGBM, CatBoost)
- Neural Networks
Multi-label classification
Each item can belong to MULTIPLE labels simultaneously
Multi-class classification
Each item belongs to exactly ONE class
2) Regression:
Predicting a continuous value, such as house prices.
- Linear Regression
- Ridge / Lasso Regression
- Decision Tree Regression
- Random Forest Regression
- SVR (Support Vector Regression)
Examples
Identifying the zip code from handwritten digits on an envelope
Determining whether a tumor is benign based on a medical image
Detecting fraudulent activity in credit card transactions
2) Un-supervised Learning
It is an approach where a model is trained on unlabeled data and tries to discover patterns, structures, or relationships within the data.
Algorithms
1) Clustering:
Grouping similar data points together
- K-Means
- DBSCAN
- Hierarchical Clustering
- Gaussian Mixture Models Ex. Customer segmentation
2) Association:
Finding relationships or rules between variables in large datasets.
- Apriori Algorithm
- Eclat Algorithm
- AIS Algorithm
- FP-Growth (Frequent Pattern Growth)
- Ex. People who buy bread also buy butter
3) Dimensionality Reduction:
Reducing the number of features (variables) while keeping important information.
- PCA (Principal Component Analysis)
- t-SNE
- UMAP
- Autoencoders Ex. Compressing image data
4) Anomaly Detection
Process of identifying data points that deviate significantly from the normal pattern in a dataset.
- Isolation Forest
- One-Class SVM
- Local Outlier Factor (LOF)
3) Semi-Supervised Learning
It is an approach that uses a combination of a small amount of labeled data and a large amount of unlabeled data to improve learning accuracy.
- Label Propagation
- Self-Training
- Co-Training
4) Reinforcement Learning
It involves training a model to make sequences of decisions by rewarding desired behaviors and punishing undesired ones
Game Playing: Training an AI to play games like chess or Go.
Robotics: Training robots to perform tasks, such as walking or grasping objects.
Self-driving Cars: Training autonomous vehicles to navigate roads safely.
Common Algorithms
Q-Learning
Deep Q-Network (DQN)
Policy Gradient Methods
Actor-Critic Methods
5) Self Supervised Learning
The model learns useful patterns from unlabeled data by creating learning signals/tasks from the data itself.
Original text:
"The cat sat on the mat."
↓
Training task:
"The cat sat on the ____"
↓
Model predicts:
"mat"
6) Incremental Learning
It updates an existing model with newly arriving data without completely retraining it from scratch
7) Transfer Learning
It takes knowledge learned by a model on one task and reuse/adapt it for a different but related task.
Model Fit
It describes how well a machine-learning model has learned patterns from its training data and, importantly, how well it performs on new/unseen data.
- Underfitting (Didn't learn enough)
- Model is too simple or insufficiently trained to capture the important patterns in the data.
- It is possible to increase both bias and variance, but this typically leads to a model that performs poorly due to both underfitting and overfitting
- Overfitting (Memorized too much) Model learns the training data too specifically, including noise/details, and fails to generalize well to new data.
How can we prevent overfitting?
- Increase training data size
- Early stopping the training of the model
- Data Augmentation
- Adjust Hyperparameters
- Ensembling
- Cross-validation
- Pruning
- Regularization
- Balanced / Good Fit Model learns the underlying patterns and generalizes well to unseen data.
Evaluation metrics
They are crucial in machine learning and artificial intelligence for assessing the performance of models and algorithms. The choice of metrics depends on the type of task (e.g., classification, regression, clustering)
- Classification Metrics:
Accuracy — How many predictions were correct overall
Precision - Of everything the model predicted as positive, how many were actually positive?
Recall/Sensitivity - Of all the actual positives, how many did the model successfully find?
F1 Score - A single score that balances precision and recall.
ROC-AUC (Receiver Operating Characteristic - Area Under Curve)
It measures the model's ability to distinguish between classes. AUC is the area under the ROC curve, which plots true positive rate vs. false positive rate.
Range: 0 to 1 (1 indicates perfect classification).
Regression Metrics
Bias
The tendency of a model to consistently make errors in a particular direction
High Bias: Leads to underfitting, where the model is too simple to capture the underlying patterns in the data.
Low Bias: Indicates a model that is more flexible and capable of fitting the training data well, but it can still suffer from high variance.
How to measure bias?
A benchmark dataset is a standardized dataset used to evaluate and compare the performance of various algorithms or models within a specific domain. They related to bias are specifically designed to help evaluate and understand fairness and bias in machine learning models.
Ex. StereoSet (Designed to evaluate and address biases in natural language processing models)
CrowS-Pairs (focusing on the perpetuation of stereotypes)
How to reduce bias?
- Use a more complex model
- Increase the number of features
Sampling Bias
It occurs when the training data does not properly represent the population the model will encounter.Measurement bias
It occurs when the way data is measured, collected, or recorded systematically produces inaccurate information.
Day images → high-quality measurements ✅
Night images → poor-quality measurements ❌
- Observer bias It occurs when a person's expectations or subjective judgment influence how data is observed, interpreted, or labeled.
Person walking quickly
↓
Human annotator
↓
"SUSPICIOUS"
- Confirmation bias It is the tendency to seek, interpret, or emphasize information that supports an existing belief while overlooking contradictory evidence.
Variance
- It defines how much a model's predictions change when it is trained on different training datasets.
- Overfitting is associated with HIGH variance.
- An overfitted model learns the training dataset too specifically.
- So if you slightly change the training data, the model it learns can change substantially.
How to reduce variance?
- Feature Selection
- Split into training and testing data sets multiple times
Data Split
Training Set
It is the data used to actually train the model and learn its weights/parameters.
Testing Set
It is the unseen data used after training/tuning to measure the final model's performance and generalization.
Validation Set
It is the separate data used during development to tune hyperparameters and choose the best model/configuration.
Machine Learning Packages
scikit-learn
It is a very popular tool which contains a number of state-of-the-art machine learning algorithms, and the most prominent Python library for machine learning
numpy
It is a fundamental packages for scientific computing in Python. It contains functionality for multidimensional arrays, high-level mathematical functions such as linear algebra operations and the Fourier transform, and pseudo random number generators
matplotlib
It is a primary scientific plotting library in Python. It provides functions for making publication-quality visualizations such as line charts, histograms, scatter plots etc
pandas
pip install numpy scipy matplotlib ipython scikit-learn pandas
First code
# Step 1: Import the necessary libraries
import numpy as np
import pandas as pd
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
# Step 2: Load the Iris dataset
iris = datasets.load_iris()
X = iris.data
y = iris.target
# Step 3: Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
# Step 4: Standardize the features
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
# Step 5: Train a K-Nearest Neighbors classifier
knn = KNeighborsClassifier(n_neighbors=3)
knn.fit(X_train, y_train)
# Step 6: Make predictions on the testing set
y_pred = knn.predict(X_test)
# Step 7: Evaluate the classifier
print("Accuracy:", accuracy_score(y_test, y_pred))
print("Classification Report:\n", classification_report(y_test, y_pred))
print("Confusion Matrix:\n", confusion_matrix(y_test, y_pred))
Ensemble Model
It is a machine learning technique that combines the predictions of multiple individual models to improve overall performance. The main idea is that by aggregating multiple models, you can achieve better accuracy, robustness, and generalization compared to using any single model alone.
Types of Ensemble Methods
Bagging (Bootstrap Aggregating)
Multiple models (e.g., decision trees) are trained on different bootstrapped subsets of the data. The predictions are aggregated (e.g., by voting for classification or averaging for regression).
It reduces variance and helps in preventing overfitting.
Ex.
Random Forest
Bagged Decision Trees
Boosting
Models are trained sequentially, where each new model tries to correct the errors of the previous ones. The predictions are combined, often with a weighted average.
It reduces bias and improves the accuracy of predictions by focusing on the errors of previous models.
Ex.
AdaBoost, Gradient Boosting, XGBoost, LightGBM, CatBoost.
Stacking
Different models (base learners) are trained on the same data, and their predictions are used as inputs to a meta-learner, which makes the final prediction.
Combines multiple models to leverage their individual strengths and improve performance.
Ex
Using logistic regression as a meta-learner with decision trees and SVMs as base learners.
Voting
For classification, majority voting is used to choose the class with the most votes. For regression, the average of predictions is taken.
Types: Hard voting (majority class) and soft voting (average predicted probabilities).
Random Forest
It is a versatile and powerful machine learning algorithm that's used for both classification and regression tasks.
The algorithm creates multiple decision trees by sampling the training data with replacement (bootstrap sampling). Each tree is trained on a slightly different dataset, which helps in reducing overfitting.
For classification tasks, the final output is determined by majority voting among the individual trees. For regression tasks, the output is the average of the predictions from all trees.
Classification
Decision Trees
Random Forest
Naive Bayes
K-Nearest Neighbors (KNN)
Logistic Regression
Neural Networks
AdaBoost
Gradient Boosting Machines (GBM)
Support Vector Machines (SVM)
Quadratic Discriminant Analysis (QDA)
Regression
Linear Regression
Decision Tree Regression
Random Forest Regression
Bayesian Regression
K-Nearest Neighbors (KNN) Regression
Gradient Boosting Machines (GBM) for Regression
Clustering
K-Medoids
K-Means Clustering
Hierarchical Clustering
Gaussian Mixture Models (GMM)
Agglomerative Clustering
BIRCH (Balanced Iterative Reducing and Clustering using Hierarchies)
DBSCAN (Density-Based Spatial Clustering of Applications with Noise)
OPTICS (Ordering Points To Identify the Clustering Structure)
HDBSCAN (Hierarchical DBSCAN)
Hyperparameters
Settings that you choose before/during training that control how a machine-learning model learns.
Learning rate
Controls how much the model adjusts its weights at each learning step.
Batch Size
Number of training examples processed before the model updates its weights.
Epoch
- One complete pass through the entire training dataset.
- Increasing this increases model accuracy
Regularization
It is a technique used to reduce overfitting by preventing a model from learning the training data too specifically.
Cross Validation (K-fold cross-validation)
It is a technique where the training data is divided into multiple parts, and the model is repeatedly trained on some parts and validated on another part.
Suppose you have 1,000 patient records and choose 5-fold cross-validation.
Fold 1 → 200 patients
Fold 2 → 200 patients
Fold 3 → 200 patients
Fold 4 → 200 patients
Fold 5 → 200 patients
Round 1:
Train → Fold 2,3,4,5
Validate → Fold 1
Round 2:
Train → Fold 1,3,4,5
Validate → Fold 2
Round 3:
Train → Fold 1,2,4,5
Validate → Fold 3
...and so on
Pruning
- It is a technique that cuts unnecessary parts of the model
- It removes branches that provide little useful predictive value
Before pruning:
Tree
/ | \
/ | \
/ | \
many unnecessary branches
After pruning:
Tree
/ \
/ \
simpler simpler
Why 255?
In standard grayscale and RGB images, pixel values are often represented as 8-bit integers, which means each pixel value ranges from 0 to 255. This range is derived from the 8-bit depth, where:
0 represents the minimum value (e.g., black in grayscale or full absence of color in RGB).
255 represents the maximum value (e.g., white in grayscale or full intensity of a color in RGB)
Correlation Matrix
It shows how strongly different numerical variables/features are related to each other.
Stay Connected!
If you enjoyed this post, don’t forget to follow me on social media for more updates and insights:
Twitter: madhavganesan
Instagram: madhavganesan
LinkedIn: madhavganesan









Top comments (0)