SlideShare una empresa de Scribd logo
1 de 23
Machine learning
system design
Prioritizing what to
work on: Spam
classification example
Machine Learning
Andrew Ng
Building a spam classifier
From: cheapsales@buystufffromme.com
To: ang@cs.stanford.edu
Subject: Buy now!
Deal of the week! Buy now!
Rolex w4tchs - $100
Med1cine (any kind) - $50
Also low cost M0rgages
available.
From: Alfred Ng
To: ang@cs.stanford.edu
Subject: Christmas dates?
Hey Andrew,
Was talking to Mom about plans
for Xmas. When do you get off
work. Meet Dec 22?
Alf
Andrew Ng
Building a spam classifier
Supervised learning. features of email. spam (1) or not spam (0).
Features : Choose 100 words indicative of spam/not spam.
From: cheapsales@buystufffromme.com
To: ang@cs.stanford.edu
Subject: Buy now!
Deal of the week! Buy now!
Note: In practice, take most frequently occurring words ( 10,000 to 50,000)
in training set, rather than manually pick 100 words.
Andrew Ng
Building a spam classifier
How to spend your time to make it have low error?
- Collect lots of data
- E.g. “honeypot” project.
- Develop sophisticated features based on email routing
information (from email header).
- Develop sophisticated features for message body, e.g. should
“discount” and “discounts” be treated as the same word? How
about “deal” and “Dealer”? Features about punctuation?
- Develop sophisticated algorithm to detect misspellings (e.g.
m0rtgage, med1cine, w4tches.)
Machine learning
system design
Error analysis
Machine Learning
Andrew Ng
Recommended approach
- Start with a simple algorithm that you can implement quickly.
Implement it and test it on your cross-validation data.
- Plot learning curves to decide if more data, more features, etc.
are likely to help.
- Error analysis: Manually examine the examples (in cross
validation set) that your algorithm made errors on. See if you
spot any systematic trend in what type of examples it is
making errors on.
Andrew Ng
Error Analysis
500 examples in cross validation set
Algorithm misclassifies 100 emails.
Manually examine the 100 errors, and categorize them based on:
(i) What type of email it is
(ii) What cues (features) you think would have helped the
algorithm classify them correctly.
Pharma:
Replica/fake:
Steal passwords:
Other:
Deliberate misspellings:
(m0rgage, med1cine, etc.)
Unusual email routing:
Unusual (spamming) punctuation:
Andrew Ng
The importance of numerical evaluation
Should discount/discounts/discounted/discounting be treated as the
same word?
Can use “stemming” software (E.g. “Porter stemmer”)
universe/university.
Error analysis may not be helpful for deciding if this is likely to improve
performance. Only solution is to try it and see if it works.
Need numerical evaluation (e.g., cross validation error) of algorithm’s
performance with and without stemming.
Without stemming: With stemming:
Distinguish upper vs. lower case (Mom/mom):
Machine learning
system design
Error metrics for
skewed classes
Machine Learning
Andrew Ng
Cancer classification example
Train logistic regression model . ( if cancer,
otherwise)
Find that you got 1% error on test set.
(99% correct diagnoses)
Only 0.50% of patients have cancer.
function y = predictCancer(x)
y = 0; %ignore x!
return
Andrew Ng
Precision/Recall
in presence of rare class that we want to detect
Precision
(Of all patients where we predicted , what
fraction actually has cancer?)
Recall
(Of all patients that actually have cancer, what fraction
did we correctly detect as having cancer?)
Machine learning
system design
Trading off precision
and recall
Machine Learning
Andrew Ng
Trading off precision and recall
Logistic regression:
Predict 1 if
Predict 0 if
Suppose we want to predict (cancer)
only if very confident.
Suppose we want to avoid missing too many
cases of cancer (avoid false negatives).
More generally: Predict 1 if threshold.
1
0.5
0.5 1
Recall
Precision
precision =
true positives
no. of predicted positive
recall =
true positives
no. of actual positive
Andrew Ng
Precision(P) Recall (R) Average F1 Score
Algorithm 1 0.5 0.4 0.45 0.444
Algorithm 2 0.7 0.1 0.4 0.175
Algorithm 3 0.02 1.0 0.51 0.0392
F1 Score (F score)
How to compare precision/recall numbers?
Average:
F1 Score:
Machine learning
system design
Data for machine
learning
Machine Learning
Designing a high accuracy learning system
[Banko and Brill, 2001]
E.g. Classify between confusable words.
{to, two, too}, {then, than}
For breakfast I ate _____ eggs.
Algorithms
- Perceptron (Logistic regression)
- Winnow
- Memory-based
- Naïve Bayes
“It’s not who has the best algorithm that wins.
It’s who has the most data.”
Training set size (millions)
Accuracy
Useful test: Given the input , can a human expert
confidently predict ?
Large data rationale
Assume feature has sufficient information to
predict accurately.
Example: For breakfast I ate _____ eggs.
Counterexample: Predict housing price from only size
(feet2) and no other features.
Large data rationale
Use a learning algorithm with many parameters (e.g. logistic
regression/linear regression with many features; neural network
with many hidden units).
Use a very large training set (unlikely to overfit)
Fashion MNIST:
It contains 70,000 items of
clothing in 10 different
categories. Each item of
clothing is in a 28x28
greyscale image.
import tensorflow as tf
mnist = tf.keras.datasets.fashion_mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()
model = tf.keras.models.Sequential([tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation=tf.nn.relu),
tf.keras.layers.Dense(10, activation=tf.nn.softmax)])
model.compile(optimizer = tf.keras.optimizers.Adam(),
loss = 'sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(training_images, training_labels, epochs=5)
model.evaluate(test_images, test_labels)
classifications = model.predict(test_images)
print(classifications[0])
training_images = training_images / 255.0
test_images = test_images / 255.0
!wget --no-check-certificate 
https://storage.googleapis.com/laurencemoroney-blog.appspot.com/rps.zip 
-O /tmp/rps.zip
!wget --no-check-certificate 
https://storage.googleapis.com/laurencemoroney-blog.appspot.com/rps-test-set.zip 
-O /tmp/rps-test-set.zip
import os
import zipfile
local_zip = '/tmp/rps.zip'
zip_ref = zipfile.ZipFile(local_zip, 'r')
zip_ref.extractall('/tmp/')
zip_ref.close()
local_zip = '/tmp/rps-test-set.zip'
zip_ref = zipfile.ZipFile(local_zip, 'r')
zip_ref.extractall('/tmp/')
zip_ref.close()
Lecture11.pptx

Más contenido relacionado

Similar a Lecture11.pptx

Teaching AI about human knowledge
Teaching AI about human knowledgeTeaching AI about human knowledge
Teaching AI about human knowledgeInes Montani
 
Making Machine Learning Work in Practice - StampedeCon 2014
Making Machine Learning Work in Practice - StampedeCon 2014Making Machine Learning Work in Practice - StampedeCon 2014
Making Machine Learning Work in Practice - StampedeCon 2014StampedeCon
 
Machine learning and_nlp
Machine learning and_nlpMachine learning and_nlp
Machine learning and_nlpankit_ppt
 
Machine learning with ADA Boost
Machine learning with ADA BoostMachine learning with ADA Boost
Machine learning with ADA BoostAman Patel
 
11 ml system design
11 ml system design11 ml system design
11 ml system designTanmayVijay1
 
Machine Learning - Lecture2.pptx
Machine Learning - Lecture2.pptxMachine Learning - Lecture2.pptx
Machine Learning - Lecture2.pptxNsitTech
 
Machine Learning - Lecture1.pptx.pdf
Machine Learning - Lecture1.pptx.pdfMachine Learning - Lecture1.pptx.pdf
Machine Learning - Lecture1.pptx.pdfNsitTech
 
A Nontechnical Introduction to Machine Learning
A Nontechnical Introduction to Machine LearningA Nontechnical Introduction to Machine Learning
A Nontechnical Introduction to Machine LearningSam Elshamy
 
AI_06_Machine Learning.pptx
AI_06_Machine Learning.pptxAI_06_Machine Learning.pptx
AI_06_Machine Learning.pptxYousef Aburawi
 
1. Demystifying ML.pdf
1. Demystifying ML.pdf1. Demystifying ML.pdf
1. Demystifying ML.pdfJyoti Yadav
 
Introduction to machine learning and deep learning
Introduction to machine learning and deep learningIntroduction to machine learning and deep learning
Introduction to machine learning and deep learningShishir Choudhary
 
notes as .ppt
notes as .pptnotes as .ppt
notes as .pptbutest
 
Week 2 Sentiment Analysis Using Machine Learning
Week 2 Sentiment Analysis Using Machine Learning Week 2 Sentiment Analysis Using Machine Learning
Week 2 Sentiment Analysis Using Machine Learning SARCCOM
 
This is a heavily data-oriented
This is a heavily data-orientedThis is a heavily data-oriented
This is a heavily data-orientedbutest
 
This is a heavily data-oriented
This is a heavily data-orientedThis is a heavily data-oriented
This is a heavily data-orientedbutest
 
Python Machine Learning January 2018 - Ho Chi Minh City
Python Machine Learning January 2018 - Ho Chi Minh CityPython Machine Learning January 2018 - Ho Chi Minh City
Python Machine Learning January 2018 - Ho Chi Minh CityAndrew Schwabe
 
.NET Fest 2017. Игорь Кочетов. Классификация результатов тестирования произво...
.NET Fest 2017. Игорь Кочетов. Классификация результатов тестирования произво....NET Fest 2017. Игорь Кочетов. Классификация результатов тестирования произво...
.NET Fest 2017. Игорь Кочетов. Классификация результатов тестирования произво...NETFest
 

Similar a Lecture11.pptx (20)

Teaching AI about human knowledge
Teaching AI about human knowledgeTeaching AI about human knowledge
Teaching AI about human knowledge
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Making Machine Learning Work in Practice - StampedeCon 2014
Making Machine Learning Work in Practice - StampedeCon 2014Making Machine Learning Work in Practice - StampedeCon 2014
Making Machine Learning Work in Practice - StampedeCon 2014
 
Machine learning and_nlp
Machine learning and_nlpMachine learning and_nlp
Machine learning and_nlp
 
Machine learning with ADA Boost
Machine learning with ADA BoostMachine learning with ADA Boost
Machine learning with ADA Boost
 
Lec1 intoduction.pptx
Lec1 intoduction.pptxLec1 intoduction.pptx
Lec1 intoduction.pptx
 
11 ml system design
11 ml system design11 ml system design
11 ml system design
 
Machine Learning - Lecture2.pptx
Machine Learning - Lecture2.pptxMachine Learning - Lecture2.pptx
Machine Learning - Lecture2.pptx
 
Sentiment Analysis in Machine Learning
Sentiment Analysis in  Machine LearningSentiment Analysis in  Machine Learning
Sentiment Analysis in Machine Learning
 
Machine Learning - Lecture1.pptx.pdf
Machine Learning - Lecture1.pptx.pdfMachine Learning - Lecture1.pptx.pdf
Machine Learning - Lecture1.pptx.pdf
 
A Nontechnical Introduction to Machine Learning
A Nontechnical Introduction to Machine LearningA Nontechnical Introduction to Machine Learning
A Nontechnical Introduction to Machine Learning
 
AI_06_Machine Learning.pptx
AI_06_Machine Learning.pptxAI_06_Machine Learning.pptx
AI_06_Machine Learning.pptx
 
1. Demystifying ML.pdf
1. Demystifying ML.pdf1. Demystifying ML.pdf
1. Demystifying ML.pdf
 
Introduction to machine learning and deep learning
Introduction to machine learning and deep learningIntroduction to machine learning and deep learning
Introduction to machine learning and deep learning
 
notes as .ppt
notes as .pptnotes as .ppt
notes as .ppt
 
Week 2 Sentiment Analysis Using Machine Learning
Week 2 Sentiment Analysis Using Machine Learning Week 2 Sentiment Analysis Using Machine Learning
Week 2 Sentiment Analysis Using Machine Learning
 
This is a heavily data-oriented
This is a heavily data-orientedThis is a heavily data-oriented
This is a heavily data-oriented
 
This is a heavily data-oriented
This is a heavily data-orientedThis is a heavily data-oriented
This is a heavily data-oriented
 
Python Machine Learning January 2018 - Ho Chi Minh City
Python Machine Learning January 2018 - Ho Chi Minh CityPython Machine Learning January 2018 - Ho Chi Minh City
Python Machine Learning January 2018 - Ho Chi Minh City
 
.NET Fest 2017. Игорь Кочетов. Классификация результатов тестирования произво...
.NET Fest 2017. Игорь Кочетов. Классификация результатов тестирования произво....NET Fest 2017. Игорь Кочетов. Классификация результатов тестирования произво...
.NET Fest 2017. Игорь Кочетов. Классификация результатов тестирования произво...
 

Último

Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086anil_gaur
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 

Último (20)

FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 

Lecture11.pptx

  • 1. Machine learning system design Prioritizing what to work on: Spam classification example Machine Learning
  • 2. Andrew Ng Building a spam classifier From: cheapsales@buystufffromme.com To: ang@cs.stanford.edu Subject: Buy now! Deal of the week! Buy now! Rolex w4tchs - $100 Med1cine (any kind) - $50 Also low cost M0rgages available. From: Alfred Ng To: ang@cs.stanford.edu Subject: Christmas dates? Hey Andrew, Was talking to Mom about plans for Xmas. When do you get off work. Meet Dec 22? Alf
  • 3. Andrew Ng Building a spam classifier Supervised learning. features of email. spam (1) or not spam (0). Features : Choose 100 words indicative of spam/not spam. From: cheapsales@buystufffromme.com To: ang@cs.stanford.edu Subject: Buy now! Deal of the week! Buy now! Note: In practice, take most frequently occurring words ( 10,000 to 50,000) in training set, rather than manually pick 100 words.
  • 4. Andrew Ng Building a spam classifier How to spend your time to make it have low error? - Collect lots of data - E.g. “honeypot” project. - Develop sophisticated features based on email routing information (from email header). - Develop sophisticated features for message body, e.g. should “discount” and “discounts” be treated as the same word? How about “deal” and “Dealer”? Features about punctuation? - Develop sophisticated algorithm to detect misspellings (e.g. m0rtgage, med1cine, w4tches.)
  • 5. Machine learning system design Error analysis Machine Learning
  • 6. Andrew Ng Recommended approach - Start with a simple algorithm that you can implement quickly. Implement it and test it on your cross-validation data. - Plot learning curves to decide if more data, more features, etc. are likely to help. - Error analysis: Manually examine the examples (in cross validation set) that your algorithm made errors on. See if you spot any systematic trend in what type of examples it is making errors on.
  • 7. Andrew Ng Error Analysis 500 examples in cross validation set Algorithm misclassifies 100 emails. Manually examine the 100 errors, and categorize them based on: (i) What type of email it is (ii) What cues (features) you think would have helped the algorithm classify them correctly. Pharma: Replica/fake: Steal passwords: Other: Deliberate misspellings: (m0rgage, med1cine, etc.) Unusual email routing: Unusual (spamming) punctuation:
  • 8. Andrew Ng The importance of numerical evaluation Should discount/discounts/discounted/discounting be treated as the same word? Can use “stemming” software (E.g. “Porter stemmer”) universe/university. Error analysis may not be helpful for deciding if this is likely to improve performance. Only solution is to try it and see if it works. Need numerical evaluation (e.g., cross validation error) of algorithm’s performance with and without stemming. Without stemming: With stemming: Distinguish upper vs. lower case (Mom/mom):
  • 9. Machine learning system design Error metrics for skewed classes Machine Learning
  • 10. Andrew Ng Cancer classification example Train logistic regression model . ( if cancer, otherwise) Find that you got 1% error on test set. (99% correct diagnoses) Only 0.50% of patients have cancer. function y = predictCancer(x) y = 0; %ignore x! return
  • 11. Andrew Ng Precision/Recall in presence of rare class that we want to detect Precision (Of all patients where we predicted , what fraction actually has cancer?) Recall (Of all patients that actually have cancer, what fraction did we correctly detect as having cancer?)
  • 12. Machine learning system design Trading off precision and recall Machine Learning
  • 13. Andrew Ng Trading off precision and recall Logistic regression: Predict 1 if Predict 0 if Suppose we want to predict (cancer) only if very confident. Suppose we want to avoid missing too many cases of cancer (avoid false negatives). More generally: Predict 1 if threshold. 1 0.5 0.5 1 Recall Precision precision = true positives no. of predicted positive recall = true positives no. of actual positive
  • 14. Andrew Ng Precision(P) Recall (R) Average F1 Score Algorithm 1 0.5 0.4 0.45 0.444 Algorithm 2 0.7 0.1 0.4 0.175 Algorithm 3 0.02 1.0 0.51 0.0392 F1 Score (F score) How to compare precision/recall numbers? Average: F1 Score:
  • 15. Machine learning system design Data for machine learning Machine Learning
  • 16. Designing a high accuracy learning system [Banko and Brill, 2001] E.g. Classify between confusable words. {to, two, too}, {then, than} For breakfast I ate _____ eggs. Algorithms - Perceptron (Logistic regression) - Winnow - Memory-based - Naïve Bayes “It’s not who has the best algorithm that wins. It’s who has the most data.” Training set size (millions) Accuracy
  • 17. Useful test: Given the input , can a human expert confidently predict ? Large data rationale Assume feature has sufficient information to predict accurately. Example: For breakfast I ate _____ eggs. Counterexample: Predict housing price from only size (feet2) and no other features.
  • 18. Large data rationale Use a learning algorithm with many parameters (e.g. logistic regression/linear regression with many features; neural network with many hidden units). Use a very large training set (unlikely to overfit)
  • 19.
  • 20. Fashion MNIST: It contains 70,000 items of clothing in 10 different categories. Each item of clothing is in a 28x28 greyscale image.
  • 21. import tensorflow as tf mnist = tf.keras.datasets.fashion_mnist (training_images, training_labels), (test_images, test_labels) = mnist.load_data() model = tf.keras.models.Sequential([tf.keras.layers.Flatten(), tf.keras.layers.Dense(128, activation=tf.nn.relu), tf.keras.layers.Dense(10, activation=tf.nn.softmax)]) model.compile(optimizer = tf.keras.optimizers.Adam(), loss = 'sparse_categorical_crossentropy', metrics=['accuracy']) model.fit(training_images, training_labels, epochs=5) model.evaluate(test_images, test_labels) classifications = model.predict(test_images) print(classifications[0]) training_images = training_images / 255.0 test_images = test_images / 255.0
  • 22. !wget --no-check-certificate https://storage.googleapis.com/laurencemoroney-blog.appspot.com/rps.zip -O /tmp/rps.zip !wget --no-check-certificate https://storage.googleapis.com/laurencemoroney-blog.appspot.com/rps-test-set.zip -O /tmp/rps-test-set.zip import os import zipfile local_zip = '/tmp/rps.zip' zip_ref = zipfile.ZipFile(local_zip, 'r') zip_ref.extractall('/tmp/') zip_ref.close() local_zip = '/tmp/rps-test-set.zip' zip_ref = zipfile.ZipFile(local_zip, 'r') zip_ref.extractall('/tmp/') zip_ref.close()