SlideShare a Scribd company logo
Hypothesis Testing With Python
True Difference or Noise?
169.61
169.88
Which is better?
Noise?
That's a question.
Mosky
➤ Python Charmer at Pinkoi.
➤ Has spoken at: PyCons in 

TW, MY, KR, JP, SG, HK,

COSCUPs, and TEDx, etc.
➤ Countless hours 

on teaching Python.
➤ Own the Python packages:
ZIPCodeTW, 

MoSQL, Clime, etc.
➤ http://mosky.tw/
8
Outline
➤ Tests with simulated datasets
➤ Tests with actual datasets
➤ How tests work
➤ Common tests
➤ Complete a test
9
Tests with datasets
Go with the notebooks
➤ 01_tests_with_simulated_datasets.ipynb
➤ 02_tests_with_actual_datasets.ipynb
➤ The notebooks are available on https://github.com/
moskytw/hypothesis-testing-with-python .
11
P-value & α
12
P-value & α Wording
p-value < 0.01 Very significant
p-value < 0.05 Significant
p-value ≥ 0.05 Not significant
How tests work
Seeing is believing
➤ p-value = 0.0027 (< 0.01)
➤ !!!
➤ p-value = 0.0271 (0.01–0.05)
➤ !❓!❓❓❓
➤ p-value = 0.2718 (≥ 0.05)
➤ ❓❓❓❓❓❓
➤ 03_how_tests_work.ipynb
14
Fair coin testing
➤ “The coin is fair.”
➤ Case 1: Toss the coin 100 times, and come up 53 heads.
➤ “Hmmm ... somehow fair.”
➤ Case 2: Toss the coin 100 times, and come up 87 heads.
➤ “Not fair! So extreme!”
15
Hypothesis testing
➤ “The means of two populations are equal.”
➤ Case 1: p-value ≥ 0.05.
➤ “Hmmm ... somehow equal.”
➤ Case 2: p-value < 0.05.
➤ “Not equal! So extreme!”
16
Hypothesis testing in a “null” taste
➤ <null hypothesis>
➤ Case 1: p-value ≥ α.
➤ Can't reject <null hypothesis>.
➤ Case 2: p-value < α.
➤ Reject <null hypothesis>.
17
Hypothesis testing in an “alternative” taste
➤ <alternative hypothesis>, ≡ not <null hypothesis>, usually.
➤ Case 1: p-value ≥ α.
➤ Can't accept <alternative hypothesis>.
➤ Case 2: p-value < α.
➤ Accept <alternative hypothesis>.
18
Hypothesis testing in “-+” taste
➤ “The case is negative.”
➤ Case 1: p-value ≥ α.
➤ “Hmmm ... somehow negative.”
➤ Case 2: p-value < α.
➤ “Positive! So extreme!”
19
Common tests
The cheat sheet
➤ If testing independence:
➤ If total size < 1000, or 

more than 20% of cells have expected frequencies < 5, 

Fisher's exact test.
➤ Use Chi-squared test.
➤ If testing difference:
➤ If median is better, don't want to trim outliers, 

variable is ordinal, or any group size < 20:
➤ If groups are paired, Wilcoxon signed-rank test.
➤ If groups are independent, Mann–Whitney U test.
➤ If groups are paired, Paired Student's t-test.
➤ If groups are independent, Welch’s t-test, not Student's.
21
More cheat sheets & references
➤ More cheat sheets:
➤ http://abacus.bates.edu/~ganderso/biology/resources/stats_flow_chart_v2014.pdf
➤ http://www.biostathandbook.com/testchoice.html
➤ https://www.sheffield.ac.uk/mash/what_test
➤ References:
➤ http://www.biostathandbook.com/fishers.html
➤ https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5426219/#__sec5title
➤ http://blog.minitab.com/blog/adventures-in-statistics-2/choosing-between-a-
nonparametric-test-and-a-parametric-test
➤ https://www.sheffield.ac.uk/mash/what_test
➤ https://en.wikipedia.org/wiki/Welch%27s_t-test#Advantages_and_limitations
➤ https://en.wikipedia.org/wiki/Student%27s_t-test#Dependent_t-
test_for_paired_samples
22
The tests in Python
➤ 04_common_tests.ipynb
23
Complete a test
Is p-value enough?
➤ sample size?
➤ alpha?
➤ beta?
➤ effect size?
➤ ❓❓❓❓❓
25
Confusion matrix, where A = 002 = C[0, 0]
26
predicted -
AC
predicted +
BD
actual -
AB
true -
A
false +
B
actual +
CD
false -
C
true +
D
False positive rate = B / AB = observed α
27
predicted -
AC
predicted +
BD
actual -
AB
true -
A
false +
B
actual +
CD
false -
C
true +
D
False negative rate = C / CD = observed β
28
predicted -
AC
predicted +
BD
actual -
AB
true -
A
false +
B
actual +
CD
false -
C
true +
D
➤ Increase sample size to decrease α, β, effect size.
➤ The effect size is the distance between groups.
➤
➤ http://www.drcoplan.com/dsm5-the-case-for-double-
standards
➤ The figures explain α, β perfectly, 

