pyrfm.linear_model.SparseMBClassifier

class pyrfm.linear_model.SparseMBClassifier(n_components=1000, loss='squared_hinge', solver='cd', C=1.0, alpha=1.0, fit_intercept=True, max_iter=100, tol=1e-06, eps=0.0001, warm_start=False, random_state=None, verbose=True, shuffle=True)[source]

Bases: pyrfm.linear_model.sparse_mb_predictor.BaseSparseMBEstimator, pyrfm.linear_model.base.LinearClassifierMixin

Linear classifier with feature map approximating the intersection (min) kernel by sparse explicit feature map, which was proposed by S.Maji and A.C.Berg.

SparseMB does not approximate min kernel only itself. Linear classifier with SparseMB approximates linear classifier with MB. For more detail, see [1].

Parameters
  • n_components (int (default=1000)) – Number of Monte Carlo samples per original features. Equals the dimensionality of the computed (mapped) feature space.

  • loss (str (default="squared_hinge")) –

    Which loss function to use. Following losses can be used:

    • ’squared_hinge’

    • ’logistic’

  • C (double (default=1.0)) – Weight of loss term.

  • alpha (double (default=1.0)) – Weight of the penalty term.

  • fit_intercept (bool (default=True)) – Whether to fit intercept (bias term) or not.

  • max_iter (int (default=100)) – Maximum number of iterations.

  • tol (double (default=1e-6)) – Tolerance of stopping criterion. If sum of absolute val of update in one epoch is lower than tol, the AdaGrad solver stops learning.

  • eps (double (default=1e-2)) – A small double to ensure objective function convex.

  • warm_start (bool (default=False)) – Whether to activate warm-start or not.

  • random_state (int, RandomState instance or None, optional (default=None)) – If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

  • verbose (bool (default=True)) – Verbose mode or not.

  • shuffle (boole (default=True)) – Whether to shuffle the order of parameters for optimization or not.

self.transformer

The learned transformer for random feature maps.

Type

scikit-learn TransformMixin object.

self.coef_

The learned coefficients of the linear model.

Type

array, shape (n_components, )

self.intercept_

The learned intercept (bias) of the linear model.

Type

array, shape (1, )

References

[1] Max-Margin Additive Classifiers for Detection. Subhransu Maji and Alexander C. Berg. In ICCV 2009. (http://acberg.com/papers/mb09iccv.pdf)

LOSSES = {'hinge': <pyrfm.linear_model.loss_fast.Hinge object>, 'logistic': <pyrfm.linear_model.loss_fast.Logistic object>, 'squared_hinge': <pyrfm.linear_model.loss_fast.SquaredHinge object>}
decision_function(X)
fit(X, y)

Fit model according to X and y.

Parameters
  • X (array-like, 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]) – Target values.

Returns

self – Returns self.

Return type

classifier

get_params(deep=True)

Get parameters for this estimator.

Parameters

deep (boolean, optional) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params – Parameter names mapped to their values.

Return type

mapping of string to any

predict(X)

Perform classification on an array of test vectors X.

Parameters

X (array-like, shape = [n_samples, n_features]) –

Returns

Predicted target values for X

Return type

array, shape = [n_samples]

predict_proba(X)
score(X, y, sample_weight=None)

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, shape = (n_samples, n_features)) – Test samples.

  • y (array-like, shape = (n_samples) or (n_samples, n_outputs)) – True labels for X.

  • sample_weight (array-like, shape = [n_samples], optional) – Sample weights.

Returns

score – Mean accuracy of self.predict(X) wrt. y.

Return type

float

set_params(**params)

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.

Returns

Return type

self