December 2018
Intermediate to advanced
318 pages
8h 28m
English
The following code shows the gini coefficient:
DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=7, max_features=None, max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None, min_samples_leaf=1, min_samples_split=2, min_weight_fraction_leaf=0.0, presort=False, random_state=None, splitter='best')
To visualize the results of the decision with a graph, use the graphviz function:
export_graphviz(treeclf, out_file='tree_kdd.dot', feature_names=X.columns)
At the command line, we run this into convert to PNG:
# dot -Tpng tree_kdd.dot -o tree_kdd.png
We then extract the feature importance:
pd.DataFrame({'feature':X.columns, 'importance':treeclf.feature_importances_}).sort_values('importance', ...Read now
Unlock full access