but due to the copyright, only put the link here.
➤ When α, β, effect size are defined, get the sample size.
➤ When α, β, sample size are defined, get the effect size.
When sample size ↑; α, β, effect size ↓
29
=
μ1 − μ2
σ
False discovery rate
➤ Suppose:
➤ A drug test has observed α = 1% and observed β = 1%.
➤ 99.5% of people are not drug users.
➤ What is the probability that a person with a positive test is a
drug user?
31
P(non-user ∣ +) =
P(+ ∣ non-user)P(non-user)
P( + )
=
P(+ ∣ non-user)P(non-user)
P(+ ∣ non-user)P(non-user) + P(+ ∣ user)P(user)
=
0.01 × 0.995
0.01 × 0.995 + 0.99 × 0.005
≈ 66.8 %
False discovery rate = B / BD
32
predicted -
AC
predicted +
BD
actual -
AB
true -
A
false +
B
actual +
CD
false -
C
true +
D
False omission rate = C / AC
33
predicted -
AC
predicted +
BD
actual -
AB
true -
A
false +
B
actual +
CD
false -
C
true +
D
➤ false positive rate = B / AB = observed α
➤ false negative rate= C / CD = observed β
➤ false discovery rate = B / BD
➤ false omission rate = C / AC
➤ actual negative rate = AB / ABCD
➤ sensitivity = D / CD = observed power
➤ specificity = A / AB = observed confidence level
➤ precision = positive predictive value = 1 - FDR
➤ recall = sensitivity
Common “rates” in confusion matrix
36
Most formal steps
➤ State the hypothesis → what test.
➤ Estimate the actual negative rate.
➤ The actual negative rate → what α, β required.
➤ The α, β, effect size → what sample size required.
➤ Still collect a sample as large as possible.
➤ Understand the sample.
➤ Missing data, outliers, Q–Q plot, transform, etc.
➤ Test and report fully.
➤ 05_complete_a_test.ipynb
37
Other statistical tools
Correlation analysis
39
Regression analysis
40
Keep learning
➤ Statistics
➤ Seeing Theory
➤ Biological Statistics
➤ scipy.stats + StatsModels
➤ Research Methods
➤ Machine Learning
➤ Scikit-learn Tutorials
➤ Standford CS229
➤ Hsuan-Tien Lin
41
➤ p-value – the “tail” probability given “actual -”.
➤ confidence interval – the values the middle probability maps to.
➤ actual negative rate > 0.5 ↑ α ↓
➤ actual negative rate < 0.5 ↓ β ↓
➤ α, β, effect size ↓ sample size ↑
➤ Visualization and simulation do help.
➤ Bonus: a1_figures.ipynb .
➤ Let's identify noise efficiently!
Recap
42

More Related Content

What's hot

Understanding Bagging and Boosting
Understanding Bagging and BoostingUnderstanding Bagging and Boosting
Understanding Bagging and Boosting
Mohit Rajput
 
Recurrent Neural Networks. Part 1: Theory
Recurrent Neural Networks. Part 1: TheoryRecurrent Neural Networks. Part 1: Theory
Recurrent Neural Networks. Part 1: Theory
Andrii Gakhov
 
Statistics Using Python | Statistics Python Tutorial | Python Certification T...
Statistics Using Python | Statistics Python Tutorial | Python Certification T...Statistics Using Python | Statistics Python Tutorial | Python Certification T...
Statistics Using Python | Statistics Python Tutorial | Python Certification T...
Edureka!
 
Naive Bayes Classifier
Naive Bayes ClassifierNaive Bayes Classifier
Naive Bayes Classifier
Arunabha Saha
 
Introduction to using google colab
Introduction to using google colabIntroduction to using google colab
Introduction to using google colab
ali alemi
 
Lex
LexLex
Random forest
Random forestRandom forest
Random forest
Ujjawal
 
Introduction of Xgboost
Introduction of XgboostIntroduction of Xgboost
Introduction of Xgboost
michiaki ito
 
Random forest
Random forestRandom forest
Random forest
Musa Hawamdah
 
Bayesian learning
Bayesian learningBayesian learning
Bayesian learning
Rogier Geertzema
 
