Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Test Driven Machine Learning
Test Driven Machine Learning

Test Driven Machine Learning: Control your machine learning algorithms using test-driven development to achieve quantifiable milestones

eBook
€15.29 €16.99
Paperback
€20.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Test Driven Machine Learning

Chapter 2. Perceptively Testing a Perceptron

Even for people comfortable with using them, neural networks can seem like a big black box. On top of that, the little bit of randomness within them just makes their inner workings that much more mysterious.

In this chapter, we're going to start exploring TDD-ing machine learning algorithms by building a very simple neural network using TDD. Then we will use this as an opportunity to more deeply understand how they work.

In this chapter, we will cover the following topics:

  • Building the simplest perceptron possible
  • Using a spreadsheet to develop simple use cases we can test to and reproduce
  • Using TDD to develop our first machine-learning algorithm
  • Testing with datasets

You will need some sort of spreadsheet program to follow along with this chapter. Microsoft Excel, Libre Office, or Google Docs are completely fine.

Getting started

A perceptron is a binary linear classifier. Like other supervised learning techniques, we can feed in rows of data along with the appropriate classification. After enough of these, the perceptron can begin to label new rows of data that have yet to be classified. Specifically, a perceptron works by adjusting a hyperplane to separate two groups of data as accurately as possible (with a linear classifier). Said a bit more simply, that means that we will have some data in a space and then perturb something like a line until it can act as an arbiter of what fits in one classification or another.

If you want to visualize it, think of 2D data being separated by a line like so:

Getting started

We'll be using TDD to develop the algorithm ourselves as an example of breaking very large problems down as much as possible. In later chapters, we will lean on third-party libraries for other implementations and focus on other ways to drive your machine learning forward in discrete steps.

It can be hard...

Summary

In this chapter, we iteratively developed the foundation of a neural network (a perceptron) using TDD by first developing concrete scenarios in a spreadsheet. Using a spreadsheet allowed us to get a handle on each of the different calculations that are required in a perceptron. We also saw that we can use TDD without needing to prove the mathematics. Instead we used TDD to implement the smallest amount of the mathematics that we needed to make our perceptron perform incrementally better. A side benefit to this is that you may have also developed a deeper understanding of what each aspect of the perceptron actually does.

In the next chapter, we will continue exploring mathematical solutions to machine learning. Specifically, we will develop a solution to maximize the money we can make when we have several different options of what to show customers and have no idea which is the most profitable.

Left arrow icon Right arrow icon

Description

Machine learning is the process of teaching machines to remember data patterns, using them to predict future outcomes, and offering choices that would appeal to individuals based on their past preferences. Machine learning is applicable to a lot of what you do every day. As a result, you can’t take forever to deliver your first iteration of software. Learning to build machine learning algorithms within a controlled test framework will speed up your time to deliver, quantify quality expectations with your clients, and enable rapid iteration and collaboration. This book will show you how to quantifiably test machine learning algorithms. The very different, foundational approach of this book starts every example algorithm with the simplest thing that could possibly work. With this approach, seasoned veterans will find simpler approaches to beginning a machine learning algorithm. You will learn how to iterate on these algorithms to enable rapid delivery and improve performance expectations. The book begins with an introduction to test driving machine learning and quantifying model quality. From there, you will test a neural network, predict values with regression, and build upon regression techniques with logistic regression. You will discover how to test different approaches to naïve bayes and compare them quantitatively, along with how to apply OOP (Object-Oriented Programming) and OOP patterns to test-driven code, leveraging SciKit-Learn. Finally, you will walk through the development of an algorithm which maximizes the expected value of profit for a marketing campaign by combining one of the classifiers covered with the multiple regression example in the book.

Who is this book for?

This book is intended for data technologists (scientists, analysts, or developers) with previous machine learning experience who are also comfortable reading code in Python. This book is ideal for those looking for a way to deliver results quickly to enable rapid iteration and improvement.

What you will learn

  • Get started with an introduction to testdriven development and familiarize yourself with how to apply these concepts to machine learning
  • Build and test a neural network deterministically, and learn to look for niche cases that cause odd model behaviour
  • Learn to use the multiarmed bandit algorithm to make optimal choices in the face of an enormous amount of uncertainty
  • Generate complex and simple random data to create a wide variety of test cases that can be codified into tests
  • Develop models iteratively, even when using a thirdparty library
  • Quantify model quality to enable collaboration and rapid iteration
  • Adopt simpler approaches to common machine learning algorithms
  • Use behaviourdriven development principles to articulate test intent

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 27, 2015
Length: 190 pages
Edition : 1st
Language : English
ISBN-13 : 9781784396367
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 27, 2015
Length: 190 pages
Edition : 1st
Language : English
ISBN-13 : 9781784396367
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 96.97
Python Machine Learning
€36.99
Practical Machine Learning
€38.99
Test Driven Machine Learning
€20.99
Total 96.97 Stars icon

