ML UT 1 Merged
ML UT 1 Merged
2. What are the types of Machine Learning? Explain the types in brief with
examples?
Machine Learning is broadly categorized into three types:
1. Supervised Learning
2. Unsupervised Learning
3. Reinforcement Learning
1. Supervised Learning
In supervised learning, the model is trained using labeled data, meaning each
input has a corresponding correct output. The model learns the mapping
between inputs and outputs.
Examples:
• Regression: Predicting house prices based on features like size, location,
and number of rooms. (Algorithm: Linear Regression)
• Classification: Identifying whether an email is spam or not. (Algorithm:
Decision Tree, SVM, Neural Networks)
Use Cases:
• Fraud detection
• Disease prediction
• Sentiment analysis
2. Unsupervised Learning
In unsupervised learning, the model is trained on unlabeled data. The system
learns patterns and relationships in the data without explicit supervision.
Examples:
• Clustering: Grouping customers based on purchasing behavior.
(Algorithm: K-Means Clustering)
• Dimensionality Reduction: Compressing high-dimensional data while
retaining meaningful patterns. (Algorithm: PCA – Principal Component
Analysis)
Use Cases:
• Customer segmentation
• Market basket analysis
• Anomaly detection (e.g., fraud detection in banking)
3. Reinforcement Learning (RL)
In reinforcement learning, an agent learns by interacting with an environment
and receiving rewards or penalties based on its actions. The goal is to maximize
cumulative rewards over time.
Examples:
• Game Playing: AI mastering chess or Go. (Algorithm: Deep Q-Networks,
Policy Gradient)
• Robotics: Training robots to walk or perform tasks autonomously.
Use Cases:
• Self-driving cars
• Automated trading
• Personalized recommendations
2. Self-Driving Cars
• Example: Tesla’s Autonomous Driving AI
• How it works:
o The car (agent) interacts with the road (environment).
o It gets rewards for following lanes and penalties for crossing lines
or hitting obstacles.
o The AI continuously improves by learning the best driving actions.
• Algorithms Used: Deep Q-Learning, Reinforcement Learning with Neural
Networks
3. Robotics
• Example: Teaching a robotic arm to pick and place objects
• How it works:
o The robot learns by trying different movements.
o It gets rewards for successfully picking up and placing an object.
o Over time, it learns the most efficient way to perform the task.
• Algorithms Used: Q-Learning, Actor-Critic Models
4. Personalized Recommendations
• Example: Netflix and YouTube video recommendations
• How it works:
o The system observes user behavior (watch history, clicks).
o It gets rewards if a user watches a recommended video and
penalties if the user skips it.
o Over time, the AI learns to suggest better videos.
• Algorithms Used: Multi-Armed Bandit, Deep Reinforcement Learning
1. Healthcare
Application: Disease Diagnosis and Prediction
Example: Predicting Diabetes using ML
• Problem: Early diagnosis of diabetes is crucial, but traditional methods
require extensive tests.
• ML Solution: ML models like Logistic Regression, Decision Trees, and
Neural Networks analyze patient data (age, BMI, glucose levels) to
predict diabetes risk.
• Impact:
o Early detection enables timely treatment.
o Reduces the need for expensive and time-consuming tests.
Other Use Cases:
• Cancer detection (using Deep Learning on medical images).
• Personalized medicine recommendations.
• AI-powered drug discovery.
2. Finance
Application: Fraud Detection in Banking
Example: Detecting Credit Card Fraud
• Problem: Fraudsters use stolen credit cards for unauthorized
transactions.
• ML Solution: Algorithms like Random Forest and Neural Networks
analyze transaction patterns, location, and spending behavior to detect
anomalies.
• Impact:
o Identifies fraudulent transactions in real-time.
o Reduces financial losses for banks and customers.
Other Use Cases:
• Stock price prediction using ML models.
• Customer credit risk analysis for loan approval.
• Automated financial portfolio management.
5. Agriculture
Application: Crop Recommendation System
Example: AI-powered Crop Selection
• Problem: Farmers struggle to choose the right crops based on soil,
climate, and water availability.
• ML Solution: ML models like Decision Trees and Random Forest analyze
soil pH, temperature, and rainfall data to recommend the best crops.
• Impact:
o Increases agricultural yield.
o Reduces wastage of resources like water and fertilizers.
Other Use Cases:
• Pest and disease detection using image recognition.
• Smart irrigation systems using ML-based weather forecasting.
• Yield prediction based on climate and soil conditions.
11. Define
a) Accuracy
Definition:
Accuracy is the ratio of correctly predicted instances to the total instances in
the dataset.
Formula:
Accuracy= TP + TN / TP + TN + FP +FN
where:
• TP (True Positives): Correctly predicted positive cases
• TN (True Negatives): Correctly predicted negative cases
• FP (False Positives): Incorrectly predicted positive cases
• FN (False Negatives): Incorrectly predicted negative cases
Example:
If an email spam classifier correctly classifies 90 out of 100 emails, the accuracy
is 90%.
Limitation:
Accuracy is not reliable for imbalanced datasets (e.g., predicting rare diseases).
d) F1-Score
Definition:
F1-score is the harmonic mean of precision and recall, balancing both.
Formula:
F1 – Score = 2 * (Precision * Recall / Precison * Recall )
Example:
If precision = 80% and recall = 60%, the F1-score is:
F1=2×0.8×0.60.8+0.6=0.685
Use Case:
Useful when both false positives and false negatives matter (e.g., spam
detection).
e) Specificity (True Negative Rate - TNR)
Definition:
Specificity measures how well the model identifies actual negative cases.
Formula:
Specificity= TN / TN + FP
Example:
If there are 100 non-spam emails, and the model correctly classifies 90 of
them, specificity is 90%.
Use Case:
Important when false positives need to be minimized (e.g., avoiding wrongful
arrests in crime detection).
14. Write a short note on learning rate (α) in linear regression. How is a
trained model debugged with respect to the learning rate?
The learning rate (α\alphaα) in linear regression is a crucial hyperparameter in
gradient descent, controlling how much the model’s parameters are updated
at each iteration. It determines the step size towards minimizing the cost
function J(θ)J(\theta)J(θ).
• A small α\alphaα results in slow convergence, requiring more iterations
to reach the minimum.
• A large α\alphaα can cause overshooting or divergence, preventing the
model from finding the optimal solution.
• An optimal α\alphaα allows for fast and stable convergence to the
global minimum.
Debugging a Trained Model with Respect to Learning Rate
To debug a trained model based on α\alphaα, check:
1. Cost Function Plot
o If J(θ)J(\theta)J(θ) decreases smoothly → α\alphaα is good.
o If J(θ)J(\theta)J(θ) decreases too slowly → α\alphaα is too small.
o If J(θ)J(\theta)J(θ) oscillates or increases → α\alphaα is too large.
2. Convergence Behavior
o Slow learning: Increase α\alphaα slightly.
o Divergence: Decrease α\alphaα to stabilize training.
3. Use Adaptive Learning Rates
o Optimizers like Adam or RMSprop adjust α\alphaα dynamically for
efficient training.
MOD 5 –
Q. Define optimization. Explain the different types of optimizations?
Optimization is the process of finding the best solution from all feasible solutions for a given
problem. It involves maximizing or minimizing an objective function by systematically
choosing input values from a defined set and computing the corresponding output.
Mathematically, it is expressed as:
Minimize or Maximize: f(x)subject to constraints
Where:
• f(x) is the objective function,
• x is the variable or vector of variables.
Types of Optimizations:
1. Linear Optimization (Linear Programming)
• Objective function and constraints are linear.
• Example:
Maximize z=3x+2y
subject to x+y≤4,x,y≥0
2. Non-Linear Optimization
• Either the objective function or constraints (or both) are non-linear.
• Used in complex real-world problems like portfolio optimization, machine learning,
etc.
3. Unconstrained Optimization
• No constraints on variables.
• Example: Minimize f(x)=x2+2x+3
4. Constrained Optimization
• Includes equality or inequality constraints.
• Example: Minimize f(x) = x^2, subject to x≥1
5. Convex Optimization
• The objective function is convex and the feasible region is a convex set.
• Global minimum is guaranteed.
• Common in machine learning and control systems.
6. Combinatorial Optimization
• Deals with discrete variables and finding the best combination (e.g., scheduling,
traveling salesman problem).
• Often solved using heuristics or approximation algorithms.
7. Stochastic Optimization
• Involves randomness or uncertainty in data or model.
• Used in scenarios where exact information is not available (e.g., financial modelling,
reinforcement learning).
8. Multi-objective Optimization
• More than one objective function to optimize simultaneously.
• Trade-offs are considered to find Pareto optimal solutions.
Key Features:
• Fast convergence (quadratic) near the optimum.
• Suitable for smooth and differentiable functions.
• Efficient in low to moderate dimensions.
Limitations:
• Requires computation of second derivatives (Hessian), which can be expensive.
• Not suitable for non-differentiable or noisy functions.
• May fail if the Hessian is singular or poorly conditioned.
Q. Describe Downhill Simplex method. Why is it called the Derivative free method?
The Downhill Simplex Method, also known as the Nelder-Mead Method, is a derivative-free
optimization algorithm used to minimize a scalar-valued function of one or more variables. It
is particularly useful when the function is non-differentiable, noisy, or complex, where
derivatives are unavailable or unreliable.
• Why is it Called a Derivative-Free Method?
The Downhill Simplex Method is called a derivative-free method because it does not require
the calculation of gradients (first derivatives) or Hessians (second derivatives) of the
objective function. Instead, it relies solely on function evaluations to explore the search space
and determine the direction of improvement.
• Concept of a Simplex
A simplex is a geometric figure consisting of n+1n + 1n+1 points in an n-dimensional space.
• In 1D → simplex is a line segment (2 points)
• In 2D → simplex is a triangle (3 points)
• In 3D → simplex is a tetrahedron (4 points)
These points represent possible solutions, and the method iteratively moves and reshapes the
simplex to find the minimum.
Advantages
• No need for derivative information
• Simple to implement
• Effective for small to medium-sized problems
• Works well on non-smooth or noisy functions
Disadvantages
• Slow for high-dimensional problems
• May converge to a local minimum
• Performance depends on initial simplex