Learning in AI
Learning in AILearning in AI
Learning in AI
Minakshi Atre
 
Lisp
LispLisp
Lecture 4 Decision Trees (2): Entropy, Information Gain, Gain Ratio
Lecture 4 Decision Trees (2): Entropy, Information Gain, Gain RatioLecture 4 Decision Trees (2): Entropy, Information Gain, Gain Ratio
Lecture 4 Decision Trees (2): Entropy, Information Gain, Gain Ratio
Marina Santini
 
large scale Machine learning
large scale Machine learninglarge scale Machine learning
Introduction to Google Colaboratory.pdf
Introduction to Google Colaboratory.pdfIntroduction to Google Colaboratory.pdf
Introduction to Google Colaboratory.pdf
Yomna Mahmoud Ibrahim Hassan
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Respa Peter
 
Lecture2 general structure of a compiler
Lecture2 general structure of a compilerLecture2 general structure of a compiler
Lecture2 general structure of a compiler
Mahesh Kumar Chelimilla
 
Naive bayes
Naive bayesNaive bayes
Naive bayes
Ashraf Uddin
 
Decision tree
Decision treeDecision tree
Decision tree
SEMINARGROOT
 
Naive Bayes
Naive BayesNaive Bayes
Naive Bayes
CloudxLab
 

What's hot (20)

Understanding Bagging and Boosting
Understanding Bagging and BoostingUnderstanding Bagging and Boosting
Understanding Bagging and Boosting
 
Recurrent Neural Networks. Part 1: Theory
Recurrent Neural Networks. Part 1: TheoryRecurrent Neural Networks. Part 1: Theory
Recurrent Neural Networks. Part 1: Theory
 
Statistics Using Python | Statistics Python Tutorial | Python Certification T...
Statistics Using Python | Statistics Python Tutorial | Python Certification T...Statistics Using Python | Statistics Python Tutorial | Python Certification T...
Statistics Using Python | Statistics Python Tutorial | Python Certification T...
 
Naive Bayes Classifier
Naive Bayes ClassifierNaive Bayes Classifier
Naive Bayes Classifier
 
Introduction to using google colab
Introduction to using google colabIntroduction to using google colab
Introduction to using google colab
 
Lex
LexLex
Lex
 
Random forest
Random forestRandom forest
Random forest
 
Introduction of Xgboost
Introduction of XgboostIntroduction of Xgboost
Introduction of Xgboost
 
Random forest
Random forestRandom forest
Random forest
 
Bayesian learning
Bayesian learningBayesian learning
Bayesian learning
 
Learning in AI
Learning in AILearning in AI
Learning in AI
 
Lisp
LispLisp
Lisp
 
Lecture 4 Decision Trees (2): Entropy, Information Gain, Gain Ratio
Lecture 4 Decision Trees (2): Entropy, Information Gain, Gain RatioLecture 4 Decision Trees (2): Entropy, Information Gain, Gain Ratio
Lecture 4 Decision Trees (2): Entropy, Information Gain, Gain Ratio
 
large scale Machine learning
large scale Machine learninglarge scale Machine learning
large scale Machine learning
 
Introduction to Google Colaboratory.pdf
Introduction to Google Colaboratory.pdfIntroduction to Google Colaboratory.pdf
Introduction to Google Colaboratory.pdf
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Lecture2 general structure of a compiler
Lecture2 general structure of a compilerLecture2 general structure of a compiler
Lecture2 general structure of a compiler
 
Naive bayes
Naive bayesNaive bayes
Naive bayes
 
Decision tree
Decision treeDecision tree
Decision tree
 
Naive Bayes
Naive BayesNaive Bayes
Naive Bayes
 

Similar to Hypothesis Testing With Python

Data Science With Python
Data Science With PythonData Science With Python
Data Science With Python
Mosky Liu
 
Forecasting using data - Deliver 2016
Forecasting using data  - Deliver 2016Forecasting using data  - Deliver 2016
Forecasting using data - Deliver 2016
Troy Magennis
 
Statistical Regression With Python
Statistical Regression With PythonStatistical Regression With Python
Statistical Regression With Python
Mosky Liu
 
Unlocking Anticipatory Text Generation- A Constrained Approach for Large Lan...
Unlocking Anticipatory Text Generation-  A Constrained Approach for Large Lan...Unlocking Anticipatory Text Generation-  A Constrained Approach for Large Lan...
Unlocking Anticipatory Text Generation- A Constrained Approach for Large Lan...
Ingeol Baek
 
Causal Inference for Everyone
Causal Inference for EveryoneCausal Inference for Everyone
Causal Inference for Everyone
AlokSwain16
 
