ML
ML
textbook:
Gene c Algorithms (GAs) are search heuris cs inspired by the principles of natural selec on and
gene cs. They are widely used for solving op miza on and search problems.
Key Components:
1. Representa on (Chromosome):
2. Popula on:
o A set of chromosomes (candidate solu ons). The size of the popula on affects the
search process and performance.
o Measures the quality of a solu on. It evaluates how well a chromosome solves the
problem. Higher fitness indicates be er performance.
4. Selec on:
Tournament Selec on: Randomly choose individuals and select the best
among them.
Rank Selec on: Individuals are ranked based on fitness, and selec on is
based on rank.
Two-Point Crossover: Two points are selected, and material between them
is exchanged.
6. Muta on:
o The algorithm stops when a maximum number of genera ons is reached, or when a
sa sfactory fitness level is achieved.
Example:
In a traveling salesman problem (TSP), each chromosome represents a possible route. The fitness
func on evaluates the total distance of the route. GAs evolve be er routes over genera ons by
selec ng the shortest paths and combining them.
Item-based collabora ve filtering recommends items similar to those a user has already rated
posi vely. Unlike user-based filtering, it focuses on the rela onship between items.
Key Steps:
o Compute the similarity between items using metrics like cosine similarity, Pearson
correla on, or Jaccard index. The similarity is based on user ra ngs for these items.
o For a target item, find similar items. Predict the user’s ra ng for these items based
on their ra ngs for similar items.
Example:
User Ra ngs:
o Movie A: 5 stars
o Movie B: 4 stars
o If users who liked Movie A also liked Movie C, then Movie C is recommended to the
user.
Key Metrics:
1. Support:
2. Confidence:
Confidence(A→B)=Support(A∪B)Support(A)\text{Confidence}(A \rightarrow B) =
\frac{\text{Support}(A \cup B)}{\text{Support}(A)}
3. Li :
o Li = 1: No associa on.
Example:
Support: 20% (Milk and Bread appear together in 20% of transac ons).
Confidence: 80% (80% of transac ons with Milk also contain Bread).
10. Discuss the user-based similarity algorithm using the Surprise library with a snippet of the
code.
Key Concepts:
o Similarity between users is computed using cosine similarity or Pearson correla on.
o If two users have similar tastes (ra ngs), they are considered neighbors.
# Load dataset
# Train-test split
algo.fit(trainset)
# Evaluate accuracy
accuracy.rmse(predic ons)
Matrix factoriza on decomposes a large matrix into smaller matrices, revealing hidden pa erns or
latent factors.
Process:
2. Reconstruc on:
Example:
User1 5 ? 2
User2 3 4 ?
Factoriza on:
Decomposed into user preferences and item a ributes. The missing ra ngs are predicted
based on these factors.
Associa on rules use metrics to measure the strength and reliability of rela onships between
itemsets.
Metrics:
1. Support:
o Frequency of the rule in the dataset. Higher support indicates a more common rule.
2. Confidence:
Confidence(A→B)=Support(A∪B)Support(A)\text{Confidence}(A \rightarrow B) =
\frac{\text{Support}(A \cup B)}{\text{Support}(A)}
3. Li :
o Indicates the degree to which the presence of AA increases the likelihood of BB.
Example:
Support: 5%
Confidence: 70%
I'll now provide detailed answers directly based on your provided document. Let's go through each
ques on thoroughly:
A perceptron is a simple ar ficial neuron in an ar ficial neural network (ANN). It is primarily used for
binary classifica on tasks.
Components:
Inputs (x1,x2,...,xnx_1, x_2, ..., x_n): These are the feature values fed into the perceptron.
Weights (w1,w2,...,wnw_1, w_2, ..., w_n): Each input is assigned a corresponding weight.
Bias (bb): This allows the model to make adjustments to the output independently of the
inputs.
Ac va on Func on: O en a step func on. If the weighted sum is above a threshold, it
outputs 1; otherwise, it outputs 0: f(x)={1if ∑wixi+b>00otherwisef(x) = \begin{cases} 1 &
\text{if } \sum w_i x_i + b > 0 \\ 0 & \text{otherwise} \end{cases}
Working Mechanism:
3. If the output matches the target, no changes are made. If not, the weights are adjusted using
a learning rule.
2. Construct the ANDNOT func on using McCulloch-Pi s neuron (binary data representa on).
The McCulloch-Pi s (M-P) neuron is a simple binary model with fixed weights and thresholds.
000
010
101
110
Configura on:
Inputs: AA and BB
Weights: w1=1w_1 = 1 for AA, w2=−1w_2 = -1 for BB
3. Construct the XOR func on using McCulloch-Pi s neuron (binary data representa on).
XOR is not linearly separable and cannot be implemented with a single-layer McCulloch-Pi s neuron.
It requires a mul -layer network.
A B A XOR B
000
011
101
110
Gene c Programming (GP) is an evolu onary technique where computer programs are evolved to
perform specific tasks.
Key Concepts:
Representa on:
Programs are o en represented as tree structures:
5. Discuss the stochas c gradient descent (SGD) version of the BACKPROPAGATION algorithm for
feedforward networks containing two layers of sigmoid units.
Steps:
3. Loss Calcula on: Compute error between predicted and actual outputs.
Gradient descent is an op miza on method used to minimize the error in a linear model.
Algorithm Steps:
4. Update weights: Adjust based on the learning rate: w=w−η×∂E∂ww = w - \eta \ mes
\frac{\par al E}{\par al w}
Gene c Algorithms (GAs) are inspired by the process of natural selec on.
Key Steps:
Item-based collabora ve filtering recommends items based on their similarity to items previously
liked.
Process:
1. Calculate the similarity between items (e.g., movies) based on user ra ngs.
Example:
If a user liked "The Godfather," they might be recommended "The Godfather Part II" due to high
similarity.
Example:
10. Discuss the user-based similarity algorithm using the Surprise library with a code snippet.
User-based Similarity: Measures the similarity between users based on their ra ngs.
Code:
Example:
Let me know if you'd like to dive deeper into any specific topic!