package sklearn

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type tag = [
  1. | `DummyClassifier
]
type t = [ `BaseEstimator | `ClassifierMixin | `DummyClassifier | `MultiOutputMixin | `Object ] Obj.t
val of_pyobject : Py.Object.t -> t
val to_pyobject : [> tag ] Obj.t -> Py.Object.t
val as_classifier : t -> [ `ClassifierMixin ] Obj.t
val as_estimator : t -> [ `BaseEstimator ] Obj.t
val as_multi_output : t -> [ `MultiOutputMixin ] Obj.t
val create : ?strategy:string -> ?random_state:int -> ?constant:[ `S of string | `Arr of [> `ArrayLike ] Np.Obj.t | `I of int ] -> unit -> t

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 :ref:`User Guide <dummy_estimators>`.

.. versionadded:: 0.13

Parameters ---------- strategy : str, default='stratified' 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

.. versionchanged:: 0.22 The default value of `strategy` will change to 'prior' in version 0.24. Starting from version 0.22, a warning will be raised if `strategy` is not explicitly set.

.. versionadded:: 0.17 Dummy Classifier now supports prior fitting strategy using parameter *prior*.

random_state : int, RandomState instance or None, optional, 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 :term:`Glossary <random_state>`.

constant : int 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.

Attributes ---------- classes_ : array or list of array of shape (n_classes,) Class labels for each output.

n_classes_ : array or list of array of shape (n_classes,) Number of label for each output.

class_prior_ : array or list of array of shape (n_classes,) 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.

Examples -------- >>> 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

val fit : ?sample_weight:[> `ArrayLike ] Np.Obj.t -> x:Py.Object.t -> y:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> t

Fit the random classifier.

Parameters ---------- X : array-like, object with finite length or shape Training data, requires length = n_samples

y : array-like of shape (n_samples,) or (n_samples, n_outputs) Target values.

sample_weight : array-like of shape (n_samples,), default=None Sample weights.

Returns ------- self : object

val get_params : ?deep:bool -> [> tag ] Obj.t -> Dict.t

Get parameters for this estimator.

Parameters ---------- deep : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns ------- params : mapping of string to any Parameter names mapped to their values.

val predict : x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

Perform classification on test vectors X.

Parameters ---------- X : array-like, object with finite length or shape Training data, requires length = n_samples

Returns ------- y : array-like of shape (n_samples,) or (n_samples, n_outputs) Predicted target values for X.

val predict_log_proba : x:Py.Object.t -> [> tag ] Obj.t -> Py.Object.t

Return log probability estimates for the test vectors X.

Parameters ---------- X : array-like, object with finite length or shape Training data, requires length = n_samples

Returns ------- P : array-like or list of array-like of shape (n_samples, n_classes) Returns the log probability of the sample for each class in the model, where classes are ordered arithmetically for each output.

val predict_proba : x:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> [> `ArrayLike ] Np.Obj.t

Return probability estimates for the test vectors X.

Parameters ---------- X : array-like, object with finite length or shape Training data, requires length = n_samples

Returns ------- P : array-like or list of array-lke of shape (n_samples, n_classes) Returns the probability of the sample for each class in the model, where classes are ordered arithmetically, for each output.

val score : ?sample_weight:[> `ArrayLike ] Np.Obj.t -> x:[ `Arr of [> `ArrayLike ] Np.Obj.t | `None ] -> y:[> `ArrayLike ] Np.Obj.t -> [> tag ] Obj.t -> float

Returns the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters ---------- X : array-like, None Test samples with shape = (n_samples, n_features) or None. Passing None as test samples gives the same result as passing real test samples, since DummyClassifier operates independently of the sampled observations.

y : array-like of shape (n_samples,) or (n_samples, n_outputs) True labels for X.

sample_weight : array-like of shape (n_samples,), default=None Sample weights.

Returns ------- score : float Mean accuracy of self.predict(X) wrt. y.

val set_params : ?params:(string * Py.Object.t) list -> [> tag ] Obj.t -> t

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form ``<component>__<parameter>`` so that it's possible to update each component of a nested object.

Parameters ---------- **params : dict Estimator parameters.

Returns ------- self : object Estimator instance.

val classes_ : t -> [> `ArrayLike ] Np.Obj.t

Attribute classes_: get value or raise Not_found if None.

val classes_opt : t -> [> `ArrayLike ] Np.Obj.t option

Attribute classes_: get value as an option.

val n_classes_ : t -> Py.Object.t

Attribute n_classes_: get value or raise Not_found if None.

val n_classes_opt : t -> Py.Object.t option

Attribute n_classes_: get value as an option.

val class_prior_ : t -> Py.Object.t

Attribute class_prior_: get value or raise Not_found if None.

val class_prior_opt : t -> Py.Object.t option

Attribute class_prior_: get value as an option.

val n_outputs_ : t -> int

Attribute n_outputs_: get value or raise Not_found if None.

val n_outputs_opt : t -> int option

Attribute n_outputs_: get value as an option.

val sparse_output_ : t -> bool

Attribute sparse_output_: get value or raise Not_found if None.

val sparse_output_opt : t -> bool option

Attribute sparse_output_: get value as an option.

val to_string : t -> string

Print the object to a human-readable representation.

val show : t -> string

Print the object to a human-readable representation.

val pp : Format.formatter -> t -> unit

Pretty-print the object to a formatter.

OCaml

Innovation. Community. Security.