Opticon 2017 Experimenting with Stats Engine
Opticon 2017 Experimenting with Stats EngineOpticon 2017 Experimenting with Stats Engine
Opticon 2017 Experimenting with Stats Engine
Optimizely
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
butest
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
butest
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
EasyStudy3
 
Machine Learning using biased data
Machine Learning using biased dataMachine Learning using biased data
Machine Learning using biased data
Arnaud de Myttenaere
 
Crash Course in A/B testing
Crash Course in A/B testingCrash Course in A/B testing
Crash Course in A/B testing
Wayne Lee
 
Yoav Benjamini, "In the world beyond p<.05: When & How to use P<.0499..."
Yoav Benjamini, "In the world beyond p<.05: When & How to use P<.0499..."Yoav Benjamini, "In the world beyond p<.05: When & How to use P<.0499..."
Yoav Benjamini, "In the world beyond p<.05: When & How to use P<.0499..."
jemille6
 
HYPOTHESIS TESTS.pptx
HYPOTHESIS TESTS.pptxHYPOTHESIS TESTS.pptx
HYPOTHESIS TESTS.pptx
ShikhaAggarwal49
 
Hypothesis and Test
Hypothesis and TestHypothesis and Test
Hypothesis and Test
Avjinder (Avi) Kaler
 
What So Funny About Proportion Testv3
What So Funny About Proportion Testv3What So Funny About Proportion Testv3
What So Funny About Proportion Testv3
ChrisConnors
 
Probability Distributions
Probability DistributionsProbability Distributions
Probability Distributions
CIToolkit
 
Naive bayes classifier python session
Naive bayes classifier  python sessionNaive bayes classifier  python session
Naive bayes classifier python session
Mostafa El-Hosseini
 
Two Proportions
Two Proportions  Two Proportions
Two Proportions
Long Beach City College
 
Practice final answer
Practice final answerPractice final answer
Practice final answer
Ibrahim Lubbad
 
Excursions into the garden of the forking paths
Excursions into the garden of the forking paths Excursions into the garden of the forking paths
Excursions into the garden of the forking paths
Ulrich Dirnagl
 

Similar to Hypothesis Testing With Python (20)

Data Science With Python
Data Science With PythonData Science With Python
Data Science With Python
 
Forecasting using data - Deliver 2016
Forecasting using data  - Deliver 2016Forecasting using data  - Deliver 2016
Forecasting using data - Deliver 2016
 
Statistical Regression With Python
Statistical Regression With PythonStatistical Regression With Python
Statistical Regression With Python
 
Unlocking Anticipatory Text Generation- A Constrained Approach for Large Lan...
Unlocking Anticipatory Text Generation-  A Constrained Approach for Large Lan...Unlocking Anticipatory Text Generation-  A Constrained Approach for Large Lan...
Unlocking Anticipatory Text Generation- A Constrained Approach for Large Lan...
 
Causal Inference for Everyone
Causal Inference for EveryoneCausal Inference for Everyone
Causal Inference for Everyone
 
Opticon 2017 Experimenting with Stats Engine
Opticon 2017 Experimenting with Stats EngineOpticon 2017 Experimenting with Stats Engine
Opticon 2017 Experimenting with Stats Engine
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Machine Learning using biased data
Machine Learning using biased dataMachine Learning using biased data
Machine Learning using biased data
 
Crash Course in A/B testing
Crash Course in A/B testingCrash Course in A/B testing
Crash Course in A/B testing
 
Yoav Benjamini, "In the world beyond p<.05: When & How to use P<.0499..."
Yoav Benjamini, "In the world beyond p<.05: When & How to use P<.0499..."Yoav Benjamini, "In the world beyond p<.05: When & How to use P<.0499..."
Yoav Benjamini, "In the world beyond p<.05: When & How to use P<.0499..."
 
HYPOTHESIS TESTS.pptx
HYPOTHESIS TESTS.pptxHYPOTHESIS TESTS.pptx
HYPOTHESIS TESTS.pptx
 
Hypothesis and Test
Hypothesis and TestHypothesis and Test
Hypothesis and Test
 
What So Funny About Proportion Testv3
What So Funny About Proportion Testv3What So Funny About Proportion Testv3
What So Funny About Proportion Testv3
 
Probability Distributions
Probability DistributionsProbability Distributions
Probability Distributions
 
Naive bayes classifier python session
Naive bayes classifier  python sessionNaive bayes classifier  python session
Naive bayes classifier python session
 
Two Proportions
Two Proportions  Two Proportions
Two Proportions
 
Practice final answer
Practice final answerPractice final answer
Practice final answer
 
