我有一个分类问题,我想测试所有可用的算法,以测试它们在解决该问题时的性能。
如果你知道下面列出的分类算法之外的任何分类算法,请在这里列出。
GradientBoostingClassifier()
DecisionTreeClassifier()
RandomForestClassifier()
LinearDiscriminantAnalysis()
LogisticRegression()
KNeighborsClassifier()
GaussianNB()
ExtraTreesClassifier()
BaggingClassifier()
答案没有提供分类器的完整列表,所以我在下面列出了它们。
from sklearn.tree import ExtraTreeClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm.classes import OneClassSVM
from sklearn.neural_network.multilayer_perceptron import MLPClassifier
from sklearn.neighbors.classification import RadiusNeighborsClassifier
from sklearn.neighbors.classification import KNeighborsClassifier
from sklearn.multioutput import ClassifierChain
from sklearn.multioutput import MultiOutputClassifier
from sklearn.multiclass import OutputCodeClassifier
from sklearn.multiclass import OneVsOneClassifier
from sklearn.multiclass import OneVsRestClassifier
from sklearn.linear_model.stochastic_gradient import SGDClassifier
from sklearn.linear_model.ridge import RidgeClassifierCV
from sklearn.linear_model.ridge import RidgeClassifier
from sklearn.linear_model.passive_aggressive import PassiveAggressiveClassifier
from sklearn.gaussian_process.gpc import GaussianProcessClassifier
from sklearn.ensemble.voting_classifier import VotingClassifier
from sklearn.ensemble.weight_boosting import AdaBoostClassifier
from sklearn.ensemble.gradient_boosting import GradientBoostingClassifier
from sklearn.ensemble.bagging import BaggingClassifier
from sklearn.ensemble.forest import ExtraTreesClassifier
from sklearn.ensemble.forest import RandomForestClassifier
from sklearn.naive_bayes import BernoulliNB
from sklearn.calibration import CalibratedClassifierCV
from sklearn.naive_bayes import GaussianNB
from sklearn.semi_supervised import LabelPropagation
from sklearn.semi_supervised import LabelSpreading
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.svm import LinearSVC
from sklearn.linear_model import LogisticRegression
from sklearn.linear_model import LogisticRegressionCV
from sklearn.naive_bayes import MultinomialNB
from sklearn.neighbors import NearestCentroid
from sklearn.svm import NuSVC
from sklearn.linear_model import Perceptron
from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis
from sklearn.svm import SVC
from sklearn.mixture import DPGMM
from sklearn.mixture import GMM
from sklearn.mixture import GaussianMixture
from sklearn.mixture import VBGMM
您可能需要查看以下问题:
如何列出所有支持predict_proba()的scikit学习分类器
接受的答案显示了在scikit中获得所有估计量的方法,该方法支持predict_probas方法。只需迭代并打印所有名称,而无需检查条件,即可获得所有估计量。(分类器、回归器、聚类等)
仅对分类器进行如下修改,以检查中实现ClassifierMix的所有类
from sklearn.base import ClassifierMixin
from sklearn.utils.testing import all_estimators
classifiers=[est for est in all_estimators() if issubclass(est[1], ClassifierMixin)]
print(classifiers)
对于>=0.22,使用此:
from sklearn.utils import all_estimators
而不是sklearn.utils.testing
注意事项:
- 名称后缀为CV的分类器实现内置的交叉验证(如LogisticRegressionCV、RidgeClassifierCV等)
- 有些是集成的,可能在输入自变量中采用其他分类器
- 一些分类器,如_QDA、_LDA是其他分类器的别名,可能会在scikit-learn的下一版本中删除
在使用之前,您应该检查他们各自的参考文档
另一种选择是使用模块from sklearn.utils import all_estimators
。以下是导入所有分类器的示例:
from sklearn.utils import all_estimators
estimators = all_estimators(type_filter='classifier')
all_clfs = []
for name, ClassifierClass in estimators:
print('Appending', name)
try:
clf = ClassifierClass()
all_clfs.append(clf)
except Exception as e:
print('Unable to import', name)
print(e)
这是合作代码,它可以工作。
Shaheer-Akram答案中的一些代码已被弃用,因此您可以使用它获得实际的导入代码(sklearn 1.0.2):
from sklearn.utils import all_estimators
estimators = all_estimators(type_filter='classifier')
for name, class_ in estimators:
module_name = str(class_).split("'")[1].split(".")[1]
class_name = class_.__name__
print(f'from sklearn.{module_name} import {class_name}')
输出
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import BaggingClassifier
from sklearn.naive_bayes import BernoulliNB
from sklearn.calibration import CalibratedClassifierCV
from sklearn.naive_bayes import CategoricalNB
from sklearn.multioutput import ClassifierChain
from sklearn.naive_bayes import ComplementNB
from sklearn.tree import DecisionTreeClassifier
from sklearn.dummy import DummyClassifier
from sklearn.tree import ExtraTreeClassifier
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.gaussian_process import GaussianProcessClassifier
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.ensemble import HistGradientBoostingClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.semi_supervised import LabelPropagation
from sklearn.semi_supervised import LabelSpreading
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.svm import LinearSVC
from sklearn.linear_model import LogisticRegression
from sklearn.linear_model import LogisticRegressionCV
from sklearn.neural_network import MLPClassifier
from sklearn.multioutput import MultiOutputClassifier
from sklearn.naive_bayes import MultinomialNB
from sklearn.neighbors import NearestCentroid
from sklearn.svm import NuSVC
from sklearn.multiclass import OneVsOneClassifier
from sklearn.multiclass import OneVsRestClassifier
from sklearn.multiclass import OutputCodeClassifier
from sklearn.linear_model import PassiveAggressiveClassifier
from sklearn.linear_model import Perceptron
from sklearn.discriminant_analysis import QuadraticDiscriminantAnalysis
from sklearn.neighbors import RadiusNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import RidgeClassifier
from sklearn.linear_model import RidgeClassifierCV
from sklearn.linear_model import SGDClassifier
from sklearn.svm import SVC
from sklearn.ensemble import StackingClassifier
from sklearn.ensemble import VotingClassifier
分类估计量列表
from sklearn.utils import all_estimators
estimators = all_estimators(type_filter='classifier')
i = 0
for name, class_ in estimators:
print(f'{i}. {class_.__name__}')
i += 1
输出(41个估计量)
- AdaBoostClassifier
- 袋装分级机
- 伯努利NB
- 校准分类器CV
- 类别NB
- 分类器链
- 互补NB
- 决策树分类器
- Dummy分类器
- ExtraTree分类器
- ExtraTrees分类器
- GaussianNB
- 高斯过程分类器
- GradientBoosting分类器
- HistGradientBoostingClassifier
- KNeighbors分类器
- LabelPropagation
- 标签传播
- 线性判别分析
- 线性SVC
- 后勤回归
- 后勤回归CV
- MLP分类器
- 多输出分类器
- 多项式NB
- 最近质心
- NuSVC
- OneVsOne分类器
- OneVsRest分类器
- 输出代码分类器
- PassiveAggressive分类器
- 感知器
- 二次判别分析
- RadiusNeighbors分类器
- RandomForest分类器
- 山脊分类器
- 山脊分类器CV
- SGD分类器
- SVC
- 堆叠分类器
- VotingClassifier