bqlearn.unhinged.KernelUnhinged

class bqlearn.unhinged.KernelUnhinged(*, alpha=1.0, kernel='linear', gamma=None, degree=3, coef0=1, kernel_params=None)[source]

Kernel Unhinged Classification.

Kernel Unhinged Classification (KUC) [1] combines unhinged classification with the kernel trick. Fitting a KUC model can be done as class kernel mean maps. It’s typically faster for medium sized datasets.

Parameters:
alphafloat, default=1.0

Regularization strength; must be a positive float. Regularization only scales the weights. Larger values specify stronger regularization. Alpha corresponds to 1 / (2C) in other linear models such as LogisticRegression or LinearSVC.

kernelstr or callable, default=”linear”

Kernel mapping used internally. This parameter is directly passed to pairwise_kernel. If kernel is a string, it must be one of the metrics in pairwise.PAIRWISE_KERNEL_FUNCTIONS. If kernel is “precomputed”, X is assumed to be a kernel matrix. Alternatively, if kernel is a callable function, it is called on each pair of instances (rows) and the resulting value recorded. The callable should take two rows from X as input and return the corresponding kernel value as a single number. This means that callables from sklearn.metrics.pairwise are not allowed, as they operate on matrices, not single samples. Use the string identifying the kernel instead.

gammafloat, default=None

Gamma parameter for the RBF, laplacian, polynomial, exponential chi2 and sigmoid kernels. Interpretation of the default value is left to the kernel; see the documentation for sklearn.metrics.pairwise. Ignored by other kernels.

degreefloat, default=3

Degree of the polynomial kernel. Ignored by other kernels.

coef0float, default=1

Zero coefficient for polynomial and sigmoid kernels. Ignored by other kernels.

kernel_paramsmapping of str to any, default=None

Additional parameters (keyword arguments) for kernel function passed as callable object.

Attributes:
dual_coef_ndarray of shape (n_samples,) or (n_samples, n_targets)

Representation of weight vector(s) in kernel space

X_fit_{ndarray, sparse matrix} of shape (n_samples, n_features)

Training data, which is also required for prediction. If kernel == “precomputed” this is instead the precomputed training matrix, of shape (n_samples, n_samples).

classes_ndarray of shape (n_classes,)

The classes labels.

n_classes_int

The number of classes.

n_features_in_int

Number of features seen during fit.

feature_names_in_ndarray of shape (n_features_in_,)

Names of features seen during fit. Defined only when X has feature names that are all strings.

References

[1]
  1. Rooyen, A. Menon and R. Williamson. “Learning with Symmetric Label Noise: The Importance of Being Unhinged.”, NeurIPS, 2015

Methods

decision_function(X)

Predict confidence scores for samples.

fit(X, y[, sample_weight])

Fit Kernel Unhinged classification model.

get_params([deep])

Get parameters for this estimator.

predict(X)

Predict class labels for samples in X.

score(X, y[, sample_weight])

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

set_params(**params)

Set the parameters of this estimator.

decision_function(X)[source]

Predict confidence scores for samples.

Parameters:
X{array-like, sparse matrix} of shape (n_samples, n_features)

Samples. If kernel == “precomputed” this is instead a precomputed kernel matrix, shape = [n_samples, n_samples_fitted], where n_samples_fitted is the number of samples used in the fitting for this estimator.

Returns:
Cndarray of shape (n_samples,) or (n_samples, n_targets)

Returns predicted values.

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

Fit Kernel Unhinged classification model.

Parameters:
X{array-like, sparse matrix} of shape (n_samples, n_features)

Training data. If kernel == “precomputed” this is instead a precomputed kernel matrix, of shape (n_samples, n_samples).

yarray-like of shape (n_samples,) or (n_samples, n_targets)

Target values.

sample_weightfloat or array-like of shape (n_samples,), default=None

Individual weights for each sample, ignored if None is passed.

Returns:
selfobject

Returns the instance itself.

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

predict(X)[source]

Predict class labels for samples in X.

Parameters:
X{array-like, sparse matrix} of shape (n_samples, n_features)

The data matrix for which we want to get the predictions.

Returns:
y_predndarray of shape (n_samples,)

Vector containing the class labels for each sample.

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

Return 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:
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns:
scorefloat

Mean accuracy of self.predict(X) w.r.t. y.

set_params(**params)[source]

Set the parameters of this estimator.

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

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.