Cover: Machine Learning For Dummies, 2nd Edition by John Paul Mueller

Title Page

Machine Learning For Dummies®

To view this book's Cheat Sheet, simply go to and search for “Machine Learning For Dummies Cheat Sheet” in the Search box.


The term machine learning has all sorts of meanings attached to it today, especially after Hollywood (and other movie studios) have gotten into the picture. Films such as Ex Machina have tantalized the imaginations of moviegoers the world over and made machine learning into all sorts of things that it really isn’t. Of course, most of us have to live in the real world, where machine learning actually does perform an incredible array of tasks that have nothing to do with androids that can pass the Turing Test (fooling their makers into believing they’re human). Machine Learning For Dummies, 2nd Edition gives you a view of machine learning in the real world and exposes you to the amazing feats you really can perform using this technology.

Even though the tasks that you perform using machine learning may seem a bit mundane when compared to the movie version, by the time you finish this book, you realize that these mundane tasks have the power to impact the lives of everyone on the planet in nearly every aspect of their daily lives. In short, machine learning is an incredible technology — just not in the way that some people have imagined.

This second edition of the book contains a significant number of changes, not the least of which is that it’s using pure Python code for the examples now upon request from our readers. You can still download R versions of every example, which is actually better than before when only some of the examples were available in R. In addition, the book contains new topics, including an entire chapter that discusses machine learning ethics.

About This Book

Machines and humans learn in entirely different ways, which is why the first part of this book is essential to your understanding of machine learning. Machines perform routine tasks at incredible speeds, but still require humans to do the actual thinking.

The second part of this book is about getting your system set up to use the various Python coding examples. The two setups work for desktop systems using Windows, Mac OS, or Linux, or mobile devices that have access to a Google Colab compatible browser.

Tip If you’re using R, you’ll find a README file in the R download file that contains instructions for configuring your R Anaconda environment.

The third part of the book discusses math basics with regard to machine learning requirements. It prepares you to perform math tasks associated with algorithms used in machine learning to make either predictions or classifications from your data.

The fourth part of the book helps you discover what to do about data that isn’t quite up to par. This part is also where you start learning about similarity and working with linear models. The most advanced chapter tells you how to work with ensembles of learners to perform tasks that might not otherwise be reasonable to complete.

The fifth part of the book is about practical application of machine learning techniques. You see how to do things like classify images, work with opinions and sentiments, and recommend products and movies.

The last part of the book contains helpful information to enhance your machine learning experience. This part of the book also contains a chapter specifically oriented toward ethical data use.

To make absorbing the concepts easy, this book uses the following conventions:

  • Text that you’re meant to type just as it appears in the book is in bold. The exception is when you’re working through a step list: Because each step is bold, the text to type is not bold.
  • Web addresses and programming code appear in monofont. If you're reading a digital version of this book on a device connected to the Internet, you can click or tap the web address to visit that website, like this:
  • When you need to type command sequences, you see them separated by a special arrow, like this: File ⇒   New File. In this example, you go to the File menu first and then select the New File entry on that menu.
  • When you see words in italics as part of a typing sequence, you need to replace that value with something that works for you. For example, if you see “Type Your Name and press Enter,” you need to replace Your Name with your actual name.

Foolish Assumptions

This book is designed for novice and professional alike. You can either read this book from cover to cover or look up topics and treat the book as a reference guide. However, we’ve made some assumptions about your level of knowledge when we put the book together. You should already know how to use your device and work with the operating system that supports it. You also know how to perform tasks like downloading files and installing applications. You can interact with Internet well enough to locate the resources you need to work with the book. You know how to work with archives, such as the .zip file format. Finally, a basic knowledge of math is helpful.

Icons Used in This Book

As you read this book, you see icons in the margins that indicate material of interest. This section briefly describes each icon.

Tip The tips in this book are time-saving techniques or pointers to resources that you should try so that you can get the maximum benefit from machine learning.

Warning You should avoid doing anything that's marked with a Warning icon. Otherwise, you might find that your application fails to work as expected, you get incorrect answers from seemingly bulletproof code, or (in the worst-case scenario) you lose data.

Technical stuff Whenever you see this icon, think advanced tip or technique. Skip these bits of information whenever you like.

Remember This text usually contains an essential process or a bit of information that you must know to perform machine learning tasks successfully.

Beyond the Book

If you want to email us, please do! Make sure you send your book-specific requests to: We want to ensure that your book experience is the best one possible. The blog entries at contain a wealth of additional information about this book. You can check out John’s website at You can also access other cool materials:

  • Cheat Sheet: A cheat sheet provides you with some special notes on things you can do with machine learning that not every other scientist knows. You can find the Cheat Sheet for this book at Type Machine Learning For Dummies in the Search box and click the Cheat Sheets option that appears.
  • Errata: You can find errata by entering this book’s title in the Search box at, which takes you to this book’s page. In addition to errata, check out the blog posts with answers to reader questions and demonstrations of useful book-related techniques at
  • Companion files: The source code is available for download. All the book examples tell you precisely which example project to use. You can find these files at this book’s page at Just enter the book title in the Search box, click Books on the page that appears, click the book’s title, and scroll down the page to Downloads.

    We’ve also had trouble with the datasets used in the previous edition of this book. Sometimes the datasets change or might become unavailable. Given that you likely don’t want to download a large dataset unless you’re interested in that example, we’ve made the non-toy datasets (those available with a package) available at You don’t actually need to download them, though; the example code will perform that task for you automatically when you run it.

Where to Go from Here

Most people will want to start this book from the beginning, because it contains a good deal of information about how the real world view of machine learning differs from what movies might tell you. However, if you already have a first grounding in the reality of machine learning, you can always skip to the next part of the book.

Chapter 4 is where you want to go if you want to use a desktop setup, while Chapter 6 is helpful when you want to use a mobile device. Your preexisting setup may not work with the book’s examples because you might have different versions of the various products. It’s essential that you use the correct product versions to ensure success. Even if you choose to go with your own setup, consider reviewing Chapter 5 unless you’re an expert Python coder already.

If you’re already an expert with Python and know how machine learning works, you could always skip to Chapter 7. Starting at Chapter 7 will help you get into the examples quickly so that you spend less time with basics and more time with intermediate machine learning tasks. You can always go back and review the previous materials as needed.

Part 1

Introducing How Machines Learn


Discovering how AI really works and what it can do for you

Considering what the term big data means

Understanding the role of statistics in machine learning

Defining where machine learning will take society in the future