simpleml.models.classifiers.sklearn.dummy

Wrapper module around sklearn.dummy

Module Contents

Classes

SklearnDummyClassifier

No different than base model. Here just to maintain the pattern

WrappedSklearnDummyClassifier

DummyClassifier is a classifier that makes predictions using simple rules.

simpleml.models.classifiers.sklearn.dummy.__author__ = Elisha Yadgaran[source]
class simpleml.models.classifiers.sklearn.dummy.SklearnDummyClassifier(has_external_files=True, external_model_kwargs=None, params=None, **kwargs)[source]

Bases: simpleml.models.classifiers.sklearn.base_sklearn_classifier.SklearnClassifier

No different than base model. Here just to maintain the pattern Generic Base -> Library Base -> Domain Base -> Individual Models (ex: [Library]Model -> SklearnModel -> SklearnClassifier -> SklearnLogisticRegression)

Need to explicitly separate passthrough kwargs to external models since most do not support arbitrary **kwargs in the constructors

_create_external_model(self, **kwargs)[source]

Abstract method for each subclass to implement

should return the desired model object

class simpleml.models.classifiers.sklearn.dummy.WrappedSklearnDummyClassifier(*, strategy='prior', random_state=None, constant=None)[source]

Bases: sklearn.dummy.DummyClassifier, simpleml.models.classifiers.external_models.ClassificationExternalModelMixin

DummyClassifier is a classifier that makes predictions using simple rules.

This classifier is useful as a simple baseline to compare with other (real) classifiers. Do not use it for real problems.

Read more in the User Guide.

New in version 0.13.

strategy{“stratified”, “most_frequent”, “prior”, “uniform”, “constant”}, default=”prior”

Strategy to use to generate predictions.

  • “stratified”: generates predictions by respecting the training set’s class distribution.

  • “most_frequent”: always predicts the most frequent label in the training set.

  • “prior”: always predicts the class that maximizes the class prior (like “most_frequent”) and predict_proba returns the class prior.

  • “uniform”: generates predictions uniformly at random.

  • “constant”: always predicts a constant label that is provided by the user. This is useful for metrics that evaluate a non-majority class

    Changed in version 0.24: The default value of strategy has changed to “prior” in version 0.24.

random_stateint, RandomState instance or None, default=None

Controls the randomness to generate the predictions when strategy='stratified' or strategy='uniform'. Pass an int for reproducible output across multiple function calls. See Glossary.

constantint or str or array-like of shape (n_outputs,)

The explicit constant as predicted by the “constant” strategy. This parameter is useful only for the “constant” strategy.

classesndarray of shape (n_classes,) or list of such arrays

Class labels for each output.

n_classes_int or list of int

Number of label for each output.

class_prior_ndarray of shape (n_classes,) or list of such arrays

Probability of each class for each output.

n_outputs_int

Number of outputs.

sparse_output_bool

True if the array returned from predict is to be in sparse CSC format. Is automatically set to True if the input y is passed in sparse format.

>>> import numpy as np
>>> from sklearn.dummy import DummyClassifier
>>> X = np.array([-1, 1, 1, 1])
>>> y = np.array([0, 1, 1, 1])
>>> dummy_clf = DummyClassifier(strategy="most_frequent")
>>> dummy_clf.fit(X, y)
DummyClassifier(strategy='most_frequent')
>>> dummy_clf.predict(X)
array([1, 1, 1, 1])
>>> dummy_clf.score(X, y)
0.75