Learning AI
Table of Contents
1. Machine Learning
a subset of artificial intelligence(AI) focused on algorithms that can “learn” the patterns of training data and, subsequently, make accurate inferences about new data. This pattern recognition ability enables machine learning models to make decisions or predictions without explicit, hard-coded instructions.
\[MachineLearning \subset ArtificialIntelligence\]
1.1. Types of ML
- Supervised Learning
- trains model to predict the “correct” output for a given input
- it applies to tasks that require some degree of accuracy relative to some external ground truth, such as classification or regression
- Unsupervised Learning
- trains a model to discern intrinsic patterns, dependencies and correlations in data
- unlike in supervised learning, unsupervised learning tasks don’t involve any external ground truth agains which its outputs should be compared
- Reinforcement Learning
- trains a model to evaluate its environment and take action that will garner the greatest
- RL scenarios don’t entail the existence of a singular ground truth, but they do entail the existence of good and bad (or neutral) actions
- Deep Learning
- subset of ML driven by multilayered neural networks whose design is inspired by the structure of the human brain
- interconnected layers of “neurons” that each perform mathematical operation
- neural networks and 1.5 not the same though associated with one another
1.2. Supervised Learning
- trains models for tasks requiring accuracy, such as 1.2.0.2 or 1.2.0.1
- to be measured for optimized for accuracy, a model’s outputs must be compared to a ground truth: the ideal or “correct” output for any given input
- uses loss function that measures the divergence(“loss”) between the model’s output and the ground truth across a batch of training inputs
- objective of supervised learning is defined mathematically as minimizing the output of a loss function
- once the loss has been computed, various optimization algorithms are used to identify parameter adjustments that will reduce loss
> since this process requires a human in the loop to provide ground truth in the form of data annotations it’s called supervised learning
- Regression
- model predicts continuous values, such as price, duration, temperature or size.
like in linear regression, its just predicting values for a new input based on previous (input,value) pairs
\[\hat{y} = b_0 + b_1x\]
example:
House features ──────→ House price $250,000 Age, income ─────────→ Insurance cost $1,200/year Temperature, humidity → Electricity consumption 43.7 kWh - Classification
- a predictive modeling process by which ML models use classification algorithms to predict the correct label for input data
- model that sorts data points into predefined groups called classes
- instead of predicting a numerical value it predicts the category (class)
Regression ↓ “What number?”
Classification ↓ “Which category?”
- classification models often don’t say “This is a cat.”, instead it rates Cat: 0.55
- then we choose the class with the highest probablity
- Ensemble Learning
- technique that aggregates two or more learners(e.g. regression models, neural networks) in order to produce better predictions
1.2.1. Self-supervised Learning
- when a model learns from unlabeled data by creating its own learning task from the data
the data provides its own “labels”
Typical example:
Original data
↓
Create a prediction task
↓
Model makes prediction
↓
Compare with original data
↓
Update model
Supervised vs Self-supervised
Supervised
Human provides labels
↓
Input → Label
Self-supervised
Data creates the labels
↓
Input → Automatically generated target
- Transfer Learning  @deep_learning
- model originally trained on one task is reused as the starting point for a model on a second, related task
- instead of training a model from scratch which requires a lot of data and compute 1.2.1.1 leverages knowledge gained from a previous task to improve generalization and performance on the new problem
1.2.2. Semi-supervised Learning
- uses a small amount of labeled data together with a large amount of unlabeled data.
- out of 100,000 images say only 1,000 has been labeled
1.2.3. Summary
Summarizing all:
| Learning type | Labeled data | Unlabeled data |
| --------------- | --------------------------- | ------------- |
| Supervised | Lots | May not use |
| Semi-supervised | Small amount | Lots |
| Self-supervised | Doesn’t require human labels | Lots |
| Unsupervised | None | Lots |
1.3. Unsupervised Learning
- when a model learns patterns or structure from data that has no labels > we give model the data but don’t tell it what the answers are
- it “discovers” patterns, patterns which aren’t necessarily visible to human observers
Types of functions in unsupervised learning:
1.3.1. Clustering: predict a category
- partiion ulabeled data points into “clusters” or groupings, based on their proximity to one another
- used for tasks like market segmentation or fraud detection
- algorithms include: K-means clustering, Gaussian mixture models, density-based methods such as DBSCAN
1.3.2. Association: find relationships between items
- discern correlations, such as particular action and certain conditions
- shows association, it asks what things tend to occur together?
- doesn’t predict a specific numerical value or necessarily assign a class
- example: e-commerce businesses use unsupervised association models to power recommendation engines
1.3.3. Dimensionality reduction
- reduces complexity of data points by representing them with a smaller number of features‐i.e. fewer dimensions
- while preserving their meaningful characteristcs
- often used for preprocessing data, as well as for tasks such as data compression or visualization
- algorithms include: autoencoders, principal component analysis(PCA)
Terms:
- Lift
- Is the relationship stronger than what we’d expect by chance?
- A lift greater than 1 generally indicates a positive association.
1.4. Reinforcement Learning
type of 1 where an agent learns by interacting with an environment and receiving rewards or penalties
Try something -> see what happens -> get reward/penalty -> learn what actions are better
Basic Components of RL;
- Agent: the thing that is learning
- Environment: the world the agent interacts with
- Action: what the agent can do
- Reward: feedback telling the agent whether the action was good or bad
- the best action isn’t always the one that gives an immediate reward
- they are trained holistically through trial and error
+---+---+---+---+ | R | | | | +---+---+---+---+ | | X | | | +---+---+---+---+ | | | | G | +---+---+---+---+ R-> robot X-> obstacle G-> goal
Terms:
- Policy
- a policy is essentially the agent’s strategy;i.e. “Given my current situation, what should I do?”
- Reward signal
- designates the RL problem’s goal
- each RL agent’s actions either receives a reward from the environment or not
- agent’s only objective is to maximize its cumulative rewards from the environment
- Value function
eg: for self driving vechiles, the reward signal can be reduced travel time, decreased collisons, remaining on the road etc
1.4.1. Difference from 1.2
- In Supervised learning, we give model the correct answer
- In Reinforcement learning, we don’t tell it the correct action directly
1.5. Deep Learning
- uses neural networks with multiple layers to learn complex patterns from data
- DL models are commonly trained through 1.2 on labeled data
- neural networks are inspired by the workings of the human brain’s neural circuits, whose functioning is driven by the complex transmission of electro-chemical signals across distributed networks of nerve cells
- in DL, the analogous “signals” are the weighted outputs of many nested mathematical operations, each performed by an artificial “neuron”(or node), that collectively comprise the neural network
1.5.1. Traditional ML vs DL
Considering an image classification.
With traditional ML, we might manually decide what features matter:
Image ↓ Human chooses features ↓ Edges Color Shape Texture ↓ ML algorithm ↓ Cat / Dog
With Deep Learning
Image ↓ Neural network ↓ Learns useful features itself ↓ Cat / Dog
1.5.2. But how does it learn?
- A neural network contains parameters, usually called weights
Initially:
\[ weights = randimish\ values \]
It makes a prediction:
\[Image -> Neural Network -> "Dog"\]
But let’s suppose the correct answer is
Cat
The network calculates how wrong it was using a loss function.
Prediction
↓
"Dog"
↓
Compare with actual answer
↓
Loss
↓
Adjust weights
This happens again and again:
Data ↓ Prediction ↓ Loss ↓ Backpropagation ↓ Update weights ↓ Prediction improves
Types of 1.5 models:
1.5.3. Convolutional Neural Networks (CNNs)
- learns small visual patterns and combines them into larger, meaningful patterns
- they are primarily(but exclusively) associated with computer vision tasks such as object detection, image recognition, image classification, 1.6
use three-dimensional data for image classification and object recognition tasks
Example flow:
Pixels ↓ Edges ↓ Shapes ↓ Eyes / ears / wheels ↓ Faces / cars / animals ↓ Object
- How do CNNs work?
they’re distinguished from other neural networks by their superior performance with image, speech or audio signal inputs
Main types of layers:
- 1.5.3.2
- Pooling Layer
- Fully-connected(FC) Layer
- With each layer, the CNN increases in its complexity, identifying greater portions of the image.
- Earlier layers focus on simple features, such as: colors, edges
- As the image data progresses through the layers of the CNN, it starts to recognize larger elements or shapes of the object eventually identifying the whole intended object
- Convolutional Layer
- majority of computation occurs here
It requires few components
- input data
- filter a.k.a kernel or feature detector
- feature map
1.6. Image Segementation
- technique that partitions a digital image into discrete groups of pizels-image segments-to inform object detection and related tasks
- it’s not the same as 1.7 or 1.8
- processes visual data at the pixel level, using various techniques to annotate individual pixels as belonging to a specific class or instance
1.7. Image Classification
- it applies class labels to an entire image
- for eg: a simple image clasification model might be trained to categorize vehicle iamges as “cars” or “truck”
- conventional image classification systems are limited in sophistication, as they do not process individual image features separately
1.8. Object Detection
- combines 1.7 with object localization, generating rectangular regions; “bounding boxes”, in which objects are located
1.9. Neural Networks
a function that takes inputs, performs mathematical operations, and produces an output.
Example:
Suppose we have inputs:
$$x_1$$ = hours studied $$x_2$$ = attendance
A neuron takes these inputs:
x₁ ──→
\
→ [ neuron ] → output
/
x₂ ──→
Each input has a weight.
x₁ ──→ × w₁ ──┐
│
x₂ ──→ × w₂ ──┼──→ sum → activation → output
│
bias ──┘
Mathematically: \[z = w_1 x_1 + w_2 x_2 + b\] then: \[ output = f(z) \] where \(f\) is an activation function.
- weights
- weights represent how strongly an input influences the neuron
- bias
- bias is an additional parameter that lets the neuron shift its output; maybe like an offset
- activation function
\[\sigma\] at the output layer transforms the linear combination to fit the decision of the function. using this architecture, the input features X are transformed into an output Y, serving as a predictive learning model
- Gradient Descent
- minimize cost function means getting to the lowest error value possible or increasing the accuracy of the model
- minimizing any function means finding the deepest valley in the function
1.9.1. Neural network training
requires rigorous training to perform well on testing; to train a network, a single neuron computes: \[z = \sum_{n}^{i=1} w_i x_i + b\]
\[a = \sigma(z)\]
where:
\(x_i\) = input feature, \(w_i\) = weight, b = bias \(z\) = weighted sum(linear transformation) \(\sigma\) = activation function (non linear transformation) \(a\) = input feature,
NEURAL NETWORK
Input Hidden layers Output
┌─────────────┐
x₁ ────────────────→ │ ● ──→ ● │
x₂ ────────────────→ │ ● ──→ ● ──→ ● ──→ prediction
x₃ ────────────────→ │ ● ──→ ● │
└─────────────┘
│
↓
Weights + Biases
│
↓
Activation functions
Typical flow:
data ↓ forward pass ↓ prediction ↓ loss ↓ backpropagation ↓ gradient descent ↓ update weights ↓ repeat