Leanpub Header

Skip to main content

Clean Machine Learning Code

Isn't it weird that ML software is super important, yet crazy fragile? If ML software is valuable but so unstable, how come data scientists and ML engineers are rarely trained on the basics of building profitable software systems? What to do about it?

Minimum price

$14.99

$24.99

You pay

$24.99

Author earns

$17.99

Cause gets

$2.00
$

...Or Buy With Credits!

You can get credits monthly with a Reader Membership
PDF
EPUB
WEB
251
Readers
220
Pages
About

About

About the Book

It is super clear that people involved with ML/DS type of work, are really really smart.

Individuals in this field know about statistics, machine learning, academic research, data manipulation, and they excel at reasoning, and logical thinking beyond belief.

However, as these talented individuals transition to working with software engineers and product managers, on live products, they notice a deep sense of instability.

The reality is that software is an intensely creative activity but produces tremendously fragile artifacts.

Now, if traditional software products are fragile and can be taken down by flipping a single IF condition at the right place, one can only imagine the fragility of ML software.

How can something so valuable for company profits, and society as a whole be so fragile? And how can this fragility be so unexplored by ML practitioners?

Not into reading? Checkout the companion 5 hours video course + book bundle:

https://www.udemy.com/course/clean-machine-learning-code

If you read this far, you are well aware that there is no useful Machine Learning (ML) without extensive software. But building complex software comes with many challenges.

ML software is explicitly full of needless complexity and repetition. Thick opacity, rigidity, and viscosity of design magnify this brew of complexity. With these issues, ML failures are growing in importance at an unprecedented pace.

It does not have to be this way.

As a global data science community, the autonomous systems we build can be costly, dangerous, and even deadly. Adding to the problem is the inexperienced workforce of this 5 to 10 years old craft. As of 2019-2020, 40% of data scientists in the USA have less than 5 years of experience.

The software industry is experiencing a boom in ML development and usage. This is not unlike previous software engineering booms in the early 2000s. The current boom manifests itself with a menagerie of constructs, abstractions, frameworks, and workflows. This multitude of integration challenges remind us of old and classical software problems. Some of the issues present in the ML software engineering practice are new. But the majority of the software engineering concerns have a historical smell. Going back to the early days of software engineering can help with today’s ML problems.

For us, ML engineers, it is time to stop reinventing the wheel, making the same old mistakes, and start using the decades of successful software engineering practices by replacing “Software” with “Machine Learning Software”.

This book can help with that.

Author

About the Author

Moussa Taifi

Data science platform architect focused on data science productivity, reliability, performance, and cost.

Working on designing and implementing large scale AI products through data collection, analysis, and warehousing.

Passionate about building scalable machine learning pipeline architectures with high business impact.

Aspiring author.

Site:

moussataifi.com

Medium:

https://medium.com/@farmi

Contents

Table of Contents

Chapter 1 - Clean Machine Learning Code Fundamentals

  1. The Flowchart: Why You Need This Book
  2. The Future of Machine Learning Code
  3. Bad Machine Learning Code
  4. The TCO of a Predictive Service Mess
  5. Rebuild the ML Pipelines from Scratch
  6. Ideal vs. Real Machine Learning Workflows
  7. Taking Responsibility for ML Code Rot
  8. Overfitting to Deadlines
  9. The Art of Feature Engineering Your Code
  10. What Is Clean Machine Learning Code?
  11. Inference vs Training of Source Code
  12. Active Reinforcement Learning for Source Code
  13. Transfer Learning and the Origins of CMLC
  14. Conclusion
  15. References

Chapter 2 - Optimizing Names

  1. Introduction
  2. The Objective Function of Names
  3. Avoid Mislabeled Labels
  4. Avoid Noisy Labels
  5. Make Siri Say it
  6. Make it Greppable
  7. Avoid Name Embeddings
  8. Avoid Semantic Name Maps
  9. Part-of-Speech Tagging
  10. CumSum vs. CummulativeSum
  11. Naming Consistency
  12. Avoid Paronomasia
  13. Use Technical Names
  14. Use Domain Names
  15. Use Clustering for Context
  16. The Scope Length Guidelines
  17. Conclusion
  18. References

