You have to get your hands dirty.
You can read all of the blog posts and watch all the videos in the world, but you’re not actually going to start really get machine learning until you start practicing.
The scikit-learn Python library is very easy to get up and running. Nevertheless I see a lot of hesitation from beginners looking get started. In this blog post I want to give a few very simple examples of using scikit-learn for some supervised classification algorithms.
Let’s get started.
Scikit-Learn Recipes
You don’t need to know about and use all of the algorithms in scikit-learn, at least initially, pick one or two (or a handful) and practice with only those.
In this post you will see 5 recipes of supervised classification algorithms applied to small standard datasets that are provided with the scikit-learn library.
The recipes are principled. Each example is:
- Standalone: Each code example is a self-contained, complete and executable recipe.
- Just Code: The focus of each recipe is on the code with minimal exposition on machine learning theory.
- Simple: Recipes present the common use case, which is probably what you are looking to do.
- Consistent: All code example are presented consistently and follow the same code pattern and style conventions.
The recipes do not explore the parameters of a given algorithm. They provide a skeleton that you can copy and paste into your file, project or python REPL and start to play with immediately.
These recipes show you that you can get started practicing with scikit-learn right now. Stop putting it off.
Logistic Regression
Logistic regression fits a logistic model to data and makes predictions about the probability of an event (between 0 and 1).
This recipe shows the fitting of a logistic regression model to the iris dataset. Because this is a mutli-class classification problem and logistic regression makes predictions between 0 and 1, a one-vs-all scheme is used (one model per class).
For more information see the API reference for Logistic Regression for details on configuring the algorithm parameters. Also see the Logistic Regression section of the user guide.
Naive Bayes
Naive Bayes uses Bayes Theorem to model the conditional relationship of each attribute to the class variable.
This recipe shows the fitting of an Naive Bayes model to the iris dataset.
For more information see the API reference for the Gaussian Naive Bayes for details on configuring the algorithm parameters. Also see the Naive Bayes section of the user guide.
k-Nearest Neighbor
The k-Nearest Neighbor (kNN) method makes predictions by locating similar cases to a given data instance (using a similarity function) and returning the average or majority of the most similar data instances. The kNN algorithm can be used for classification or regression.
This recipe shows use of the kNN model to make predictions for the iris dataset.
For more information see the API reference for the k-Nearest Neighbor for details on configuring the algorithm parameters. Also see the k-Nearest Neighbor section of the user guide.
Classification and Regression Trees
Classification and Regression Trees (CART) are constructed from a dataset by making splits that best separate the data for the classes or predictions being made. The CART algorithm can be used for classification or regression.
This recipe shows use of the CART model to make predictions for the iris dataset.
For more information see the API reference for CART for details on configuring the algorithm parameters. Also see the Decision Tree section of the user guide.
Support Vector Machines
Support Vector Machines (SVM) are a method that uses points in a transformed problem space that best separate classes into two groups. Classification for multiple classes is supported by a one-vs-all method. SVM also supports regression by modeling the function with a minimum amount of allowable error.
This recipe shows use of the SVM model to make predictions for the iris dataset.
For more information see the API reference for SVM for details on configuring the algorithm parameters. Also see the SVM section of the user guide.
Summary
In this post you have seen 5 self-contained recipes demonstrating some of the most popular and powerful supervised classification problems.
Each example is less than 20 lines that you can copy and paste and start using scikit-learn, right now. Stop reading and start practicing. Pick one recipe and run it, then start to play with the parameters and see what effect that has on the results.
No comments:
Post a Comment