Skip to content

Instantly share code, notes, and snippets.

@netsatsawat
Created May 19, 2019 17:31
Show Gist options
  • Save netsatsawat/aeb60e7b99b3ae0868a67e2030a98b7d to your computer and use it in GitHub Desktop.
Save netsatsawat/aeb60e7b99b3ae0868a67e2030a98b7d to your computer and use it in GitHub Desktop.
Code snippet for decision tree and plot the decision tree to file
tree_clf = tree.DecisionTreeClassifier(random_state=SEED, max_depth=3)
_ = myUtilityFunction.prediction_evaluation(tree_clf, X_train, X_test,
y_train, y_test, X_train.columns,
'features')
dot_data = tree.export_graphviz(tree_clf, out_file=None,
feature_names=X_train.columns,
class_names=['No', 'Yes'],
filled=True, rounded=True,
special_characters=True)
graph = graphviz.Source(dot_data)
graph.format = 'png'
graph.render('../img/output/model_decision tree_employee attrition', view=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment