Is there an equivalent to caret's getmodelinfo() function in Scikit Learn?

Viewed 74

I'm trying to create a dataframe with all algorithms from Scikit Learn as well as metadata for each. In Caret in R there is a function called getmodelinfo() that does this.

Is there an equivalent in Scikit Learn?

1 Answers

You can get closest to what you want with sklearn.utils and inspect. E.g.you can get a list of all sklearn classes or just classifiers like:

from sklearn.utils.testing import all_estimators
all_est = all_estimators(type_filter=None)
all_classifiers = all_estimators(type_filter="classifier")

Then with the help of inspect you can retrieve args of classifiers .fit method like:

import inspect
all_classifiers_fit_args = {}
for name, clf in all_classifiers:
    all_classifiers_fit_args[name] = inspect.signature(clf.fit)

Finally you can put the info into pandas df:

df = pd.DataFrame(all_classifiers_fit_args.items(), columns=["fit_classifier", "args"])
df
    fit_classifier  args
0   AdaBoostClassifier  (self, X, y, sample_weight=None)
1   BaggingClassifier   (self, X, y, sample_weight=None)
2   BernoulliNB (self, X, y, sample_weight=None)
3   CalibratedClassifierCV  (self, X, y, sample_weight=None)
4   CategoricalNB   (self, X, y, sample_weight=None)
5   CheckingClassifier  (self, X, y, **fit_params)
6   ClassifierChain (self, X, Y)
7   ComplementNB    (self, X, y, sample_weight=None)
8   DecisionTreeClassifier  (self, X, y, sample_weight=None, check_input=T...
...

Alternatively you can access args of the classifiers themselves:

for name, clf in all_classifiers:
    all_classifiers_args[name] = inspect.signature(clf)
df = pd.DataFrame(all_classifiers_args.items(), columns=["classifier", "args"])
df
    classifier  args
0   AdaBoostClassifier  (base_estimator=None, n_estimators=50, learnin...
1   BaggingClassifier   (base_estimator=None, n_estimators=10, max_sam...
2   BernoulliNB (alpha=1.0, binarize=0.0, fit_prior=True, clas...
3   CalibratedClassifierCV  (base_estimator=None, method='sigmoid', cv=None)
4   CategoricalNB   (alpha=1.0, fit_prior=True, class_prior=None)
5   CheckingClassifier  (check_y=None, check_X=None, foo_param=0, expe...
6   ClassifierChain (base_estimator, order=None, cv=None, random_s...
7   ComplementNB    (alpha=1.0, fit_prior=True, class_prior=None, ...
8   DecisionTreeClassifier  (criterion='gini', splitter='best', max_depth=...
...
Related