Excursions into the garden of the forking paths
Excursions into the garden of the forking paths Excursions into the garden of the forking paths
Excursions into the garden of the forking paths
 

More from Mosky Liu

Practicing Python 3
Practicing Python 3Practicing Python 3
Practicing Python 3
Mosky Liu
 
Elegant concurrency
Elegant concurrencyElegant concurrency
Elegant concurrency
Mosky Liu
 
Boost Maintainability
Boost MaintainabilityBoost Maintainability
Boost Maintainability
Mosky Liu
 
Beyond the Style Guides
Beyond the Style GuidesBeyond the Style Guides
Beyond the Style Guides
Mosky Liu
 
Simple Belief - Mosky @ TEDxNTUST 2015
Simple Belief - Mosky @ TEDxNTUST 2015Simple Belief - Mosky @ TEDxNTUST 2015
Simple Belief - Mosky @ TEDxNTUST 2015
Mosky Liu
 
Concurrency in Python
Concurrency in PythonConcurrency in Python
Concurrency in Python
Mosky Liu
 
ZIPCodeTW: Find Taiwan ZIP Code by Address Fuzzily
ZIPCodeTW: Find Taiwan ZIP Code by Address FuzzilyZIPCodeTW: Find Taiwan ZIP Code by Address Fuzzily
ZIPCodeTW: Find Taiwan ZIP Code by Address Fuzzily
Mosky Liu
 
Graph-Tool in Practice
Graph-Tool in PracticeGraph-Tool in Practice
Graph-Tool in Practice
Mosky Liu
 
Minimal MVC in JavaScript
Minimal MVC in JavaScriptMinimal MVC in JavaScript
Minimal MVC in JavaScript
Mosky Liu
 
Learning Git with Workflows
Learning Git with WorkflowsLearning Git with Workflows
Learning Git with Workflows
Mosky Liu
 
Dive into Pinkoi 2013
Dive into Pinkoi 2013Dive into Pinkoi 2013
Dive into Pinkoi 2013
Mosky Liu
 
MoSQL: More than SQL, but Less than ORM @ PyCon APAC 2013
MoSQL: More than SQL, but Less than ORM @ PyCon APAC 2013MoSQL: More than SQL, but Less than ORM @ PyCon APAC 2013
MoSQL: More than SQL, but Less than ORM @ PyCon APAC 2013
Mosky Liu
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from Data
Mosky Liu
 
MoSQL: More than SQL, but less than ORM
MoSQL: More than SQL, but less than ORMMoSQL: More than SQL, but less than ORM
MoSQL: More than SQL, but less than ORM
Mosky Liu
 
Introduction to Clime
Introduction to ClimeIntroduction to Clime
Introduction to Clime
Mosky Liu
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.
Mosky Liu
 
Programming with Python - Basic
Programming with Python - BasicProgramming with Python - Basic
Programming with Python - Basic
Mosky Liu
 

More from Mosky Liu (17)

Practicing Python 3
Practicing Python 3Practicing Python 3
Practicing Python 3
 
Elegant concurrency
Elegant concurrencyElegant concurrency
Elegant concurrency
 
Boost Maintainability
Boost MaintainabilityBoost Maintainability
Boost Maintainability
 
Beyond the Style Guides
Beyond the Style GuidesBeyond the Style Guides
Beyond the Style Guides
 
Simple Belief - Mosky @ TEDxNTUST 2015
Simple Belief - Mosky @ TEDxNTUST 2015Simple Belief - Mosky @ TEDxNTUST 2015
Simple Belief - Mosky @ TEDxNTUST 2015
 
Concurrency in Python
Concurrency in PythonConcurrency in Python
Concurrency in Python
 
ZIPCodeTW: Find Taiwan ZIP Code by Address Fuzzily
ZIPCodeTW: Find Taiwan ZIP Code by Address FuzzilyZIPCodeTW: Find Taiwan ZIP Code by Address Fuzzily
ZIPCodeTW: Find Taiwan ZIP Code by Address Fuzzily
 
Graph-Tool in Practice
Graph-Tool in PracticeGraph-Tool in Practice
Graph-Tool in Practice
 
Minimal MVC in JavaScript
Minimal MVC in JavaScriptMinimal MVC in JavaScript
Minimal MVC in JavaScript
 
Learning Git with Workflows
Learning Git with WorkflowsLearning Git with Workflows
Learning Git with Workflows
 
Dive into Pinkoi 2013
Dive into Pinkoi 2013Dive into Pinkoi 2013
Dive into Pinkoi 2013
 