Chapter 3 - Optimizing Functions

  1. Small is Beautiful
  2. 3, 4, maybe 5 lines max!
  3. Hierarchical functions
  4. Single Objective Function
  5. Bagging and Function Ensembles
  6. Single Abstraction Level
  7. Function Arguments
  8. Have No Collateral Damage
  9. Side-effects in Feature Engineering Pipelines
  10. Functional Programming 101
  11. Make Temporal Couplings Explicit
  12. Grokking Commands vs. Queries
  13. Handling Exceptions
  14. Single Entry, Single Exit
  15. A Method to the Madness
  16. Conclusion
  17. References

Chapter 4 - Style

  1. Comments
  2. Don’t Hide Bad Code Behind Comments
  3. Let Code Explain Itself
  4. Useful comments
  5. Useless Comments
  6. Formatting Goals
  7. Python File Size and Notebook Size
  8. PEP-8 When You Can
  9. Minimize Conceptual Distances
  10. One last thing about one-liners
  11. Conclusion
  12. References

Chapter 5 - Clean Machine Learning Classes

  1. I Know Classes in Python Why Are You Wasting My Time?
  2. Goals for ML Class Design
  3. S.O.L.I.D Design Principles for ML Classes
  4. Small Cohesive Classes: The Single Responsibility Principle
  5. Organizing for Change: The Open-Closed Principle
  6. Maintaining Contracts: The Liskov Substitution Principle
  7. Isolating from Change I: The Interface Substitution Principle
  8. Isolating from Change II: The Dependency Inversion Principle
  9. Conclusion
  10. References

Chapter 6 - ML Software Architecture

  1. The purpose of ML Software Architecture
  2. Third-party packages are NOT an Architecture
  3. Architecture is about Usage
  4. Avoiding Chaos using Architecture
  5. Frameworks and Harems
  6. Defining ML Use-cases
  7. Separating High Level Policy from Low Level Implementation
  8. The Clean Architecture in One Picture
  9. Related Architecture Names and Concepts
  10. Friction and Boundary Conditions
  11. Taming the Recsys Beast
  12. Clean ML Architecture
  13. Re-architecting the ML Pipeline
  14. Living with a Main
  15. Conclusion
  16. References

Chapter 7 - Test Driven Machine Learning

  1. Making Your Life Harder in the Short Term
  2. 60 Minutes to Save Lives
  3. Does ML Code Rot?
  4. Tests Let You Clean Your Code
  5. Self-testing ML Code
  6. What is this TDD you are talking about?
  7. Which ML Code Tests Do You Need?
  8. GridSearch for ML Code Tests
  9. Unit Tests
  10. Integration Tests
  11. Component Tests
  12. End-to-End Tests
  13. Threshold Tests
  14. Regression Tests
  15. Test Implementation techniques
  16. Test Doubles
  17. Cost Effective Tests
  18. Property-based testing
  19. Exterminate Non-Determinism in ML Tests
  20. The Basics
  21. Social Distancing
  22. Isolation And Co-mingling
  23. The Brave New Async World
  24. Working around Remote Services
  25. Clocks
  26. It Only Fails During Business Hours
  27. Test Coverage
  28. What To Do If You Are Giving Up on Testing
  29. Testing Expeditions a.k.a. Exploratory Testing
  30. Synthetic Monitoring
  31. Feature Toggles
  32. Approaches From Around The ML Community
  33. Software 2.0
  34. The ML Test Score
  35. ML Score Checklist Visualized
  36. Coding Habits for Data Scientists
  37. Continuous Delivery
  38. Conclusions
  39. References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

Causes

Causes Supported

Tree-Nation

Tree-Nation Tree-Nation

You reforest the world

https://tree-nation.com
Tree-Nation is the largest reforestation platform enabling citizens and companies to plant trees around the world.
Tree-Nation’s mission is to reforest the world. The organisation offers people the possibility to select from over 300 different tree species which can be planted in 50 different reforestation projects located in 6 different continents. In every project, the species are carefully selected according to the specific benefits they bring for the environment and to the local population. Each tree planted on the Tree-Nation platform is assigned its own unique URL, which means the species, the location, the plantation project information and the CO2 compensation values can be tracked throughout the lifetime of the tree. Since its inception in 2006, more than 130,000 users and more than 2,200 companies have planted 5 million trees using its platform.

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub