I have old code using scikit-learn DecisionTreeClassifier. I would like to make partial graphs based on this classifier.
All the examples that I have seen so far (for example, http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.partial_dependence.plot_partial_dependence.html ) use the "GradientBoostingRegressor" classifier.
My question is, is it possible to make partial graphs for another classifier? (eg.DecisionTreeClassifier). I tried the following code:
from sklearn.tree import DecisionTreeClassifier from sklearn.ensemble.partial_dependence import plot_partial_dependence from sklearn.datasets import make_friedman1 X, y = make_friedman1() clf = DecisionTreeClassifier(max_features='auto').fit(X,y) fig, axs = plot_partial_dependence(clf, X, [0, (0, 1)])
and it does not work.
ValueError: gbrt has to be an instance of BaseGradientBoosting
I found some comments on the Internet (Quora):
Partial dependence graphs are generally independent of the particular choice of classifier. The plot partial dependency module used as an example of increasing the gradient will work fine if you change to a random forest classifier.
However, I still don't know how this works.
Also for R, I can make partial graphs for the randomForest package. However, Iβm not quite sure how random forest is implemented, in the manual R author Andy Love refers to the link "Friedman, J. (2001). Approximation of greed: Gradient Enhancer, Ann. Of Stat."
Does this mean that I have to use gradient acceleration to get partial graphs?
Any help is appreciated. Many thanks!
python scikit-learn r
user2921752
source share