7

In analogy to How to list all scikit-learn classifiers that support predict_proba() I want to retrieve a list of all classification/regression/clustering algorithms currently supported in scikit-learn.

Community
  • 1
  • 1
dreamflasher
  • 1,387
  • 15
  • 22

2 Answers2

10

Combining How to list all scikit-learn classifiers that support predict_proba() and http://scikit-learn.org/stable/modules/classes.html#module-sklearn.base yields the solution:

from sklearn.utils.testing import all_estimators
from sklearn import base

estimators = all_estimators()

for name, class_ in estimators:
    if issubclass(class_, base.ClassifierMixin):
        print(name)

Or use any other base class: ClusterMixin, RegressorMixin, TransformerMixin.

Community
  • 1
  • 1
dreamflasher
  • 1,387
  • 15
  • 22
4

As a more up-to-date solution, sklearn updated the module to sklearn.utils.all_estimators. Here's an example for importing all regression models:

from sklearn.utils import all_estimators

estimators = all_estimators(type_filter='regressor')

all_regs = []
for name, RegressorClass in estimators:
    try:
        print('Appending', name)
        reg = RegressorClass()
        all_regs.append(reg)
    except Exception as e:
        print(e)

Some of them require an init parameter (like estimator) and had to be ignored using try..except.

Fernando Wittmann
  • 1,991
  • 20
  • 16