List of all classification algorithms

Question:

I have a classification problem and I would like to test all the available algorithms to test their performance in tackling the problem.

If you know any classification algorithm other than these listed below, please list it here.

GradientBoostingClassifier()
DecisionTreeClassifier()
RandomForestClassifier()
LinearDiscriminantAnalysis()
LogisticRegression()
KNeighborsClassifier()
GaussianNB()
ExtraTreesClassifier()
BaggingClassifier()
Asked By: Natheer Alabsi

||

Answers:

You may want to look at the following question:

How to list all scikit-learn classifiers that support predict_proba()

The accepted answer shows the method to get all estimators in scikit which support predict_probas method. Just iterate and print all names without checking the condition and you get all estimators. (Classifiers, regressors, cluster etc)

For only classifiers, modify it like below to check all classes that implement ClassifierMixin

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)

For versions >= 0.22, use this:

from sklearn.utils import all_estimators

instead of sklearn.utils.testing

Points to note:

  • The classifiers with CV suffixed to their names implement inbuilt cross-validation (like LogisticRegressionCV, RidgeClassifierCV etc).
  • Some are ensemble and may take other classifiers in input arguments.
  • Some classifiers like _QDA, _LDA are aliases for other classifiers and may be removed in next versions of scikit-learn.

You should check their respective reference docs before using them

Answered By: Vivek Kumar

The answers did not provide the full list of classifiers, so I have listed them below.

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
Answered By: Shaheer Akram

Another alternative is to use the module from sklearn.utils import all_estimators. Here’s an example for importing all classifiers:

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)

Here’s Colaboratory code with it working.

Answered By: Fernando Wittmann

Some code from Shaheer Akram answer is deprecated, so you can get actual import code with it (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}')

Output

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

List of classification estimators

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

Output (41 estimators)

  1. AdaBoostClassifier
  2. BaggingClassifier
  3. BernoulliNB
  4. CalibratedClassifierCV
  5. CategoricalNB
  6. ClassifierChain
  7. ComplementNB
  8. DecisionTreeClassifier
  9. DummyClassifier
  10. ExtraTreeClassifier
  11. ExtraTreesClassifier
  12. GaussianNB
  13. GaussianProcessClassifier
  14. GradientBoostingClassifier
  15. HistGradientBoostingClassifier
  16. KNeighborsClassifier
  17. LabelPropagation
  18. LabelSpreading
  19. LinearDiscriminantAnalysis
  20. LinearSVC
  21. LogisticRegression
  22. LogisticRegressionCV
  23. MLPClassifier
  24. MultiOutputClassifier
  25. MultinomialNB
  26. NearestCentroid
  27. NuSVC
  28. OneVsOneClassifier
  29. OneVsRestClassifier
  30. OutputCodeClassifier
  31. PassiveAggressiveClassifier
  32. Perceptron
  33. QuadraticDiscriminantAnalysis
  34. RadiusNeighborsClassifier
  35. RandomForestClassifier
  36. RidgeClassifier
  37. RidgeClassifierCV
  38. SGDClassifier
  39. SVC
  40. StackingClassifier
  41. VotingClassifier
Answered By: Sinba