8.6.1. sklearn.dummy.DummyClassifier¶
- class sklearn.dummy.DummyClassifier(strategy='stratified', random_state=None)¶
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.
Parameters : strategy: str :
- 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.
- “uniform”: generates predictions uniformly at random.
random_state: int seed, RandomState instance, or None (default) :
The seed of the pseudo random number generator to use.
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. outputs_2d_ bool, True if the output at fit is 2d, else false. Methods
fit get_params predict predict_log_proba predict_proba score set_params - __init__(strategy='stratified', random_state=None)¶
- fit(X, y)¶
Fit the random classifier.
Parameters : X : {array-like, sparse matrix}, shape = [n_samples, n_features]
Training vectors, where n_samples is the number of samples and n_features is the number of features.
y : array-like, shape = [n_samples] or [n_samples, n_outputs]
Target values.
Returns : self : object
Returns self.
- get_params(deep=True)¶
Get parameters for the estimator
Parameters : deep: boolean, optional :
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- predict(X)¶
Perform classification on test vectors X.
Parameters : X : {array-like, sparse matrix}, shape = [n_samples, n_features]
Input vectors, where n_samples is the number of samples and n_features is the number of features.
Returns : y : array, shape = [n_samples] or [n_samples, n_outputs]
Predicted target values for X.
- predict_log_proba(X)¶
Return log probability estimates for the test vectors X.
Parameters : X : {array-like, sparse matrix}, shape = [n_samples, n_features]
Input vectors, where n_samples is the number of samples and n_features is the number of features.
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.
- predict_proba(X)¶
Return probability estimates for the test vectors X.
Parameters : X : {array-like, sparse matrix}, shape = [n_samples, n_features]
Input vectors, where n_samples is the number of samples and n_features is the number of features.
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.
- score(X, y)¶
Returns the mean accuracy on the given test data and labels.
Parameters : X : array-like, shape = [n_samples, n_features]
Training set.
y : array-like, shape = [n_samples]
Labels for X.
Returns : z : float
- set_params(**params)¶
Set the parameters of the estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Returns : self :