Thoughtful Machine Learning
by Matthew Kirk
Copyright 2015 All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
- Editors: Mike Loukides and Ann Spencer
- Production Editor: Melanie Yarbrough
- Copyeditor: Rachel Monaghan
- Proofreader: Jasmine Kwityn
- Indexer: Ellen Troutman-Zaig
- Interior Designer: David Futato
- Cover Designer: Ellie Volkhausen
- Illustrator: Rebecca Demarest
- October 2014: First Edition
Revision History for the First Edition
- 2014-09-23: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781449374068 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. Thoughtful Machine Learning, the cover image of a Eurasian eagle-owl, and related trade dress are trademarks of OReilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-449-37406-8
[LSI]
Preface
This book is about approaching tough problems. Machine learning is an amazing application of computation because it tackles problems that are straight out of science fiction. These algorithms can solve voice recognition, mapping, recommendations, and disease detection. The applications are endless, which is what makes machine learning so fascinating.
This flexibility is also what makes machine learning daunting. It can solve many problems, but how do we know whether were solving the right problem, or actually solving it in the first place? On top of that sadly much of academic coding standards are lax.
Up until this moment there hasnt been a lot of talk about writing good quality code when it comes to machine learning and that is unfortunate. The ability for us to disseminate an idea across an entire industry is based on our ability to communicate it effectively. And if we write bad code, its doubtful a lot of people will listen.
Writing this book is my answer to that problem. Teaching machine learning to people in an easier to approach way. This subject is tough, and its compounded by hard to read code, or ancient C implementations that make zero sense.
While a lot of people will be confused as to why this book is written in Ruby instead of Python, its because writing tests in Ruby is a beautiful way of explaining your code. The entire book taking this test driven approach is about communication, and communicating the beautiful world of Machine Learning.
What to Expect from This Book
This book is not an exhaustive machine learning resource. For that Id highly recommend Peter Flachs Machine Learning: The Art and Science of Algorithms that Make Sense of Data (Cambridge University Press) or if you are mathematically inclined, Tom Mitchells Machine Learning series is top notch. There are also great tidbits from Artificial Intelligence: A Modern Approach, Third Edition by Stuart Russell and Peter Norvig (Prentice Hall).
After reading this book you will not have a PhD in machine learning, but I hope to give you enough information to get working on real problems using data with machine learning. You should expect lots of examples of the approach to problems as well as how to use them at a fundamental level.
You should also find yourself learning how to approach problems that are more fuzzy than the normal unit testing scenario.
How to Read This Book
The best way to read this book is to find examples that excite you. Each chapter aims to be fairly contained, although at times they wont be. My goal for this book is not to be purely theoretical but to introduce you to some examples of problems that machine learning can solve for you as well as some worked out samples of how Id approach working with data.
In most of the chapters, I try to introduce some business cases in the beginning then delve into a worked out example toward the end. This book is intended as a short read because I want you to focus on working with the code and thinking about these problems instead of getting steeped up in theory.
Who This Book Is For
There are three main people I have written the book for: the developer, the CTO, and the business analyst.
The developer already knows how to write code and is interested in learning more about the exciting world of machine learning. She has some background in working out problems in a computational context and may or may not write Ruby. The book is primarily focused on this persona but there is also the CTO and the business analyst.
The CTO is someone who really wants to know how to utilize machine learning to improve his company. He might have heard of K-Means, K-Nearest Neighbors but hasnt quite figured out how its applicable to him. The business analyst is similar except that she is less technically inclined. These two personas I wrote the start of every chapter for.
How to Contact Me
I love receiving emails from people who either liked a presentation I gave or need help with a problem. Feel free to email me at matt@matthewkirk.com. And to cement this, I will gladly buy you a cup of coffee if you come to the Seattle area (and our schedules permit).
If youd like to view any of the code in this book, its free at GitHub.
Conventions Used in This Book
The following typographical conventions are used in this book:
ItalicIndicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.
Tip
This element signifies a tip or suggestion.
Note
This element signifies a general note.
Warning
This element indicates a warning or caution.
Important
This element indicates a warning of significant importance; read carefully.
Using Code Examples
Supplemental material (code examples, exercises, etc.) is available for download at http://github.com/thoughtfulml.
This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless youre reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from OReilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your products documentation does require permission.