Data Science from Scratch
by Joel Grus
Copyright 2019 Joel Grus. 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://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
- Editor: Michele Cronin
- Production Editor: Deborah Baker
- Copy Editor: Rachel Monaghan
- Proofreader: Rachel Head
- Indexer: Judy McConville
- Interior Designer: David Futato
- Cover Designer: Karen Montgomery
- Illustrator: Rebecca Demarest
- April 2015: First Edition
- May 2019: Second Edition
Revision History for the Second Edition
- 2019-04-10: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781492041139 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. Data Science from Scratch, Second Edition, the cover image of a rock ptarmigan, 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-492-04113-9
[LSI]
Preface to the Second Edition
I am exceptionally proud of the first edition of Data Science from Scratch.It turned out very much the book I wanted it to be. But severalyears of developments in data science, of progress in the Python ecosystem,and of personal growth as a developer and educator have changed what Ithink a first book in data science should look like.
In life, there are no do-overs. In writing, however, there are second editions.
Accordingly, Ive rewritten all the code and examples using Python 3.6(and many of its newly introduced features, like type annotations). Ive woven into the book an emphasis on writing clean code. Ive replaced some ofthe first editions toy examples with more realistic ones using realdatasets. Ive added new material on topics such as deep learning, statistics, andnatural language processing, corresponding to things that todays data scientistsare likely to be working with. (Ive also removed some material that seems less relevant.)And Ive gone over the book with a fine-toothed comb, fixing bugs, rewriting explanations thatare less clear than they could be, and freshening up some of the jokes.
The first edition was a great book, and this edition is even better. Enjoy!
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.
Using Code Examples
Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/joelgrus/data-science-from-scratch.
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.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: Data Science from Scratch, Second Edition, by Joel Grus (OReilly). Copyright 2019 Joel Grus, 978-1-492-04113-9.
If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .
OReilly Online Learning
Note
For almost 40 years, OReilly Media has provided technology and business training, knowledge, and insight to help companies succeed.
Our unique network of experts and innovators share their knowledge and expertise through books, articles, conferences, and our online learning platform. OReillys online learning platform gives you on-demand access to live training courses, in-depth learning paths, interactive coding environments, and a vast collection of text and video from OReilly and 200+ other publishers. For more information, please visit http://oreilly.com.
How to Contact Us
Please address comments and questions concerning this book to the publisher:
- OReilly Media, Inc.
- 1005 Gravenstein Highway North
- Sebastopol, CA 95472
- 800-998-9938 (in the United States or Canada)
- 707-829-0515 (international or local)
- 707-829-0104 (fax)
We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://bit.ly/data-science-from-scratch-2e.
To comment or ask technical questions about this book, send email to .
For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia
Acknowledgments
First, I would like to thank Mike Loukides for accepting my proposal for this book (and for insisting that I pare it down to a reasonable size). It would have been very easy for him to say, Whos this person who keeps emailing me sample chapters, and how do I get him to go away? Im grateful he didnt. Id also like to thank my editors, Michele Cronin and Marie Beaugureau, for guiding me through the publishing process and getting the book in a much better state than I ever would have gotten it on my own.
I couldnt have written this book if Id never learned data science, and I probably wouldnt have learned data science if not for the influence of Dave Hsu, Igor Tatarinov, John Rauser, and the rest of the Farecast gang. (So long ago that it wasnt even called data science at the time!) The good folks at Coursera and DataTau deserve a lot of credit, too.