MACHINE LEARNING Unit-2
MACHINE LEARNING Unit-2
UNIT-II
1. Artificial Neural Network Introduction.
A. An Artificial Neural Network (ANN) is a computational model
inspired by the structure and function of biological neural networks
in animal brains. It is a type of machine learning (ML) paradigm that
enables computers to process data in a way that mimics human
cognition.
Key Components:
Advantages:
1
Types of ANNs:
Key Components
Representation
2
Types of Neural Networks
3
Gaming and Decision-Making: Neural networks can be
used to learn policies or strategies that optimize
cumulative rewards over time, making them suitable for
gaming and decision-making applications.
4
2. Inner Part: The inner part of a perception performs a computation
on the weighted sum of inputs and bias:
o Weighted sum: The sum of products between input values
and their corresponding weights.
o Activation function: A non-linear function that transforms
the weighted sum into an output value. Common activation
functions include sigmoid, ReLU, and step functions.
3. Activation Function: The activation function determines the
output of the perception. For example:
o Step function: Outputs 1 if the weighted sum is greater than
a threshold, and 0 otherwise.
o Sigmoid function: Maps the weighted sum to a value
between 0 and 1, often used for binary classification.
Key Points:
5
patterns and relationships. The backpropagation algorithm is a
supervised learning method used to train these networks by
adjusting the weights and biases to minimize the error between the
predicted output and the desired output.
Key Components
1. Input Layer: Receives the input data and passes it to the next
layer.
2. Hidden Layers: One or more layers that process the input data
and transform it into a more abstract representation.
3. Output Layer: Produces the final output based on the transformed
input.
4. Weights: Adjustable connections between neurons that determine
the strength of the signal passed between them.
5. Biases: Constant values added to the weighted sum of inputs to
each neuron.
Back-Propagation Algorithm
1. Forward Pass: The input data flows through the network, and the
output is calculated at each layer.
2. Error Calculation: The difference between the predicted output
and the desired output is calculated as the error.
3. Backward Pass: The error is propagated backwards through the
network, adjusting the weights and biases to minimize the error.
4. Weight Update: The weights are updated based on the gradient of
the error with respect to each weight, using an optimization
algorithm such as stochastic gradient descent.
Mathematical Derivation
Let’s denote the input to the network as x, the output as y, and the
weights and biases as W and b, respectively. The output of each layer is
calculated using the activation function σ:
where h_l is the output of layer l, W_l is the weight matrix, and b_l is the
bias vector.
The error between the predicted output y_pred and the desired
output y_true is calculated as:
6
E = (y_true - y_pred)^2
The gradients are then used to update the weights and biases using an
optimization algorithm.
Advantages
Challenges
Conclusion
7
the weights and biases of the network to minimize the error between
predicted and actual outputs.
Key Steps:
Notable Properties:
Advantages:
Challenges:
8
Real-World Applications:
Code Implementation:
Preprocessing:
9
2. Data normalization: Normalize the pixel values to a range of [0, 1]
to prevent features from being dominated by brightness or color.
3. Face detection: Use a pre-trained face detection model (e.g.,
Haar Cascade Classifier) to locate and crop the faces from each
image, ensuring that only the face region is used for feature
extraction.
Feature Extraction:
1. Test dataset: Split the dataset into a test set (e.g., 20 images per
person) and a training set (e.g., 80 images per person).
2. Evaluation metrics: Use metrics such as accuracy, precision,
recall, and F1-score to evaluate the model’s performance on the
test set.
Example Output:
10
import tensorflow as tf
def extract_features(image):
features = vggface.predict(image)
return features.flatten()
svm.fit(X_train, y_train)
print(f"Accuracy: {accuracy:.3f}")
11
8. Artificial Neural Network Topics.
A. Here are some advanced topics in artificial neural networks in
machine learning:
Hyperparameter tuning
Regularization techniques (e.g., dropout, L1/L2 regularization)
Activation functions (e.g., ReLU, sigmoid, tanh)
12
Optimization algorithms (e.g., stochastic gradient descent, Adam,
RMSProp)
Batch normalization
Attention mechanisms
Long short-term memory (LSTM) networks
Gated recurrent units (GRUs)
These advanced topics and concepts are essential for building and
optimizing complex neural networks, and are widely used in various
applications, including computer vision, natural language processing,
speech recognition, and recommender systems.
13
o Random search: Random sampling of hyperparameters.
o Bayesian optimization: Adaptive search using probabilistic
models.
5. Model Selection: Techniques for selecting the best hypothesis
include:
o Cross-validation: Evaluating models on multiple subsets of
the data.
o Model selection criteria: Choosing the model with the
lowest loss or highest accuracy.
6. Interpretability: Understanding the behavior and decisions made
by the learned hypothesis is essential for:
o Feature importance: Identifying relevant input features.
o Partial dependence plots: Visualizing the relationship
between input features and predictions.
o SHAP values: Assigning feature contributions to predictions.
Key Takeaways:
Key Takeaways
Key Concepts:
15
2. Sample: A subset of the population, selected using a sampling
method.
3. Sampling Frame: The list or database of all individuals or data
points in the population.
4. Sampling Method: The technique used to select the sample from
the population, such as random, systematic, stratified, or non-
probability sampling.
17
CI = [x̄ - ME, x̄ + ME] = [x̄ - (zα/2 * SE), x̄ + (zα/2 * SE)]
For example, if you want to construct a 95% confidence interval for the
population mean (μ) based on a sample mean (x̄ ) with a standard error
(SE), you would:
2. Type II Error (β): Failing to reject a false null hypothesis (H0). This
occurs when the researcher fails to detect a significant difference
or relationship between variables when, in fact, one exists.
18
Probability of Type II error (β) = 1 - Power (1 - probability of detecting a
true effect)
Key differences:
Interpretation:
Conclusion:
19
2. Evaluation Metrics: Choose relevant metrics to measure algorithm
performance: * Accuracy * Precision * Recall * F1-score * Mean Squared
Error (MSE) * Mean Absolute Error (MAE) * R-squared
20
…
21