简体   繁体   中英

Python Decision Tree Image sklearn

I am working with a baseball data set where each row is an individual pitch. Each column is an attribute about that pitch. Example 1 pitch could be 95 mph, 2,000 RPM spin rate, Exit velocity off the bat of 100mph, etc.

I built a decision tree off of the code from this webpage below, and used pitch velocity, and spin rate to predict whether that pitch resulted in a hit or not. I got 81% accuracy... but who cares? I need to be able to have some insight from the decision tree. For example I need to be able to read something like, Pitches over 95mph with spin rates over 3,000 result in "not a hit" 87% of the time.

How do I plot the image of my decision tree to see this kind of data that I can make recommendations on?

http://dataaspirant.com/2017/02/01/decision-tree-algorithm-python-with-scikit-learn/

Dump decision tree model after training to a file using code

with open("fine_name.dot", 'w') as f:
    f = tree.export_graphviz(tree_name, out_file=f, feature_names=columns)

Copy content of file generated and paste in editor of http://webgraphviz.com/ to visualize decision tree. It converts Decision tree to a white box :D

您可以使用 tree.plot_tree 来获取树的图像。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM