April 2018
Beginner to intermediate
282 pages
6h 52m
English
Decision tree models can be created by importing scikit-learn's DecisionTreeClassifier:
import numpy as npimport pandas as pdfrom sklearn.tree import DecisionTreeClassifierfrom sklearn.metrics import accuracy_scorefrom sklearn import tree
Next, we read the HR attrition dataset and do all the data preprocessing that was done in the previous logistics regression example:
hr_data = pd.read_csv('data/hr.csv', header=0)hr_data.head()hr_data = hr_data.dropna()print(" Data Set Shape ", hr_data.shape)print(list(hr_data.columns))print(" Sample Data ", hr_data.head())
The output of the preceding code is as follows:
The following code creates the dummy variables for categorical data and splits the ...