OneVsOneClassifier#

class cuml.multiclass.OneVsOneClassifier(estimator, *, verbose=False, output_type=None)[source]#

Fit one binary classifier per pair of classes. The input can be any kind of cuML compatible array, and the output type follows cuML’s output type configuration rules.

The input is converted to a host (NumPy) array and partitioned into binary classification problems. Each cuML estimator transforms its partition back to the device. These host/device copies have some overhead. For more details see issue NVIDIA/cuml#2876.

For documentation see scikit-learn’s OneVsOneClassifier.

Parameters:
estimatorcuML estimator
verboseint or boolean, default=False

Sets logging level. It must be one of cuml.common.logger.level_*. See Verbosity Levels for more info.

output_type{None, ‘input’, ‘cupy’, ‘numpy’, ‘cudf’, ‘pandas’}, default=None

Return results and set estimator attributes to the indicated output type. If None, the output type set at the module level (cuml.global_settings.output_type) will be used. See Output Data Type Configuration for more info.

Examples

>>> from cuml.linear_model import LogisticRegression
>>> from cuml.multiclass import OneVsOneClassifier
>>> from cuml.datasets.classification import make_classification
>>> X, y = make_classification(n_samples=10, n_features=6,
...                            n_informative=4, n_classes=3,
...                            random_state=137)
>>> cls = OneVsOneClassifier(LogisticRegression())
>>> cls.fit(X, y)
OneVsOneClassifier(estimator=LogisticRegression())
>>> cls.predict(X)
array([1, 1, 0, 1, 1, 1, 2, 2, 1, 2])
decision_function(X)[source]#

Calculate the decision function.

Parameters:
Xarray-like (device or host) shape = (n_samples, n_features)

Dense matrix with dtype float32 or float64. Acceptable formats: CUDA array interface compliant objects like CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas DataFrame/Series.

Returns:
resultscuDF, CuPy or NumPy object depending on cuML’s output type configuration, shape = (n_samples, 1)

Decision function values

For more information on how to configure cuML’s output type, refer to: Output Data Type Configuration.

fit(
X,
y,
sample_weight=None,
) _BaseMulticlassClassifier[source]#

Fit a multiclass classifier.

Parameters:
Xarray-like (device or host) shape = (n_samples, n_features)

Dense matrix with dtype float32 or float64. Acceptable formats: CUDA array interface compliant objects like CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas DataFrame/Series.

yarray-like (device or host) shape = (n_samples, 1)

Dense matrix with any dtype. Acceptable formats: CUDA array interface compliant objects like CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas DataFrame/Series.

sample_weightarray-like (device or host) shape = (n_samples,), default=None

The weights for each observation in X. If None, all observations are assigned equal weight. Acceptable formats: CUDA array interface compliant objects like CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas DataFrame/Series.

get_params(deep=True)[source]#

Returns a dict of all params owned by this class. If the child class has appropriately overridden the _get_param_names method and does not need anything other than what is there in this method, then it doesn’t have to override this method

predict(X)[source]#

Predict using multi class classifier.

Parameters:
Xarray-like (device or host) shape = (n_samples, n_features)

Dense matrix with dtype float32 or float64. Acceptable formats: CUDA array interface compliant objects like CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas DataFrame/Series.

Returns:
predscuDF, CuPy or NumPy object depending on cuML’s output type configuration, shape = (n_samples, 1)

Predicted values

For more information on how to configure cuML’s output type, refer to: Output Data Type Configuration.

score(X, y, sample_weight=None, **kwargs)[source]#

Scoring function for classifier estimators based on mean accuracy.

Parameters:
Xarray-like (device or host) shape = (n_samples, n_features)

Dense matrix with dtype float32 or float64. Acceptable formats: CUDA array interface compliant objects like CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas DataFrame/Series.

yarray-like (device or host) shape = (n_samples, 1)

Dense matrix with dtype float32 or float64. Acceptable formats: CUDA array interface compliant objects like CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas DataFrame/Series.

sample_weightarray-like (device or host) shape = (n_samples,), default=None

The weights for each observation in X. If None, all observations are assigned equal weight. Acceptable formats: CUDA array interface compliant objects like CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas DataFrame/Series.

Returns:
scorefloat

Accuracy of self.predict(X) wrt. y (fraction where y == pred_y)

set_params(**params)[source]#

Accepts a dict of params and updates the corresponding ones owned by this class. If the child class has appropriately overridden the _get_param_names method and does not need anything other than what is, there in this method, then it doesn’t have to override this method