SlideShare una empresa de Scribd logo
1 de 19
Do Your
Homework!
Writing Tests for Data
Science and Natural
Language Processing
David Waterman
github.com/drwaterman/pydatadctesting
Agenda 1. Why test your code?
2. Our problem: text analysis, Natural
Language Processing
3. Practical Implementation
How Does
Homework
Work?
Why give students homework problems
and the matching solutions?
If you know
where you
are going,
you can tell if
you are
moving in the
right
direction
Many of our daily tasks are like
homework problems
Test Driven
Development
Cycle
Why Test
Your Code
For others:
 Reduce bugs
 Improve feedback
loops
 Speeds up iteration
 Makes code more
reusable
 Increases
confidence in the
system
For you:
 Earns trust and
confidence in you and
your work
 Earns respect from devs
and engineers (for whom
it’s not optional)
 Allows you to submit to
open source projects
 Probably required for
acceptance into external
code base
Agenda 1. Why test your code?
2. Our problem: text analysis,
Natural Language Processing
3. Practical Implementation
Supply
Chain
Insight
Who makes
what?
Identifying
Relationships
in Text
Challenges
• Per the long-term agreement,
WABCO will supply its single-piston
air disc brake (ADB) technology,
MAXX, for the manufacturing of
Hyundai’s new medium-duty trucks,
which are expected to start from
August 2019.
• Timken has become the sole
supplier of needle roller bearings to
Volkswagen Transmission.
• Dana Corp. has begun supplying
Ford Motor Co. with its
thermoplastic cylinder-head-cover
modules for the automaker's 3.0-
liter Duratec V-6 engine.
The structure of text is
domain specific.
Regular people don’t
talk like this:
Our
Approach:
“Gold” Tests
 Human reads the text
 Identifies relationship
from text
 Puts relationship into
machine-friendly
format (JSON, YAML)
 Writes a test for the
relationship
 Write and rewrite
code to pass the test
Agenda 1. Why test your code?
2. Our problem: text analysis, Natural
Language Processing
3. Practical Implementation
Recommendation:
Pytest as your
framework
➕ More Pythonic
➕ Easy to write fast - less
boilerplate
➕ Can still run unittests,
doctests, and nose
➕ Readable, pretty output
(including HTML reports)
➕ Great documentation &
guides
➖ It’s not a builtin
What to
Test
 Expected output
 Invalid input
 Edge cases
Data ModelsCode
 Data is valid
 Types are correct
 Missing values are
handled correctly
 Format is correct
 Produces
expected results
 Can be used to
benchmark
 Monitor for
model drift
EXAMPLES
Repo: https://github.com/drwaterman/pydatadctesting
Pytest
features
useful for
Data
Science
▪ Fixtures – For when you need something
repeatedly over multiple tests (Loading
test data, making a connection,
preprocessing data)
▪ Skip and Xfail – For when you know what
to test for but the code doesn’t pass yet
▪ Comparing images/plots
– Available in matplotlib
▪ Benchmarking a model
Some Nice
Pytest
Options
Save your pytest
command line
arguments in a
shell script
pytest --html=test-logs/testreport.html --self-
contained-html --cov=my_module --cov-report term-
missing -r aPp test
▪ --html: Where to save the html test report
▪ --self-contained-html: Save everything in one html
file (no external CSS, etc.)
▪ --cov=: What modules to include in the coverage
report
▪ --cov-report term-missing: Terminal report w/
missing line numbers
▪ -r aPp: display test results summary at the end
▪ test: The location in which to run the tests
CONCLUSION
 Pytest is easy!
 Start now
 It will earn you trust and respect
 It is possible to use it even if your code is
stochastic
Time for questions!

Más contenido relacionado

La actualidad más candente

Funda Gunes, Senior Research Statistician Developer & Patrick Koch, Principal...
Funda Gunes, Senior Research Statistician Developer & Patrick Koch, Principal...Funda Gunes, Senior Research Statistician Developer & Patrick Koch, Principal...
Funda Gunes, Senior Research Statistician Developer & Patrick Koch, Principal...
MLconf
 

La actualidad más candente (20)