Table of Contents

10 Chapters
1. Introducing Test-Driven Machine Learning Chevron down icon Chevron up icon
2. Perceptively Testing a Perceptron Chevron down icon Chevron up icon
3. Exploring the Unknown with Multi-armed Bandits Chevron down icon Chevron up icon
4. Predicting Values with Regression Chevron down icon Chevron up icon
5. Making Decisions Black and White with Logistic Regression Chevron down icon Chevron up icon
6. You're So Naïve, Bayes Chevron down icon Chevron up icon
7. Optimizing by Choosing a New Algorithm Chevron down icon Chevron up icon
8. Exploring scikit-learn Test First Chevron down icon Chevron up icon
9. Bringing It All Together Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(3 Ratings)
5 star 33.3%
4 star 0%
3 star 0%
2 star 66.7%
1 star 0%
Julian Cook Jan 27, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a totally out-of-left-field book on machine learning. Not only is it novel, but I think the ideas will become more important over time, as more models move into production scenarios and need to be iteratively changed and improved, whilst not _breaking_ the model that already works.The main idea, as you may have guessed, is to change the model development process from exploring data - followed by trying different models, to a more formal approach of wrapping your data in a test framework and then proceeding to develop the model(s).The initial model (or failing test) can just be a random guesser, after this you continually re-factor your code to improve on the random result or previous iteration of the model (at which point the test passes).This will seem weird to a statistician, who would insist of emphasizing significance tests or (at least) looking at an ROC curve, which this book also does. The point made by the author is that once you enter the real world of running prediction models in production, you need to move to a process of iterative development, where you have some formal guarantee that the new model is better than the last and that you have not somehow fooled yourself into using something that is not much better than random.There are a couple of drawbacks to the whole approach though. The first is the pain of setting up the tests in the first place, especially when you have a lot of data. I thought about setting up some synthetic data to test a new model, but it was honestly quicker to step through an example with the real data to figure out whether the code was working or not.The other issue is with interactive environments, like R and ipython, you can write your code in short sections at the console, then test each section, or model iteration, as you go. This is very efficient and doesn't necessarily work with a 'think up the tests before you do anything' approach.Even if you don't like the ideas, the book itself is still a very good way to approach statistical model development and should be widely read, especially in organizations where multiple people might touch the ML code.
Amazon Verified review Amazon
Bill Jan 17, 2017
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
I have no disagreements whatsoever with the main point of this book--creating a comprehensive suite of tests is a critical step of building quality ML tools. However, when describing this process for various ML models, the tests described by the author are incredibly trivial. If you know nothing about building ML models, then this book could be valuable for you. If you are even a moderately experienced practitioner, this book is a waste of your time. In my opinion, the entire text could be boiled down to the following 3 sentences1. You should have tests for your ML tools2. You should have tests to make sure your tools perform as you expect they would, at a very basic level (as you should do with any code you write)3. You should have tests to make sure your tools meet appropriate performance benchmarks on a handful of appropriate toy problemsNothing proposed by the author is a bad idea, it's just trivial. I learned nothing.
Amazon Verified review Amazon
Martin Aug 03, 2020
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
This book attempts to introduce test-driven development to data scientists.Because of this I had hoped to find answers to questions specific to machinelearning which other books about test-driven development in general do notconsider. My questions (in particular, how to deal with statistical uncertaintyin tests and how to keep the test suite fast) were touched superficially at best.The book could have been a real gem, sitting at the sweet spot where the topicstest-driven development and machine learning intersect. Instead, it tries to bean introductory text in both fields and falls short. There are better introductorybooks specifically for either topic.The quality of the text and code examples is low. The text contains ambiguousformulations, discrepancies, and topics that are introduced but not furtherdiscussed. The code examples are carelessly formatted, contain obvious copy&pastemistakes, and syntax errors. The occasional mistake in a technical book is usuallyno big deal, but their sheer amount made reading this book an annoying experience.All that said, this book could be interesting for a reader who has had priorexposure to the topics being covered and is committed to work through them indetail to elaborate on what the examples show and what is left unsaid.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.

Modal Close icon
Modal Close icon