Created
May 9, 2020 12:50
-
-
Save VincentTatan/fe8560542739e15ff184641a168a5f3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_and_visualize_tree(X_train,y_train,max_depth=3): | |
decision_tree = DecisionTreeClassifier(max_depth=max_depth, min_samples_leaf=1,random_state=1) | |
decision_tree = decision_tree.fit(X_train, y_train) | |
tree_str = export_graphviz(decision_tree, feature_names=X_train.columns, | |
filled=True, out_file=None) | |
graph = pydotplus.graph_from_dot_data(tree_str) | |
graph.write_png('dt.png') | |
display(Image('dt.png')) | |
return decision_tree |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment