简体   繁体   中英

How to list all classification/regression/clustering algorithms in scikit-learn?

类似于如何列出支持 predict_proba() 的所有 scikit-learn 分类器,我想检索 scikit-learn 当前支持的所有分类/回归/聚类算法的列表。

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM