Week11-AI ML DL
Week11-AI ML DL
ARTIFICIAL INTELLIGENCE,
MACHINE LEARNING AND
DEEP LEARNING
Preparatory Year Program -
Introduction to Digital Technologies (PYP 002)
Announcement
Quiz 03
Week 12 (17 Nov- 21 Nov) After midterm break
Chapter 04 from LAB Manual
Algorithms and Python Programming
Conditional Statements in Python
2
Announcement
Projects List available on the blackboard
Send the preferred project by Nov 21st, 2024
Week 14 – 15 for project presentations and code demo
Sample report provided on blackboard
Project Requirements
Problem Definition Define the problem addressed in the project
Data Analysis Plot chart describing the relation between different
features of the data
3
Objectives
Introduction to AI
Machine Learning
Deep Learning
Applications
Supervised ML
Classification
ML Pipeline
4
Artificial Intelligence
Sending emails
6
Applications
7
AI use cases
Product Automating
Fraud Detection Diagnosis Identify threats
Recommendations assembly
Defects
Treatment Facial recognition
identification
8
Relationship between AI, ML and DL
10
Machine Learning (Example)
11
Machine Learning (Example)
Spam Detection (Identify incoming email is spam or not)
Machine Learning
Learn from data
Show spam and non-spam emails to algorithm (Past Data)
Algorithm learns important features from the data (Training)
Once trained, ML algorithm can predict new emails (Future Data)
12
Machine Learning (Example)
Training
Feeding data to a ML algorithm
Algorithm learns important features from the data
Features of a spam email? (Count the number of times specific word
appears like Lottery, win, etc., )
Features to recognize images? (Eye size, distance between eyes,
Nose size)
Think of features as inputs
Creates a trained model
Testing / Prediction
Once trained, test the model on unseen data (New Data)
Is the new email spam or not spam
13
Deep Learning
14
Machine learning algorithms
Machine Learning
Supervised
Unsupervised Reinforcement (Learn
(Data with output while running)
(Data without output labels)
labels)
Regression
15
Machine learning algorithms
Supervised Learning:
Supervised learning is used for labeled datasets
Training data is provided
Training data is labeled.
Each data input contains its desired output as well.
Usually last column in dataset
Once training is complete. The label of unseen (new) data is
predicted
Performance is measured based on how accurately the new data
is predicted
16
Machine learning algorithms
Classification
The computer learns to classify things into categories based
on given examples
The system learns a model/function called classifier that
maps input to a discrete output
Models: ANN, SVM, CNN
Applications: Images classification, speech recognition,
Email spam detection, etc.
Classification:
Predict a class label for an input
17
Machine learning algorithms
18
Machine Learning Pipeline
Model Model
ML Algorithm
Deployment Evaluation
19
Scikit-learn
20
Machine Learning Pipeline
Data Collection:
The data can be in various formats such as text,
tabular, image etc.
Important to have good quality of data
Use pandas to load the dataset or sklearn module
Model Model
ML Algorithm
Deployment Evaluation
21
Example
Preprocessing:
Data is cleaned and transformed into something that is usable by
machine learning algorithms.
Data normalization, dealing with outliers, transforming categorical
features, histogram equalization and data augmentation, among
other tasks.
Example: Label encoder transforms categorical data to numeric.
Model Model
ML Algorithm
Deployment Evaluation
23
Preprocessing
Display data info
Data head
24
Preprocessing
Class Distribution (plt histogram plot)
25
Preprocessing
Convert categorical data to numerical data
from sklearn.preprocessing import LabelEncoder
label_encoder = LabelEncoder()
data['class']=label_encoder.fit_transform(data['class'])
Before Encoding
After Encoding
26
Machine Learning Pipeline
Feature Extraction:
Also known as feature engineering,
Extract useful features from the preprocessed data
Various methods such as Discrete Wavelet Transform,
Fourier Transform, Morphological opening etc.
Model Model
ML Algorithm
Deployment Evaluation
27
Machine Learning Pipeline
Data Distribution:
Separate inputs and outputs from the dataset
Output is usually the last column in the dataset for supervised
classification.
Model Model
ML Algorithm
Deployment Evaluation
28
Data Distribution in Supervised Learning
Data
29
Machine Learning Pipeline
Data Distribution:
Next, a split is performed on the data that distributes it randomly
into two sets called training and testing.
Usually 70% Training, 30% Testing
train_test_split function in the model_selection
module of sklearn library
Model Model
ML Algorithm
Deployment Evaluation
30
Data Distribution in Supervised Learning
x_train y_train
x_test y_test
31
Machine Learning Pipeline
Model Model
ML Algorithm
Deployment Evaluation
32
ML Algorithm
33
ML Algorithm
34
Kernel
35
Kernel
36
Machine Learning Pipeline
Model Evaluation:
The performance of the system is evaluated on the test data based
on various metrics.
Accuracy in a classification model determines the fraction of total
predictions that were correctly classified.
Sensitivity, Specificity, Confusion Matrix etc.
Different performance metrics can be imported from sklearn module
from sklearn.metrics import accuracy_score
y_pred = model.predict(x_test)
accuracy=accuracy_score(y_test, y_pred)
Data Feature Data
Preprocessing
Collection Extraction Distribution
Model Model
ML Algorithm
Deployment Evaluation
37
Confusion Matrix
38
Confusion Matrix
39
Accuracy Measurements
Yes 36 5 [ 36
6
5
15 ]
No 6 15
Accuracy = =
Sensitivity = =
Specificity =
40
Accuracy Measurements
Yes 41 0 [ 41
0
0
21 ]
No 0 21
41
Machine Learning Pipeline
Model Deployment:
Once the model provides satisfactory results on the
training and testing data, it is deployed in the
production environment to make predictions on unseen
data.
Model Model
ML Algorithm
Deployment Evaluation
42
Exercise
43