Skip to Content
Python: Advanced Predictive Analytics
book

Python: Advanced Predictive Analytics

by Ashish Kumar, Joseph Babcock
December 2017
Beginner to intermediate
660 pages
15h 31m
English
Packt Publishing
Content preview from Python: Advanced Predictive Analytics

Implementing a decision tree with scikit-learn

Now, when we are sufficiently aware of the mathematics behind decision trees, let us implement a simple decision tree using the methods in scikit-learn. The dataset we will be using for this is a commonly available dataset called the iris dataset that has information about flower species and their petal and sepal dimensions. The purpose of this exercise will be to create a classifier that can classify a flower as belonging to a certain species based on the flower petal and sepal dimensions.

To do this, let's first import the dataset and have a look at it:

import pandas as pd
data=pd.read_csv('E:/Personal/Learning/Predictive Modeling Book/My Work/Chapter 7/iris.csv')
data.head()

The datasheet looks as ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Predictive Analytics with Python

Mastering Predictive Analytics with Python

Joseph Babcock

Publisher Resources

ISBN: 9781788992367Supplemental Content