MoSQL: More than SQL, but Less than ORM @ PyCon APAC 2013
MoSQL: More than SQL, but Less than ORM @ PyCon APAC 2013MoSQL: More than SQL, but Less than ORM @ PyCon APAC 2013
MoSQL: More than SQL, but Less than ORM @ PyCon APAC 2013
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from Data
 
MoSQL: More than SQL, but less than ORM
MoSQL: More than SQL, but less than ORMMoSQL: More than SQL, but less than ORM
MoSQL: More than SQL, but less than ORM
 
Introduction to Clime
Introduction to ClimeIntroduction to Clime
Introduction to Clime
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.
 
Programming with Python - Basic
Programming with Python - BasicProgramming with Python - Basic
Programming with Python - Basic
 

Recently uploaded

一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
osoyvvf
 
一比一原版(UofT毕业证)多伦多大学毕业证如何办理
一比一原版(UofT毕业证)多伦多大学毕业证如何办理一比一原版(UofT毕业证)多伦多大学毕业证如何办理
一比一原版(UofT毕业证)多伦多大学毕业证如何办理
exukyp
 
Q4FY24 Investor-Presentation.pdf bank slide
Q4FY24 Investor-Presentation.pdf bank slideQ4FY24 Investor-Presentation.pdf bank slide
Q4FY24 Investor-Presentation.pdf bank slide
mukulupadhayay1
 
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
ywqeos
 
SAP BW4HANA Implementagtion Content Document
SAP BW4HANA Implementagtion Content DocumentSAP BW4HANA Implementagtion Content Document
SAP BW4HANA Implementagtion Content Document
newdirectionconsulta
 
Senior Software Profiles Backend Sample - Sheet1.pdf
Senior Software Profiles  Backend Sample - Sheet1.pdfSenior Software Profiles  Backend Sample - Sheet1.pdf
Senior Software Profiles Backend Sample - Sheet1.pdf
Vineet
 
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdfNamma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
22ad0301
 
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service LucknowCall Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
hiju9823
 
社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .
NABLAS株式会社
 
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
hqfek
 
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
Timothy Spann
 
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
actyx
 
一比一原版(uob毕业证书)伯明翰大学毕业证如何办理
一比一原版(uob毕业证书)伯明翰大学毕业证如何办理一比一原版(uob毕业证书)伯明翰大学毕业证如何办理
一比一原版(uob毕业证书)伯明翰大学毕业证如何办理
9gr6pty
 
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
asyed10
 
Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...
Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...
Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...
Marlon Dumas
 
A gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented GenerationA gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented Generation
dataschool1
 
一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理
zsafxbf
 
一比一原版澳洲西澳大学毕业证(uwa毕业证书)如何办理
一比一原版澳洲西澳大学毕业证(uwa毕业证书)如何办理一比一原版澳洲西澳大学毕业证(uwa毕业证书)如何办理
一比一原版澳洲西澳大学毕业证(uwa毕业证书)如何办理
aguty
 
Sample Devops SRE Product Companies .pdf
Sample Devops SRE  Product Companies .pdfSample Devops SRE  Product Companies .pdf
Sample Devops SRE Product Companies .pdf
Vineet
 
Econ3060_Screen Time and Success_ final_GroupProject.pdf
Econ3060_Screen Time and Success_ final_GroupProject.pdfEcon3060_Screen Time and Success_ final_GroupProject.pdf
Econ3060_Screen Time and Success_ final_GroupProject.pdf
blueshagoo1
 

Recently uploaded (20)

一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
 
一比一原版(UofT毕业证)多伦多大学毕业证如何办理
一比一原版(UofT毕业证)多伦多大学毕业证如何办理一比一原版(UofT毕业证)多伦多大学毕业证如何办理
一比一原版(UofT毕业证)多伦多大学毕业证如何办理
 
Q4FY24 Investor-Presentation.pdf bank slide
Q4FY24 Investor-Presentation.pdf bank slideQ4FY24 Investor-Presentation.pdf bank slide
Q4FY24 Investor-Presentation.pdf bank slide
 
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
 
SAP BW4HANA Implementagtion Content Document
SAP BW4HANA Implementagtion Content DocumentSAP BW4HANA Implementagtion Content Document
SAP BW4HANA Implementagtion Content Document
 
Senior Software Profiles Backend Sample - Sheet1.pdf
Senior Software Profiles  Backend Sample - Sheet1.pdfSenior Software Profiles  Backend Sample - Sheet1.pdf
Senior Software Profiles Backend Sample - Sheet1.pdf
 
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdfNamma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
Namma-Kalvi-11th-Physics-Study-Material-Unit-1-EM-221086.pdf
 
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service LucknowCall Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
Call Girls Lucknow 0000000000 Independent Call Girl Service Lucknow
 
社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .社内勉強会資料_Hallucination of LLMs               .
社内勉強会資料_Hallucination of LLMs               .
 
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
 
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
06-20-2024-AI Camp Meetup-Unstructured Data and Vector Databases
 
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
 
一比一原版(uob毕业证书)伯明翰大学毕业证如何办理
一比一原版(uob毕业证书)伯明翰大学毕业证如何办理一比一原版(uob毕业证书)伯明翰大学毕业证如何办理
一比一原版(uob毕业证书)伯明翰大学毕业证如何办理
 
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
 
Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...
Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...
Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...
 
A gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented GenerationA gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented Generation
 
一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理
 
一比一原版澳洲西澳大学毕业证(uwa毕业证书)如何办理
一比一原版澳洲西澳大学毕业证(uwa毕业证书)如何办理一比一原版澳洲西澳大学毕业证(uwa毕业证书)如何办理
一比一原版澳洲西澳大学毕业证(uwa毕业证书)如何办理
 
Sample Devops SRE Product Companies .pdf
Sample Devops SRE  Product Companies .pdfSample Devops SRE  Product Companies .pdf
Sample Devops SRE Product Companies .pdf
 
Econ3060_Screen Time and Success_ final_GroupProject.pdf
Econ3060_Screen Time and Success_ final_GroupProject.pdfEcon3060_Screen Time and Success_ final_GroupProject.pdf
Econ3060_Screen Time and Success_ final_GroupProject.pdf
 

