simpleml.models.classifiers.sklearn.dummy
Wrapper module around sklearn.dummy
Module Contents
Classes
No different than base model. Here just to maintain the pattern |
|
DummyClassifier makes predictions that ignore the input features. |
Attributes
- class simpleml.models.classifiers.sklearn.dummy.SklearnDummyClassifier(has_external_files=True, external_model_kwargs=None, params=None, fitted=False, pipeline_id=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
Two supported patterns - full initialization in constructor or stepwise configured before fit and save
- Parameters
- 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 makes predictions that ignore the input features.
This classifier serves as a simple baseline to compare against other more complex classifiers.
The specific behavior of the baseline is selected with the strategy parameter.
All strategies make predictions that ignore the input feature values passed as the X argument to fit and predict. The predictions, however, typically depend on values observed in the y parameter passed to fit.
Note that the “stratified” and “uniform” strategies lead to non-deterministic predictions that can be rendered deterministic by setting the random_state parameter if needed. The other strategies are naturally deterministic and, once fit, always return a the same constant prediction for any value of X.
Read more in the User Guide.
New in version 0.13.
- strategy{“most_frequent”, “prior”, “stratified”, “uniform”, “constant”}, default=”prior”
Strategy to use to generate predictions.
“most_frequent”: the predict method always returns the most frequent class label in the observed y argument passed to fit. The predict_proba method returns the matching one-hot encoded vector.
“prior”: the predict method always returns the most frequent class label in the observed y argument passed to fit (like “most_frequent”).
predict_proba
always returns the empirical class distribution of y also known as the empirical class prior distribution.“stratified”: the predict_proba method randomly samples one-hot vectors from a multinomial distribution parametrized by the empirical class prior probabilities. The predict method returns the class label which got probability one in the one-hot vector of predict_proba. Each sampled row of both methods is therefore independent and identically distributed.
“uniform”: generates predictions uniformly at random from the list of unique classes observed in y, i.e. each class has equal probability.
“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'
orstrategy='uniform'
. Pass an int for reproducible output across multiple function calls. See Glossary.- constantint or str or array-like of shape (n_outputs,), default=None
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
Unique class labels observed in y. For multi-output classification problems, this attribute is a list of arrays as each output has an independent set of possible classes.
- 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
Frequency of each class observed in y. For multioutput classification problems, this is computed independently for each output.
- n_outputs_int
Number of outputs.
- n_features_in_None
Always set to None.
New in version 0.24.
Deprecated since version 1.0: Will be removed in 1.0
- 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.
DummyRegressor : Regressor that makes predictions using simple rules.
>>> 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