High-Performance Python
High-Performance PythonHigh-Performance Python
High-Performance Python
 
Oleksii Moskalenko "Continuous Delivery of ML Pipelines to Production"
Oleksii Moskalenko "Continuous Delivery of ML Pipelines to Production"Oleksii Moskalenko "Continuous Delivery of ML Pipelines to Production"
Oleksii Moskalenko "Continuous Delivery of ML Pipelines to Production"
 
Managing and Versioning Machine Learning Models in Python
Managing and Versioning Machine Learning Models in PythonManaging and Versioning Machine Learning Models in Python
Managing and Versioning Machine Learning Models in Python
 
Funda Gunes, Senior Research Statistician Developer & Patrick Koch, Principal...
Funda Gunes, Senior Research Statistician Developer & Patrick Koch, Principal...Funda Gunes, Senior Research Statistician Developer & Patrick Koch, Principal...
Funda Gunes, Senior Research Statistician Developer & Patrick Koch, Principal...
 
Common Problems in Hyperparameter Optimization
Common Problems in Hyperparameter OptimizationCommon Problems in Hyperparameter Optimization
Common Problems in Hyperparameter Optimization
 
Braden Hancock "Programmatically creating and managing training data with Sno...
Braden Hancock "Programmatically creating and managing training data with Sno...Braden Hancock "Programmatically creating and managing training data with Sno...
Braden Hancock "Programmatically creating and managing training data with Sno...
 
Jean-François Puget, Distinguished Engineer, Machine Learning and Optimizatio...
Jean-François Puget, Distinguished Engineer, Machine Learning and Optimizatio...Jean-François Puget, Distinguished Engineer, Machine Learning and Optimizatio...
Jean-François Puget, Distinguished Engineer, Machine Learning and Optimizatio...
 
Online Machine Learning: introduction and examples
Online Machine Learning:  introduction and examplesOnline Machine Learning:  introduction and examples
Online Machine Learning: introduction and examples
 
Julia + R for Data Science
Julia + R for Data ScienceJulia + R for Data Science
Julia + R for Data Science
 
Nikhil Garg, Engineering Manager, Quora at MLconf SF 2016
Nikhil Garg, Engineering Manager, Quora at MLconf SF 2016Nikhil Garg, Engineering Manager, Quora at MLconf SF 2016
Nikhil Garg, Engineering Manager, Quora at MLconf SF 2016
 
Death to project documentation with eXtreme Programming
Death to project documentation with eXtreme ProgrammingDeath to project documentation with eXtreme Programming
Death to project documentation with eXtreme Programming
 
Misha Bilenko, Principal Researcher, Microsoft at MLconf SEA - 5/01/15
Misha Bilenko, Principal Researcher, Microsoft at MLconf SEA - 5/01/15Misha Bilenko, Principal Researcher, Microsoft at MLconf SEA - 5/01/15
Misha Bilenko, Principal Researcher, Microsoft at MLconf SEA - 5/01/15
 
Using dataset versioning in data science
Using dataset versioning in data scienceUsing dataset versioning in data science
Using dataset versioning in data science
 
10 more lessons learned from building Machine Learning systems
10 more lessons learned from building Machine Learning systems10 more lessons learned from building Machine Learning systems
10 more lessons learned from building Machine Learning systems
 
Machine Learning In Production
Machine Learning In ProductionMachine Learning In Production
Machine Learning In Production
 
Scott Clark, CEO, SigOpt, at The AI Conference 2017
Scott Clark, CEO, SigOpt, at The AI Conference 2017Scott Clark, CEO, SigOpt, at The AI Conference 2017
Scott Clark, CEO, SigOpt, at The AI Conference 2017
 
Data Science Challenges in Personal Program Analysis
Data Science Challenges in Personal Program AnalysisData Science Challenges in Personal Program Analysis
Data Science Challenges in Personal Program Analysis
 
Kaz Sato, Evangelist, Google at MLconf ATL 2016
Kaz Sato, Evangelist, Google at MLconf ATL 2016Kaz Sato, Evangelist, Google at MLconf ATL 2016
Kaz Sato, Evangelist, Google at MLconf ATL 2016
 
