8.19.3. sklearn.multiclass.OneVsOneClassifier¶
- class sklearn.multiclass.OneVsOneClassifier(estimator)¶
One-vs-one multiclass strategy
This strategy consists in fitting one classifier per class pair. At prediction time, the class which received the most votes is selected. Since it requires to fit n_classes * (n_classes - 1) / 2 classifiers, this method is usually slower than one-vs-the-rest, due to its O(n_classes^2) complexity. However, this method may be advantageous for algorithms such as kernel algorithms which don’t scale well with n_samples. This is because each individual learning problem only involves a small subset of the data whereas, with one-vs-the-rest, the complete dataset is used n_classes times.
Parameters : estimator : estimator object
An estimator object implementing fit and predict.
Attributes
estimators_ list of n_classes * (n_classes - 1) / 2 estimators Estimators used for predictions. classes_ numpy array of shape [n_classes] Array containing labels. Methods
fit(X, y) Fit underlying estimators. get_params([deep]) Get parameters for the estimator predict(X) Predict multi-class targets using underlying estimators. score(X, y) Returns the mean accuracy on the given test data and labels. set_params(**params) Set the parameters of the estimator. - __init__(estimator)¶
- fit(X, y)¶
Fit underlying estimators.
Parameters : X: {array-like, sparse matrix}, shape = [n_samples, n_features] :
Data.
y : numpy array of shape [n_samples]
Multi-class targets.
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)¶
Predict multi-class targets using underlying estimators.
Parameters : X : {array-like, sparse matrix}, shape = [n_samples, n_features]
Data.
Returns : y : numpy array of shape [n_samples]
Predicted multi-class targets.
- 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 :