0% found this document useful (0 votes)
13 views89 pages

Machine Learning Concepts and Challenges

Uploaded by

vaihan1528
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views89 pages

Machine Learning Concepts and Challenges

Uploaded by

vaihan1528
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CSEN3261 Machine Learning

Course Outcome 1
To formulate the different machine learning problems

2
Contents
1. Use of Machine Learning,
2. Types of machine learning systems,
3. Machine learning challenges,
4. Testing and validating,
5. Working with real data,
6. Obtaining the data,
7. Data preparation,
8. Visualizing the data,

3
9. Training and fine tuning the model
Reference
1. Chapters 1, 2
Aurelion Geron, Hands-on Machine Learning with Scikit-
Learn, Keras, and Tensor Flow: Concepts, Tools and Techniques
to build Intelligent Systems, 2/e, O’Reilly Media, 2019.
2. Week 1 - Lecture 1 - Introduction to Machine Learning
3. Week 1 Lecture 2 - Supervised Learning
4. Week 1 Lecture 3 - Unsupervised Learning
5. Week 1 Lecture 4 - Reinforcement Learning
[Link]
iy295pg6_SY5qznc77

4
Traditional vs Machine Learning

5
Models and Parameters

How were
these
parameters
determined?

6
Models and Parameters

How were
these
parameters
7 determined?
Models and Parameters
 Linear
 Quadratic
 Polynomial
 Machine Learning Models – Bayesian, SVM, Decision Tree
(Units 2, 3, 4)
 Deep Learning – Artificial Neural Networks (Unit 5)

8
When Do We Use Machine Learning?
 Human expertise does not exist (navigating on Mars)
 Humans can’t explain their expertise (speech recognition)
 Models must be customized (personalized medicine)
 Models are based on huge amounts of data (genomics)
Not useful
 Compute First/Second etc class based on CGPA
 Direct computation, Mathematical formula is available.

9
Machine Learning Pipeline

10
MLOps Pipeline

11
12
13
Supervised – Classification

14
Supervised – Classification

15
Supervised – Regression

16
Supervised (Inductive) Classification
Given (x1, y1), (x2, y2), ..., (xn, yn)

Classification : Learn a function model f(x) to


predict y given x – y is categorical

Regression : Learn a function Model f(x) to predict


y given x – y is real-valued

17
Question
Learning algorithms are to be developed for two problems:

1. From a large inventory of identical items, it is required


to predict that how many of them will be sold in the
next 3 months.

2. A Software should check each customer account and


identify if it is hacked.

How to treat them, as classification problem or


regression problem?

18
Amazon app – classification
Product Category Recommendation
 Inputs:
 User browsing history (e.g., item IDs, time spent)
 Past purchase categories
 Device/app usage time (e.g., mobile vs desktop)
 Output Categories:
 Electronics, Books, Fashion, Home Appliances, Beauty, Grocery, etc.

19
Amazon app – classification
Review Sentiment Detection
 Inputs:
 Review text (tokenized words or embeddings)
 Review length
 Presence of strong sentiment words (e.g., “amazing”, “terrible”)
 Output Categories:
 Positive, Neutral, Negative

20
Amazon app – classification

Review Sentiment
Exclamation Predicted
Length Score (from
Count Sentiment
(words) text)
120 0.92 3 Positive
45 0.03 0 Negative
80 0.50 1 Neutral

21
Amazon app – classification
Fake/Genuine Review Detection
 Inputs:
 Reviewer purchase history (e.g., never bought the item?)
 Time of posting vs purchase date
 Number of reviews posted per day by user
 Output Categories:
 Genuine, Fake

22
Amazon app – Regression
Product Rating Prediction
 Inputs:
 User’s historical rating patterns
 Product features (price, brand, popularity)
 Sentiment score of review text
 Output:
 Predicted rating (e.g., 4.2 on a 1–5 scale)

23
Amazon app – Regression
Estimated Delivery Time
 Inputs:
 User’s location and pin code
 Warehouse inventory and dispatch time
 Courier network traffic/load
 Output:
 Predicted delivery duration (e.g., 2.8 days)

24
Amazon app – Regression

Zip Code Carrier Predicted