Hypothesis Testing With Python

  • 1. Hypothesis Testing With Python True Difference or Noise?
  • 7.
  • 8. Mosky ➤ Python Charmer at Pinkoi. ➤ Has spoken at: PyCons in 
 TW, MY, KR, JP, SG, HK,
 COSCUPs, and TEDx, etc. ➤ Countless hours 
 on teaching Python. ➤ Own the Python packages: ZIPCodeTW, 
 MoSQL, Clime, etc. ➤ http://mosky.tw/ 8
  • 9. Outline ➤ Tests with simulated datasets ➤ Tests with actual datasets ➤ How tests work ➤ Common tests ➤ Complete a test 9
  • 11. Go with the notebooks ➤ 01_tests_with_simulated_datasets.ipynb ➤ 02_tests_with_actual_datasets.ipynb ➤ The notebooks are available on https://github.com/ moskytw/hypothesis-testing-with-python . 11
  • 12. P-value & α 12 P-value & α Wording p-value < 0.01 Very significant p-value < 0.05 Significant p-value ≥ 0.05 Not significant
  • 14. Seeing is believing ➤ p-value = 0.0027 (< 0.01) ➤ !!! ➤ p-value = 0.0271 (0.01–0.05) ➤ !❓!❓❓❓ ➤ p-value = 0.2718 (≥ 0.05) ➤ ❓❓❓❓❓❓ ➤ 03_how_tests_work.ipynb 14
  • 15. Fair coin testing ➤ “The coin is fair.” ➤ Case 1: Toss the coin 100 times, and come up 53 heads. ➤ “Hmmm ... somehow fair.” ➤ Case 2: Toss the coin 100 times, and come up 87 heads. ➤ “Not fair! So extreme!” 15
  • 16. Hypothesis testing ➤ “The means of two populations are equal.” ➤ Case 1: p-value ≥ 0.05. ➤ “Hmmm ... somehow equal.” ➤ Case 2: p-value < 0.05. ➤ “Not equal! So extreme!” 16
  • 17. Hypothesis testing in a “null” taste ➤ <null hypothesis> ➤ Case 1: p-value ≥ α. ➤ Can't reject <null hypothesis>. ➤ Case 2: p-value < α. ➤ Reject <null hypothesis>. 17
  • 18. Hypothesis testing in an “alternative” taste ➤ <alternative hypothesis>, ≡ not <null hypothesis>, usually. ➤ Case 1: p-value ≥ α. ➤ Can't accept <alternative hypothesis>. ➤ Case 2: p-value < α. ➤ Accept <alternative hypothesis>. 18
  • 19. Hypothesis testing in “-+” taste ➤ “The case is negative.” ➤ Case 1: p-value ≥ α. ➤ “Hmmm ... somehow negative.” ➤ Case 2: p-value < α. ➤ “Positive! So extreme!” 19
  • 21. The cheat sheet ➤ If testing independence: ➤ If total size < 1000, or 
 more than 20% of cells have expected frequencies < 5, 
 Fisher's exact test. ➤ Use Chi-squared test. ➤ If testing difference: ➤ If median is better, don't want to trim outliers, 
 variable is ordinal, or any group size < 20: ➤ If groups are paired, Wilcoxon signed-rank test. ➤ If groups are independent, Mann–Whitney U test. ➤ If groups are paired, Paired Student's t-test. ➤ If groups are independent, Welch’s t-test, not Student's. 21
  • 22. More cheat sheets & references ➤ More cheat sheets: ➤ http://abacus.bates.edu/~ganderso/biology/resources/stats_flow_chart_v2014.pdf ➤ http://www.biostathandbook.com/testchoice.html ➤ https://www.sheffield.ac.uk/mash/what_test ➤ References: ➤ http://www.biostathandbook.com/fishers.html ➤ https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5426219/#__sec5title ➤ http://blog.minitab.com/blog/adventures-in-statistics-2/choosing-between-a- nonparametric-test-and-a-parametric-test ➤ https://www.sheffield.ac.uk/mash/what_test ➤ https://en.wikipedia.org/wiki/Welch%27s_t-test#Advantages_and_limitations ➤ https://en.wikipedia.org/wiki/Student%27s_t-test#Dependent_t- test_for_paired_samples 22
  • 23. The tests in Python ➤ 04_common_tests.ipynb 23
  • 25. Is p-value enough? ➤ sample size? ➤ alpha? ➤ beta? ➤ effect size? ➤ ❓❓❓❓❓ 25
  • 26. Confusion matrix, where A = 002 = C[0, 0] 26 predicted - AC predicted + BD actual - AB true - A false + B actual + CD false - C true + D
  • 27. False positive rate = B / AB = observed α 27 predicted - AC predicted + BD actual - AB true - A false + B actual + CD false - C true + D
  • 28. False negative rate = C / CD = observed β 28 predicted - AC predicted + BD actual - AB true - A false + B actual + CD false - C true + D
  • 29. ➤ Increase sample size to decrease α, β, effect size. ➤ The effect size is the distance between groups. ➤ ➤ http://www.drcoplan.com/dsm5-the-case-for-double- standards ➤ The figures explain α, β perfectly, 
 but due to the copyright, only put the link here. ➤ When α, β, effect size are defined, get the sample size. ➤ When α, β, sample size are defined, get the effect size. When sample size ↑; α, β, effect size ↓ 29 = μ1 − μ2 σ
  • 30.
  • 31. False discovery rate ➤ Suppose: ➤ A drug test has observed α = 1% and observed β = 1%. ➤ 99.5% of people are not drug users. ➤ What is the probability that a person with a positive test is a drug user? 31 P(non-user ∣ +) = P(+ ∣ non-user)P(non-user) P( + ) = P(+ ∣ non-user)P(non-user) P(+ ∣ non-user)P(non-user) + P(+ ∣ user)P(user) = 0.01 × 0.995 0.01 × 0.995 + 0.99 × 0.005 ≈ 66.8 %
  • 32. False discovery rate = B / BD 32 predicted - AC predicted + BD actual - AB true - A false + B actual + CD false - C true + D
  • 33. False omission rate = C / AC 33 predicted - AC predicted + BD actual - AB true - A false + B actual + CD false - C true + D
  • 34.
  • 35.
  • 36. ➤ false positive rate = B / AB = observed α ➤ false negative rate= C / CD = observed β ➤ false discovery rate = B / BD ➤ false omission rate = C / AC ➤ actual negative rate = AB / ABCD ➤ sensitivity = D / CD = observed power ➤ specificity = A / AB = observed confidence level ➤ precision = positive predictive value = 1 - FDR ➤ recall = sensitivity Common “rates” in confusion matrix 36
  • 37. Most formal steps ➤ State the hypothesis → what test. ➤ Estimate the actual negative rate. ➤ The actual negative rate → what α, β required. ➤ The α, β, effect size → what sample size required. ➤ Still collect a sample as large as possible. ➤ Understand the sample. ➤ Missing data, outliers, Q–Q plot, transform, etc. ➤ Test and report fully. ➤ 05_complete_a_test.ipynb 37
  • 41. Keep learning ➤ Statistics ➤ Seeing Theory ➤ Biological Statistics ➤ scipy.stats + StatsModels ➤ Research Methods ➤ Machine Learning ➤ Scikit-learn Tutorials ➤ Standford CS229 ➤ Hsuan-Tien Lin 41
  • 42. ➤ p-value – the “tail” probability given “actual -”. ➤ confidence interval – the values the middle probability maps to. ➤ actual negative rate > 0.5 ↑ α ↓ ➤ actual negative rate < 0.5 ↓ β ↓ ➤ α, β, effect size ↓ sample size ↑ ➤ Visualization and simulation do help. ➤ Bonus: a1_figures.ipynb . ➤ Let's identify noise efficiently! Recap 42