Quantcast
Channel: How to extract sklearn decision tree rules to pandas boolean conditions? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by kevin for How to extract sklearn decision tree rules to pandas boolean conditions?

$
0
0

Now you can use export_text.

from sklearn.tree import export_textr = export_text(loan_tree, feature_names=(list(X_train.columns)))print(r)

A complete example from sklearn

from sklearn.datasets import load_irisfrom sklearn.tree import DecisionTreeClassifierfrom sklearn.tree import export_textiris = load_iris()X = iris['data']y = iris['target']decision_tree = DecisionTreeClassifier(random_state=0, max_depth=2)decision_tree = decision_tree.fit(X, y)r = export_text(decision_tree, feature_names=iris['feature_names'])print(r)

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>