Warehouse
Distance Rating (0– Delivery
Delay (hrs)
(km) 1) Time
15 4 0.90 1.8 days
300 12 0.55 4.3 days
120 6 0.70 2.7 days

25
Amazon

26
Amazon App: Features from other Apps
Recent Map
Search
App Usage Visit Type
Keyword Predicted
Count (Gym=1,
Score (Home Category
(Flipkart) Mall=2,
Decor)
None=0)
Fitness
12 0.85 1
Products
3 0.10 2 Fashion
Home
0 0.60 0
Essentials
27
Amazon App: Features from other Apps

Predicted
Screen Daily GPay Battery Purchase
Time (min) Usage (₹) Level (%) Time
(hrs)
80 250 60 3.5
20 50 90 12.0
120 600 40 1.8

28
Question
Select any App you frequently choose.
1. Identify three classification tasks
2. Identify three regression tasks
Identify at least three inputs and the output for each
task
Identify the features this App may borrow from other
Apps on the Mobile.

29
Labelling – Classification
Manual Labeling (Human Annotation)
 Description: Trained annotators or domain experts label
data point-by-point based on guidelines.
 Use Case: High accuracy required; domain-specific
knowledge needed.
 Examples:
 Scale AI and Appen offer large-scale human labeling services.
 Google used human raters to label search relevance and
sentiment in early BERT development

30
Labelling – Classification
Crowdsourcing
 Description: Tasks are distributed to non-expert users
online to obtain multiple labels per instance.
 Use Case: Scalable and fast, especially for simple labeling
tasks.
 Examples:
 Amazon Mechanical Turk (MTurk) is widely used by
Microsoft, Stanford, and OpenAI for collecting labeled
datasets like sentiment or object annotations.
 Zooniverse (used by NASA) for image classification tasks
(e.g., galaxy labeling).

31
Labelling – Regression
Manual Measurement or Expert Annotation
 Description: Domain experts or instruments measure the
target variable directly.
 Use Case: Where precision is critical and sensors or human
expertise are available.
 Examples:
 Medical Imaging: Radiologists manually measure tumor size
(used by companies like Siemens Healthineers).
 Real Estate: Human appraisers estimate property prices for
training price prediction models (e.g., Zillow's Zestimate).

32
Labelling – Regression
Sensor or System Logs (Automated Labels)
 Description: Devices or systems automatically generate
ground-truth values (e.g., temperature, speed).
 Use Case: Continuous, large-scale, low-cost data labeling.
 Examples:
 Tesla: Uses car sensors to label acceleration, energy usage, or
road slope for predictive modeling.
 Google Nest: Uses thermostat data (e.g., actual room
temperature) for predicting energy usage.

33
Unsupervised – Clustering
• Given attributes x1, x2, ..., xn (without labels)
• Output hidden structure behind the x’s

34
Unsupervised Learning

 Little or no idea about the result.


 No feedback based on prediction results.
35
Amazon App

Use Case Benefits:


•Target Cluster 1 with premium deals
•Nudge Cluster 3 with onboarding offers
36
•Offer Cluster 2 time-limited discounts
Unsupervised Learning

37 Independent component analysis – separate a combined signal into its original sources
Unsupervised Learning

38
Facebook App
Avg Daily Posts Per Video Watch Cluster
Scrolls Week Time (min/day) (Interpretation)
Cluster 1
300 1 10
(Casual User)
Cluster 2
1200 5 60 (Heavy
Consumer)
Cluster 3
250 25 30 (Content
Creator)
39
Facebook: Features from other Apps
Instagram Travel App E-Commerce
Cluster
Usage Location Searches (past
Interpretation
(min/day) Changes/Week 7 days)
Cluster 1 (Visual
120 1 2
Casual User)
Cluster 2
45 12 15 (Mobile Active
Shopper)
Cluster 3 (Heavy
200 0 0 Social Media
User)
40
Supervised vs Unsupervised

41
Reinforcement Learning

42
Youtube
(YouTube uses deep reinforcement learning for video
recommendations and autoplay optimization)
Watch Time Skip Rate Like/Dislike Action Taken by
(min) (%) Ratio RL Agent
Recommended
15 10 0.90
similar video
Switched to short-
3 70 0.30
form video
Autoplay next
50 5 1.00 video from same
43 channel
Youtube : Features from other Apps
(YouTube uses deep reinforcement learning for video
recommendations and autoplay optimization)

TikTok Usage Spotify Genre Preference Browser Search on


(min/day) (e.g Music = 1, None = 0) “TED Talks” = 1/0

45 1 1
90 0 0
15 1 0

44
Youtube : Features from other Apps

45
Reinforcement Learning
In Reinforcement Learning, data is not pre-given, but
dynamically generated, and
performance is judged by how well the agent acts, not
by accuracy on a test set.
Optional Tools:
 Simulators (e.g., OpenAI Gym, MuJoCo, Unity ML-
Agents) generate states and rewards.
 Logging tools (e.g., TensorBoard) monitor learning curves,
episode returns.

46
What Is Machine Learning?
 Machine Learning is the science (and art) of programming
computers so they can learn from data.
 [Machine Learning is the] field of study that gives computers
the ability to learn without being explicitly programmed.

—Arthur Samuel, 1959


 A computer program is said to learn from experience E with
respect to some task T and some performance measure P, if
its performance on T, as measured by P, improves with
experience E.
—Tom Mitchell, 1997

47
Challenges
1. Data Quality and Quantity
❖ Insufficient Data: Many ML algorithms require large datasets to
perform effectively. Collecting sufficient data can be a major
hurdle.
❖ Data Quality: Poor quality data, with issues such as missing
values, noise, or outliers, can negatively impact model
performance.
2. Data Labeling
❖ Labeling Effort: Supervised learning algorithms require labeled
data, which can be time-consuming and expensive to obtain.
❖ Human Error: Manual labeling can introduce errors due to
human mistakes or inconsistencies.
48
Challenges
3. Overfitting and Underfitting
Overfitting: A model that is too complex may perform well on
training data but poorly on new, unseen data.
Underfitting: A model that is too simple may fail to capture the
underlying patterns in the data.
4. Computational Resources
High Computational Cost: Training large models, especially deep
neural networks, can be computationally expensive and time-
consuming.
Hardware Limitations: Limited access to high-performance
computing resources can hinder model training and deployment.

49
Challenges
5. Security and Privacy
Data Privacy: Ensuring that the data used for training and predictions
complies with privacy regulations.
Adversarial Attacks: ML models can be vulnerable to adversarial
attacks, where small changes to the input data can lead to incorrect
predictions.
6. Ethical Considerations
Ethical Use: Ensuring that ML applications are used ethically and do
not cause harm.
Transparency: Maintaining transparency in how ML models are
developed and used.

50
Challenges
7. Scalability
Scalability of Algorithms: Some ML algorithms may not scale
well with increasing data sizes or feature dimensions.
Infrastructure: Building and maintaining the infrastructure to
support scalable ML applications can be challenging.
8. Reproducibility
Experiment Reproducibility: Ensuring that ML experiments are
reproducible, including maintaining detailed records of data,
code, and experimental settings.

51
Training, Validation and Testing

52
K-fold cross validation

53
Benchmark Datasets
 UCI Machine Learning Repository [Link]
 Kaggle Datasets [Link]
 OpenML
[Link]
active
 Hugging Face Datasets [Link]
 Papers with Code – Datasets
[Link]
 Awesome Public Datasets (GitHub)
[Link]
 Microsoft Research Open Data [Link]
us/research/tools/?
54
Types of Attributes
In machine learning, attributes (or features) represent the
properties or characteristics of data. They are broadly classified
into four types based on their nature and measurement scale
1. Nominal Attributes
 Definition: Categories with no inherent order.
 Examples:
 Color: {Red, Green, Blue}
 Gender: {Male, Female, Other}
 Use: Encoded using one-hot encoding or label encoding.

55
One-hot encoding

ID Gender ID Male Female Other


1 Male 1 1 0 0
2 Female 2 0 1 0
3 Other 3 0 0 1
4 Female 4 0 1 0
5 Male 5 1 0 0

56
Types of Attributes
2. Ordinal Attributes
 Definition: Categories with a meaningful order but
unknown interval between them.
 Examples:
 Education level: {High School < Bachelor < Master < PhD}
 Rating: {Poor, Average, Good, Excellent}
 Use: Often encoded using integer mapping or target
encoding

57
Integer mapping

Education Mapped ID Education Encoded


Level Value 1 Bachelor 2
High School 1 2 Master 3
Bachelor 2 3 High School 1
Master 3 4 PhD 4
PhD 4 5 Bachelor 2

58
Types of Attributes
3. Interval Attributes
 Definition: Numerical values with equal intervals, but no
true zero point.
 Examples:
 Temperature in Celsius or Fahrenheit
 30°C is hotter than 20°C, but 0°C ≠ no temperature.

 Use: Algorithms can apply arithmetic operations, but ratios


are meaningless.

59
Types of Attributes
4. Ratio Attributes
 Definition: Numerical values with a meaningful zero,
allowing full arithmetic operations.
 Examples:
 Age: 20 years is twice as old as 10 years.
 Income: ₹0 means no income.
 Use: Supports all operations, including meaningful ratios.

60
Types of Attributes
Operations
Attribute Type Nature Example
Allowed
Nominal Categorical Gender =, ≠
Ordinal Categorical Rating =, ≠, <, >
Temperature
Interval Numerical +, −
(°C)
Ratio Numerical Income, Age +, −, ×, ÷

61
Types of Attributes
ID Gender Education Temp (°C) Age (yrs) Income (₹)
1 Male Bachelor 22 25 40,000
2 Female Master 30 30 60,000
3 Other High School 18 20 25,000
4 Female PhD 25 45 1,00,000
5 Male Bachelor 28 35 75,000

62
Data preparation
1. Data Cleaning
Goal: Handle missing, duplicate, or inconsistent data.
Example: A column Age has missing values → Fill with mean
or median.
df['Age'].fillna(df['Age'].mean(),
inplace=True)

2. Data Integration
Goal: Combine data from multiple sources.
Example: Merge patient data from hospital database and lab test
results using Patient_ID
[Link](df1, df2, on='Patient_ID')
63
Data preparation
3. Data Transformation
Goal: Convert data into suitable formats.
Example: Convert categorical Gender to one-hot encoding
pd.get_dummies(df['Gender'],
prefix='Gender’)

4. Feature Scaling
Goal: Normalize or standardize numeric values.
Example: Normalize Income to [0,1] using Min-Max scaling
from [Link] import
MinMaxScaler
scaler = MinMaxScaler()
df['Income_scaled'] =
scaler.fit_transform(df[['Income']])
64
Data preparation
5. Feature Selection/Extraction
Goal: Choose the most relevant features or reduce dimensionality.
Example:
Remove highly correlated features or apply PCA
from [Link] import PCA
pca = PCA(n_components=2)
reduced = pca.fit_transform(df[['feat1',
'feat2', 'feat3']])

6. Data Splitting
Goal: Divide into training and testing sets.
from sklearn.model_selection import
train_test_split
X_train, X_test, y_train, y_test =
train_test_split(X, y, test_size=0.2)
65
Example
Patient_ID,Gender,Education,Age,Income,Cholesterol,Smoker
101,Male,Bachelor,25,40000,180,Yes
102,Female,Master,30,60000,,No
103,Other,High School,,25000,190,Yes
104,Female,PhD,45,100000,200,No
105,Male,Bachelor,35,75000,210,Yes
106,Female,,28,,185,No

66
Example
Feature Data Prep Step Issue/Use
Missing value → fill with
Age Data Cleaning
median/mean
Income Feature Scaling Normalize between [0,1]
One-Hot Nominal → convert to
Gender
Encoding binary columns
Ordinal → map High
Education Integer Mapping
School < Bachelor etc.
Normal Numeric
Cholesterol Use as-is or scale
Feature
67 Smoker Binary Categorical Encode as 0/1
Options to Handle Missing Ordinal Data
 Option 1: Impute using mode (most frequent
category)
This is common when the missing value is likely to be similar to
the majority.
 Option 2: Impute using domain knowledge
If you know that most patients in that age group (e.g., 28 years)
have a Bachelor's degree:

68
Exploratory Data Analysis (EDA)
Visualization Utility
Understand feature
Histogram
distribution
Box Plot Detect outliers and spread
Analyze frequency of
Bar Chart / Pie
categorical variables
Examine relationships
Scatter Plot
between variables
Visualize pairwise relations
Pair Plot
& distributions
69 Heatmap (correlation) Identify multicollinearity
Pairwise plots

1. Petal Width vs Sepal Length


Setosa forms a distinct tight cluster. Versicolor and Virginica
overlap considerably. Weak class separability; sepal length does
not strongly distinguish Versicolor and Virginica.
70
Pairwise plots

2. Petal Width vs Sepal Width


High overlap among all three species. Sepal width is the least
informative feature for classification.

71
Pairwise plots

3. Petal Width vs Petal Length


Clear class separability: Setosa forms a completely separate tight
cluster. Versicolor and Virginica form elongated but distinguishable
clusters. This pair provides the best feature combination for class
separation.
72
Pairwise plots

4. Petal Width vs Petal Width


Petal width alone is highly discriminative, especially for Setosa.
while Versicolor and Virginica show wider but distinct ranges.

73
74
Box plots
Boxplots display spread, median, and outliers across species.
Spread/Interquartile Range (IQR)
Definition: Distance between the 75th percentile (Q3) and
25th percentile (Q1).
Represents: Middle 50% of the data.
Formula:
IQR=Q3−Q1
Larger IQR → greater spread (more variability).

75
 Setosa has generally smaller sepal lengths, but overlap with
Versicolor exists.
 Versicolor and Virginica have highly overlapping ranges.
76
 Significant overlap across all three species.
77
 Setosa completely separated from other species.
 Versicolor and Virginica show partial overlap.
78
 Setosa completely separated;
79  Minimal overlap between Versicolor and Virginica.
Violin Plot
Violin plots show both distribution shape and central tendency.
1. Distribution Shape
The shape of the violin (wider or narrower parts) shows how
data points are distributed (their density) across the range.
2. Central Tendency
The typical (central) value of the data — often shown by a
white dot (median), thick black bar (interquartile range), and
thin line (95% confidence interval) in Seaborn’s violin plot.

80
Shape & Spread: All species show similar central tendency with
wide overlapping distributions. Versicolor and Virginica distributions
are almost symmetric; Setosa slightly skewed towards lower values.
81 Class Separability: Poor — large overlap among species.
Shape & Spread:
High variability; Setosa shows a wider spread compared to other species.
Several outliers apparent as long tails.
Class Separability: Very poor — high overlap; not useful for
82
classification.
Shape & Spread: Setosa forms a tight, narrow distribution (low
variance).Versicolor and Virginica have wider, partially overlapping
distributions.
Class Separability: Good — Setosa is perfectly distinct; Versicolor &
83 Virginica partly separable.
Shape & Spread: Setosa has a tight, narrow distribution (very low
spread).Versicolor and Virginica show broader but distinct distributions.
Class Separability: Excellent — clear separation among species, best single
feature for classification
84
Correlation Heatmap

85
Correlation Heatmap
Compared With Correlation Comment
Strong positive correlation →
Sepal length ~0.82 larger sepal length tends to
accompany larger petal width.
Moderate negative correlation →
Sepal width ~-0.37 wider sepals slightly correspond to
narrower petals.
Very strong positive correlation →
Petal length ~0.96 petal width & length are
almost linearly related.
Petal width 1.00 (self) Perfect correlation (diagonal).
•Petal width has the strongest positive correlation with petal length → they
carry similar information (might be redundant for some ML models).
86
•Negative or weak correlation with sepal width suggests independent information.
Model Training & Evaluation (Unit 2)
Visualization Utility
Confusion Matrix Show classification performance
ROC / Precision-Recall
Evaluate binary classifier
Curve
Feature Importance Identify top influencing features
Learning Curve Detect overfitting/underfitting

87
Dimensionality Reduction/Clustering (Unit 3)

Visualization Utility
PCA / t-SNE Plot Visualize high-dimensional data
Dendrogram Explore hierarchical clusters
3D Scatter Plot Explore multivariable clusters

88
Thank You All Very Much

89

You might also like