There are so many posts like this about how to extract sklearn decision tree rules but I could not find any about using pandas.
Take this data and model for example, as below
# Create Decision Tree classifer objectclf = DecisionTreeClassifier(criterion="entropy", max_depth=3)# Train Decision Tree Classiferclf = clf.fit(X_train,y_train)
The result:
Expected:
There're 8 rules about this example.
From left to right,notice that dataframe is df
r1 = (df['glucose']<=127.5) & (df['bmi']<=26.45) & (df['bmi']<=9.1)……r8 = (df['glucose']>127.5) & (df['bmi']>28.15) & (df['glucose']>158.5)
I'm not a master of extracting sklearn decision tree rules. Getting the pandas boolean conditions will help me calculate samples and other metrics for each rule. So I want to extract each rule to a pandas boolean condition.