Improving data interoperability in Python and R
Improving data interoperability in Python and RImproving data interoperability in Python and R
Improving data interoperability in Python and R
 
Implications of GPT-3
Implications of GPT-3Implications of GPT-3
Implications of GPT-3
 

Similar a Do Your Homework! Writing tests for Data Science and Stochastic Code - David Waterman

Trends in Agile Testing by Lisa Crispin
Trends in Agile Testing by Lisa CrispinTrends in Agile Testing by Lisa Crispin
Trends in Agile Testing by Lisa Crispin
Directi Group
 

Similar a Do Your Homework! Writing tests for Data Science and Stochastic Code - David Waterman (20)

Web performance
Web  performance Web  performance
Web performance
 
Measuring Your Code
Measuring Your CodeMeasuring Your Code
Measuring Your Code
 
Illustrated Code (ASE 2021)
Illustrated Code (ASE 2021)Illustrated Code (ASE 2021)
Illustrated Code (ASE 2021)
 
Trends in Agile Testing by Lisa Crispin
Trends in Agile Testing by Lisa CrispinTrends in Agile Testing by Lisa Crispin
Trends in Agile Testing by Lisa Crispin
 
Bodo Value Guide.pdf
Bodo Value Guide.pdfBodo Value Guide.pdf
Bodo Value Guide.pdf
 
Automated tests
Automated testsAutomated tests
Automated tests
 
Scaling Streaming - Concepts, Research, Goals
Scaling Streaming - Concepts, Research, GoalsScaling Streaming - Concepts, Research, Goals
Scaling Streaming - Concepts, Research, Goals
 
DevOpsDaysRiga 2017 ignite: Mikhail Iljin - DevOps meets Data Science - how t...
DevOpsDaysRiga 2017 ignite: Mikhail Iljin - DevOps meets Data Science - how t...DevOpsDaysRiga 2017 ignite: Mikhail Iljin - DevOps meets Data Science - how t...
DevOpsDaysRiga 2017 ignite: Mikhail Iljin - DevOps meets Data Science - how t...
 
Data science tools of the trade
Data science tools of the tradeData science tools of the trade
Data science tools of the trade
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional Programmer
 
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual StudioSPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
SPCA2013 - Test-driven Development with SharePoint 2013 and Visual Studio
 
When develpment met test(shift left testing)
When develpment met test(shift left testing)When develpment met test(shift left testing)
When develpment met test(shift left testing)
 
What would Jesus Developer do?
What would Jesus Developer do?What would Jesus Developer do?
What would Jesus Developer do?
 
10 Ways To Improve Your Code
10 Ways To Improve Your Code10 Ways To Improve Your Code
10 Ways To Improve Your Code
 
Whats In Your QA Tool Belt?
Whats In Your QA Tool Belt?Whats In Your QA Tool Belt?
Whats In Your QA Tool Belt?
 
2014 toronto-torbug
2014 toronto-torbug2014 toronto-torbug
2014 toronto-torbug
 
Testing Big Data solutions fast and furiously
Testing Big Data solutions fast and furiouslyTesting Big Data solutions fast and furiously
Testing Big Data solutions fast and furiously
 
Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.
 
Testing 101
Testing 101Testing 101
Testing 101
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 

Más de PyData

Más de PyData (20)

Michal Mucha: Build and Deploy an End-to-end Streaming NLP Insight System | P...
Michal Mucha: Build and Deploy an End-to-end Streaming NLP Insight System | P...Michal Mucha: Build and Deploy an End-to-end Streaming NLP Insight System | P...
Michal Mucha: Build and Deploy an End-to-end Streaming NLP Insight System | P...
 
Unit testing data with marbles - Jane Stewart Adams, Leif Walsh
Unit testing data with marbles - Jane Stewart Adams, Leif WalshUnit testing data with marbles - Jane Stewart Adams, Leif Walsh
Unit testing data with marbles - Jane Stewart Adams, Leif Walsh
 
The TileDB Array Data Storage Manager - Stavros Papadopoulos, Jake Bolewski
The TileDB Array Data Storage Manager - Stavros Papadopoulos, Jake BolewskiThe TileDB Array Data Storage Manager - Stavros Papadopoulos, Jake Bolewski
The TileDB Array Data Storage Manager - Stavros Papadopoulos, Jake Bolewski
 
Graph Analytics - From the Whiteboard to Your Toolbox - Sam Lerma
Graph Analytics - From the Whiteboard to Your Toolbox - Sam LermaGraph Analytics - From the Whiteboard to Your Toolbox - Sam Lerma
Graph Analytics - From the Whiteboard to Your Toolbox - Sam Lerma
 
Mining dockless bikeshare and dockless scootershare trip data - Stefanie Brod...
Mining dockless bikeshare and dockless scootershare trip data - Stefanie Brod...Mining dockless bikeshare and dockless scootershare trip data - Stefanie Brod...
Mining dockless bikeshare and dockless scootershare trip data - Stefanie Brod...
 
Avoiding Bad Database Surprises: Simulation and Scalability - Steven Lott
Avoiding Bad Database Surprises: Simulation and Scalability - Steven LottAvoiding Bad Database Surprises: Simulation and Scalability - Steven Lott
Avoiding Bad Database Surprises: Simulation and Scalability - Steven Lott
 
Words in Space - Rebecca Bilbro
Words in Space - Rebecca BilbroWords in Space - Rebecca Bilbro
Words in Space - Rebecca Bilbro
 
Pydata beautiful soup - Monica Puerto
Pydata beautiful soup - Monica PuertoPydata beautiful soup - Monica Puerto
Pydata beautiful soup - Monica Puerto
 
1D Convolutional Neural Networks for Time Series Modeling - Nathan Janos, Jef...
1D Convolutional Neural Networks for Time Series Modeling - Nathan Janos, Jef...1D Convolutional Neural Networks for Time Series Modeling - Nathan Janos, Jef...
1D Convolutional Neural Networks for Time Series Modeling - Nathan Janos, Jef...
 
Extending Pandas with Custom Types - Will Ayd
Extending Pandas with Custom Types - Will AydExtending Pandas with Custom Types - Will Ayd
Extending Pandas with Custom Types - Will Ayd
 
Measuring Model Fairness - Stephen Hoover
Measuring Model Fairness - Stephen HooverMeasuring Model Fairness - Stephen Hoover
Measuring Model Fairness - Stephen Hoover
 
What's the Science in Data Science? - Skipper Seabold
What's the Science in Data Science? - Skipper SeaboldWhat's the Science in Data Science? - Skipper Seabold
What's the Science in Data Science? - Skipper Seabold
 
Applying Statistical Modeling and Machine Learning to Perform Time-Series For...
Applying Statistical Modeling and Machine Learning to Perform Time-Series For...Applying Statistical Modeling and Machine Learning to Perform Time-Series For...
Applying Statistical Modeling and Machine Learning to Perform Time-Series For...
 
Solving very simple substitution ciphers algorithmically - Stephen Enright-Ward
Solving very simple substitution ciphers algorithmically - Stephen Enright-WardSolving very simple substitution ciphers algorithmically - Stephen Enright-Ward
Solving very simple substitution ciphers algorithmically - Stephen Enright-Ward
 
The Face of Nanomaterials: Insightful Classification Using Deep Learning - An...
The Face of Nanomaterials: Insightful Classification Using Deep Learning - An...The Face of Nanomaterials: Insightful Classification Using Deep Learning - An...
The Face of Nanomaterials: Insightful Classification Using Deep Learning - An...
 
Deprecating the state machine: building conversational AI with the Rasa stack...
Deprecating the state machine: building conversational AI with the Rasa stack...Deprecating the state machine: building conversational AI with the Rasa stack...
Deprecating the state machine: building conversational AI with the Rasa stack...
 
Towards automating machine learning: benchmarking tools for hyperparameter tu...
Towards automating machine learning: benchmarking tools for hyperparameter tu...Towards automating machine learning: benchmarking tools for hyperparameter tu...
Towards automating machine learning: benchmarking tools for hyperparameter tu...
 
Using GANs to improve generalization in a semi-supervised setting - trying it...
Using GANs to improve generalization in a semi-supervised setting - trying it...Using GANs to improve generalization in a semi-supervised setting - trying it...
Using GANs to improve generalization in a semi-supervised setting - trying it...
 
LightFields.jl: Fast 3D image reconstruction for VR applications - Hector And...
LightFields.jl: Fast 3D image reconstruction for VR applications - Hector And...LightFields.jl: Fast 3D image reconstruction for VR applications - Hector And...
LightFields.jl: Fast 3D image reconstruction for VR applications - Hector And...
 
Extracting relevant Metrics with Spectral Clustering - Evelyn Trautmann
Extracting relevant Metrics with Spectral Clustering - Evelyn TrautmannExtracting relevant Metrics with Spectral Clustering - Evelyn Trautmann
Extracting relevant Metrics with Spectral Clustering - Evelyn Trautmann
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

Do Your Homework! Writing tests for Data Science and Stochastic Code - David Waterman

  • 1. Do Your Homework! Writing Tests for Data Science and Natural Language Processing David Waterman github.com/drwaterman/pydatadctesting
  • 2. Agenda 1. Why test your code? 2. Our problem: text analysis, Natural Language Processing 3. Practical Implementation
  • 3. How Does Homework Work? Why give students homework problems and the matching solutions?
  • 4. If you know where you are going, you can tell if you are moving in the right direction
  • 5. Many of our daily tasks are like homework problems
  • 7. Why Test Your Code For others:  Reduce bugs  Improve feedback loops  Speeds up iteration  Makes code more reusable  Increases confidence in the system For you:  Earns trust and confidence in you and your work  Earns respect from devs and engineers (for whom it’s not optional)  Allows you to submit to open source projects  Probably required for acceptance into external code base
  • 8. Agenda 1. Why test your code? 2. Our problem: text analysis, Natural Language Processing 3. Practical Implementation
  • 11. Challenges • Per the long-term agreement, WABCO will supply its single-piston air disc brake (ADB) technology, MAXX, for the manufacturing of Hyundai’s new medium-duty trucks, which are expected to start from August 2019. • Timken has become the sole supplier of needle roller bearings to Volkswagen Transmission. • Dana Corp. has begun supplying Ford Motor Co. with its thermoplastic cylinder-head-cover modules for the automaker's 3.0- liter Duratec V-6 engine. The structure of text is domain specific. Regular people don’t talk like this:
  • 12. Our Approach: “Gold” Tests  Human reads the text  Identifies relationship from text  Puts relationship into machine-friendly format (JSON, YAML)  Writes a test for the relationship  Write and rewrite code to pass the test
  • 13. Agenda 1. Why test your code? 2. Our problem: text analysis, Natural Language Processing 3. Practical Implementation
  • 14. Recommendation: Pytest as your framework ➕ More Pythonic ➕ Easy to write fast - less boilerplate ➕ Can still run unittests, doctests, and nose ➕ Readable, pretty output (including HTML reports) ➕ Great documentation & guides ➖ It’s not a builtin
  • 15. What to Test  Expected output  Invalid input  Edge cases Data ModelsCode  Data is valid  Types are correct  Missing values are handled correctly  Format is correct  Produces expected results  Can be used to benchmark  Monitor for model drift
  • 17. Pytest features useful for Data Science ▪ Fixtures – For when you need something repeatedly over multiple tests (Loading test data, making a connection, preprocessing data) ▪ Skip and Xfail – For when you know what to test for but the code doesn’t pass yet ▪ Comparing images/plots – Available in matplotlib ▪ Benchmarking a model
  • 18. Some Nice Pytest Options Save your pytest command line arguments in a shell script pytest --html=test-logs/testreport.html --self- contained-html --cov=my_module --cov-report term- missing -r aPp test ▪ --html: Where to save the html test report ▪ --self-contained-html: Save everything in one html file (no external CSS, etc.) ▪ --cov=: What modules to include in the coverage report ▪ --cov-report term-missing: Terminal report w/ missing line numbers ▪ -r aPp: display test results summary at the end ▪ test: The location in which to run the tests
  • 19. CONCLUSION  Pytest is easy!  Start now  It will earn you trust and respect  It is possible to use it even if your code is stochastic Time for questions!