Master the art of machine learning with Python and build effective machine learning systems with this intensive hands-on guide **Overview** * Master Machine Learning using a broad set of Python libraries and start building your own Python-based ML systems. * Covers classification, regression, feature engineering, and much more guided by practical examples. * A scenario-based tutorial to get into the right mind-set of a machine learner (data exploration) and successfully implement this in your new or existing projects. **In Detail** Machine learning, the field of building systems that learn from data, is exploding on the Web and elsewhere. Python is a wonderful language in which to develop machine learning applications. As a dynamic language, it allows for fast exploration and experimentation and an increasing number of machine learning libraries are developed for Python. Building Machine Learning system with Python shows you exactly how to find patterns through raw data. The book starts by brushing up on your Python ML knowledge and introducing libraries, and then moves on to more serious projects on datasets, Modelling, Recommendations, improving recommendations through examples and sailing through sound and image processing in detail. Using open-source tools and libraries, readers will learn how to apply methods to text, images, and sounds. You will also learn how to evaluate, compare, and choose machine learning techniques Written for Python programmers, Building Machine Learning Systems with Python teaches you how to use open-source libraries to solve real problems with machine learning. The book is based on real-world examples that the user can build on. Readers will learn how to write programs that classify the quality of StackOverflow answers or whether a music file is Jazz or Metal. They will learn regression, which is demonstrated on how to recommend movies to users. Advanced topics such as topic modeling (finding a text’s most important topics), basket analysis, and cloud computing are covered as well as many other interesting aspects. Building Machine Learning Systems with Python will give you the tools and understanding required to build your own systems, which are tailored to solve your problems. **What you will learn from this book** * Build a classification system that can be applied to text, images, or sounds * Use scikit-learn, a Python open-source library for machine learning * Explore the mahotas library for image processing and computer vision * Build a topic model of the whole of Wikipedia * Get to grips with recommendations using the basket analysis * Use the Jug package for data analysis * Employ Amazon Web Services to run analyses on the cloud * Recommend products to users based on past purchases **Approach** A practical, scenario-based tutorial, this book will help you get to grips with machine learning with Python and start building your own machine learning projects. By the end of the book you will have learnt critical aspects of machine learning Python projects and experienced the power of ML-based systems by actually working on them. Cover 1 Copyright 3 Credits 4 About the Authors 5 About the Reviewers 7 www.PacktPub.com 9 Table of Contents 10 Preface 16 Chapter 1: Getting Started with Python Machine Learning 22 Machine learning and Python – the dream team 23 What the book will teach you (and what it will not) 24 What to do when you are stuck 25 Getting started 26 Introduction to NumPy, SciPy, and Matplotlib 27 Installing Python 27 Chewing data efficiently with NumPy and intelligently with SciPy 27 Learning NumPy 28 Indexing 30 Handling non-existing values 30 Comparing runtime behaviors 31 Learning SciPy 32 Our first (tiny) machine learning application 34 Reading in the data 34 Preprocessing and cleaning the data 35 Choosing the right model and learning algorithm 37 Before building our first model 37 Starting with a simple straight line 37 Towards some advanced stuff 39 Stepping back to go forward – another look at our data 41 Training and testing 43 Answering our initial question 45 Summary 46 Chapter 2: Learning How to Classify with Real-world Examples 48 The Iris dataset 48 The first step is visualization 49 Building our first classification model 50 Evaluation – holding out data and cross-validation 53 Building more complex classifiers 55 A more complex dataset and a more complex classifier 56 Learning about the Seeds dataset 57 Features and feature engineering 58 Nearest neighbor classification 59 Binary and multiclass classification 62 Summary 63 Chapter 3: Clustering – Finding Related Posts 64 Measuring the relatedness of posts 65 How not to do it 65 How to do it 66 Preprocessing – similarity measured as similar number of common words 66 Converting raw text into a bag-of-words 67 Counting words 68 Normalizing the word count vectors 71 Removing less important words 71 Stemming 72 Installing and using NLTK 73 Extending the vectorizer with NLTK's stemmer 74 Stop words on steroids 75 Our achievements and goals 76 Clustering 77 KMeans 78 Getting test data to evaluate our ideas on 80 Clustering posts 82 Solving our initial challenge 83 Another look at noise 86 Tweaking the parameters 87 Summary 88 Chapter 4: Topic Modeling 90 Latent Dirichlet allocation (LDA) 90 Building a topic model 91 Comparing similarity in topic space 95 Modeling the whole of Wikipedia 98 Choosing the number of topics 101 Summary 102 Chapter 5: Classification – Detecting Poor Answers 104 Sketching our roadmap 105 Learning to classify classy answers 105 Tuning the instance 105 Tuning the classifier 105 Fetching the data 106 Slimming the data down to chewable chunks 107 Preselection and processing of attributes 108 Defining what is a good answer 109 Creating our first classifier 110 Starting with the k-nearest neighbor (kNN) algorithm 110 Engineering the features 111 Training the classifier 112 Measuring the classifier's performance 112 Designing more features 113 Deciding how to improve 116 Bias-variance and its trade-off 117 Fixing high bias 117 Fixing high variance 118 High bias or low bias 118 Using logistic regression 120 A bit of math with a small example 121 Applying logistic regression to our postclassification problem 123 Looking behind accuracy – precision and recall 125 Slimming the classifier 129 Ship it! 130 Summary 130 Chapter 6: Classification II – Sentiment Analysis 132 Sketching our roadmap 132 Fetching the Twitter data 133 Introducing the Naive Bayes classifier 133 Getting to know the Bayes theorem 134 Being naive 135 Using Naive Bayes to classify 136 Accounting for unseen words and other oddities 139 Accounting for arithmetic underflows 140 Creating our first classifier and tuning it 142 Solving an easy problem first 143 Using all the classes 145 Tuning the classifier's parameters 147 Cleaning tweets 151 Taking the word types into account 153 Determining the word types 154 Successfully cheating using SentiWordNet 156 Our first estimator 158 Putting everything together 160 Summary 161 Chapter 7: Regression – Recommendations 162 Predicting house prices with regression 162 Multidimensional regression 166 Cross-validation for regression 166 Penalized regression 168 L1 and L2 penalties 168 Using Lasso or Elastic nets in scikit-learn 169 P greater than N scenarios 170 An example based on text 171 Setting hyperparameters in a smart way 173 Rating prediction and recommendations 174 Summary 178 Chapter 8: Regression – Recommendations Improved 180 Improved recommendations 180 Using the binary matrix of recommendations 181 Looking at the movie neighbors 183 Combining multiple methods 184 Basket analysis 187 Obtaining useful predictions 188 Analyzing supermarket shopping baskets 188 Association rule mining 191 More advanced basket analysis 193 Summary 194 Chapter 9: Classification III – Music Genre Classification 196 Sketching our roadmap 196 Fetching the music data 197 Converting into a wave format 197 Looking at music 197 Decomposing music into sine wave components 199 Using FFT to build our first classifier 201 Increasing experimentation agility 201 Training the classifier 202 Using the confusion matrix to measure accuracy in multiclass problems 203 An alternate way to measure classifier performance using receiver operator characteristic (ROC) 205 Improving classification performance with Mel Frequency Cepstral Coefficients 208 Summary 212 Chapter 10: Computer Vision – Pattern Recognition 214 Introducing image processing 214 Loading and displaying images 215 Basic image processing 216 Thresholding 217 Gaussian blurring 220 Filtering for different effects 222 Adding salt and pepper noise 222 Putting the center in focus 223 Pattern recognition 225 Computing features from images 226 Writing your own features 227 Classifying a harder dataset 230 Local feature representations 231 Summary 234 Chapter 11: Dimensionality Reduction 236 Sketching our roadmap 237 Selecting features 237 Detecting redundant features using filters 238 Correlation 238 Mutual information 240 Asking the model about the features using wrappers 245 Other feature selection methods 247 Feature extraction 248 About principal component analysis (PCA) 248 Sketching PCA 249 Applying PCA 249 Limitations of PCA and how LDA can help 251 Multidimensional scaling (MDS) 252 Summary 255 Chapter 12: Big(ger) Data 256 Learning about big data 256 Using jug to break up your pipeline into tasks 257 About tasks 257 Reusing partial results 260 Looking under the hood 261 Using jug for data analysis 261 Using Amazon Web Services (AWS) 263 Creating your first machines 265 Installing Python packages on Amazon Linux 268 Running jug on our cloud machine 269 Automating the generation of clusters with starcluster 270 Summary 274 Appendix: Where to Learn More about Machine Learning 276 Online courses 276 Books 276 Q&A sites 277 Blogs 277 Data sources 278 Getting competitive 278 What was left out 279 Summary 279 Index 280 Master the art of machine learning with Python and build effective machine learning systems with this intensive hands-on guide Overview Master Machine Learning using a broad set of Python libraries and start building your own Python-based ML systems. Covers classification, regression, feature engineering, and much more guided by practical examples. A scenario-based tutorial to get into the right mind-set of a machine learner (data exploration) and successfully implement this in your new or existing projects. In Detail Machine learning, the field of building systems that learn from data, is exploding on the Web and elsewhere. Python is a wonderful language in which to develop machine learning applications. As a dynamic language, it allows for fast exploration and experimentation and an increasing number of machine learning libraries are developed for Python. Building Machine Learning system with Python shows you exactly how to find patterns through raw data. The book starts by brushing up on your Python ML knowledge and introducing libraries, and then moves on to more serious projects on datasets, Modelling, Recommendations, improving recommendations through examples and sailing through sound and image processing in detail. Using open-source tools and libraries, readers will learn how to apply methods to text, images, and sounds. You will also learn how to evaluate, compare, and choose machine learning techniques Written for Python programmers, Building Machine Learning Systems with Python teaches you how to use open-source libraries to solve real problems with machine learning. The book is based on real-world examples that the user can build on. Readers will learn how to write programs that classify the quality of StackOverflow answers or whether a music file is Jazz or Metal. They will learn regression, which is demonstrated on how to recommend movies to users. Advanced topics such as topic modeling (finding a text’s most important topics), basket analysis, and cloud computing are covered as well as many other interesting aspects. Building Machine Learning Systems with Python will give you the tools and understanding required to build your own systems, which are tailored to solve your problems. What you will learn from this book Build a classification system that can be applied to text, images, or sounds Use scikit-learn, a Python open-source library for machine learning Explore the mahotas library for image processing and computer vision Build a topic model of the whole of Wikipedia Get to grips with recommendations using the basket analysis Use the Jug package for data analysis Employ Amazon Web Services to run analyses on the cloud Recommend products to users based on past purchases Approach A practical, scenario-based tutorial, this book will help you get to grips with machine learning with Python and start building your own machine learning projects. By the end of the book you will have learnt critical aspects of machine learning Python projects and experienced the power of ML-based systems by actually working on them.
In Detail
Machine learning, the field of building systems that learn from data, is exploding on the Web and elsewhere. Python is a wonderful language in which to develop machine learning applications. As a dynamic language, it allows for fast exploration and experimentation and an increasing number of machine learning libraries are developed for Python.
Building Machine Learning system with Python shows you exactly how to find patterns through raw data. The book starts by brushing up on your Python ML knowledge and introducing libraries, and then moves on to more serious projects on datasets, Modelling, Recommendations, improving recommendations through examples and sailing through sound and image processing in detail.
Using open-source tools and libraries, readers will learn how to apply methods to text, images, and sounds. You will also learn how to evaluate, compare, and choose machine learning techniques.
Written for Python programmers, Building Machine Learning Systems with Python teaches you how to use open-source libraries to solve real problems with machine learning. The book is based on real-world examples that the user can build on.
Readers will learn how to write programs that classify the quality of StackOverflow answers or whether a music file is Jazz or Metal. They will learn regression, which is demonstrated on how to recommend movies to users. Advanced topics such as topic modeling (finding a text's most important topics), basket analysis, and cloud computing are covered as well as many other interesting aspects.
Building Machine Learning Systems with Python will give you the tools and understanding required to build your own systems, which are tailored to solve your problems.
Approach
A practical, scenario-based tutorial, this book will help you get to grips with machine learning with Python and start building your own machine learning projects. By the end of the book you will have learnt critical aspects of machine learning Python projects and experienced the power of ML-based systems by actually working on them.
Who this book is for
This book is for Python programmers who are beginners in machine learning, but want to learn Machine learning. Readers are expected to know Python and be able to install and use open-source libraries. They are not expected to know machine learning, although the book can also serve as an introduction to some Python libraries for readers who know machine learning. This book does not go into the detail of the mathematics behind the algorithms.
This book primarily targets Python developers who want to learn and build machine learning in their projects, or who want to provide machine learning support to their existing projects, and see them getting implemented effectively.
As the Big Data explosion continues at an almost incomprehensible rate, being able to understand and process it becomes even more challenging. With Building Machine Learning Systems with Python, you'll learn everything you need to tackle the modern data deluge - by harnessing the unique capabilities of Python and its extensive range of numerical and scientific libraries, you will be able to create complex algorithms that can 'learn' from data, allowing you to uncover patterns, make predictions, and gain a more in-depth understanding of your data. Featuring a wealth of real-world examples, this book provides gives you with an accessible route into Python machine learning. Learn the Iris dataset, find out how to build complex classifiers, and get to grips with clustering through practical examples that deliver complex ideas with clarity. Dig deeper into machine learning, and discover guidance on classification and regression, with practical machine learning projects outlining effective strategies for sentiment analysis and basket analysis. The book also takes you through the latest in computer vision, demonstrating how image processing can be used for pattern recognition, as well as showing you how to get a clearer picture of your data and trends by using dimensionality reduction. Keep up to speed with one of the most exciting trends to emerge from the world of data science and dig deeper into your data with Python with this unique data science tutorial. This is a tutorial-driven and practical, but well-grounded book showcasing good Machine Learning practices. There will be an emphasis on using existing technologies instead of showing how to write your own implementations of algorithms. This book is a scenario-based, example-driven tutorial. By the end of the book you will have learnt critical aspects of Machine Learning Python projects and experienced the power of ML-based systems by actually working on them.This book primarily targets Python developers who want to learn about and build Machine Learning into their projects, or who want to provide Machine Learning support to their existing projects, and see them get implemented effectively.Computer science researchers, data scientists, Artificial Intelligence programmers, and statistical programmers would equally gain from this book and would learn about effective implementation through lots of the practical examples discussed.Readers need no prior experience with Machine Learning or statistical processing. Python development experience is assumed. This is a tutorial-driven and practical, but well-grounded book showcasing good Machine Learning practices. There will be an emphasis on using existing technologies instead of showing how to write your own implementations of algorithms. This book is a scenario-based, example-driven tutorial. By the end of the book you will have learnt critical aspects of Machine Learning Python projects and experienced the power of ML-based systems by actually working on them. This book primarily targets Python developers who want to learn about and build Machine Learning into their projects, or who want to pro