orthrus.sparse.classifiers namespace¶
Submodules¶
orthrus.sparse.classifiers.svm module¶
-
class
orthrus.sparse.classifiers.svm.L1SVM(nu: float = 1, eps: float = 1e-05, tp: float = 0.1, delta: float = 0.001, imax: int = 50, tol: float = 0.001, kernel_args: dict = None, device: int = - 1, verbosity: int = 1)¶ Bases:
sklearn.base.BaseEstimator,sklearn.base.ClassifierMixin-
convert_type(x)¶
-
fit(X, y)¶
-
predict(X)¶
-
-
class
orthrus.sparse.classifiers.svm.SSVMClassifier(C: float = 1.0, tol: float = 0.001, solver: object = None, errorTrace: object = None, use_cuda: bool = False, verbosity: int = 0, debug: bool = False)¶ Bases:
sklearn.base.BaseEstimator,sklearn.base.ClassifierMixinA class implementing a sparse support vector machine (SSVM) algorithm, which solves the sparse (l1) support vector problem. The primal form of the optimization problem is (?)
min ||w||_1 + C*sum(xi_j) s.t. y_j*(w’*x_j - b) <= 1-xi_j,
for points x_j with corresponding labels y_j (assumed +/-1 in this formulation), optimizing for vector w (the weight vector) and scalar b (the bias), with a corresponding linear (affine) model function f(x) = w’*x - b which approximates the original X, and classifies points using sign(f(x)).
The sklearn adaptation was implemented by Eric Kehoe, CSU 2021. The original Python implementation of this code was by Tomojit Ghosh, which was originally an adaptation of a Matlab code by Sofya Chepushtanova and Michael Kirby.
- Parameters
C (float) – C is the tuning parameter which weights how heavily to penalize the average error for points to violate the hard-margin hyperplane constraints. For values C close to zero, points will be able to violate the hard-margin constraints more so, and sparsity in the w vector will be maximized. Default value is 1.0.
tol (float) – Error tolerance to use in interior point method specified by solver. Default value is .001.
solver (object) – Solver to use for solving the above linear program.
errorTrace (object) – Not known, ignore.
use_cuda (bool) – Flag indicating whether or not to perform linear algebra operations, including solving the above LP, on the GPU. use_cuda = True means use the GPU. use_cuda = False is default.
verbosity (int) – Specifies the level of text output to the user. The default value in 0; indicating minimal text output.
debug (bool) – Passed to the solver to print debug information. Default value is False.
-
weights_¶ Vector of weights, obtained by fitting the SSVM classifier via
SSVMClassifier.fit(), defining the normal vector to the separating hyperplane.- Type
ndarray of shape (n_features,)
-
bias_¶ Affine shift of the hyperplane obtained by fitting the SSVM classifier via
SSVMClassifier.fit().- Type
float
-
pred_labels_¶ Prediction labels of test data obtained by predicting with the SSVM classifier via
SSVMClassifier.predict()- Type
list of length n_samples
-
classes_¶ The class labels.
- Type
ndarray of shape (n_classes,)
-
decision_function(X)¶
-
fit(X, y)¶ Fit/training step for Sparse Support Vector Machines (SSVM). A model function
f(x)=w’*x - b
is found for vector w=len(x) and scalar b which optimally classify the training X, in the sense of solving the L1 minimization problem
min ||w||_1 + C*sum( xi_j ) s.t. y_j*(w’*x_j -b) <= 1-xi_j, j=1,…,n,
where x_j are vector input X, y_j are {-1,+1} class labels for each x_j, xi_j are scalar slack variables.
This code only supports binary classification right now.
The weight vector w and bias b are stored in
SSVMClassifier.weights_andSSVMClassifier.bias_respectively.
-
predict(X, prob=False, pos=None)¶ Classification step for Sparse Support Vector Machine (SSVM). After the fit/training step, vectors w and b are found to optimally classify the training X (in the sense described in the fit() docstring). New X is classified using
sign(f(x)) = sign( w’*x - b ).
-
property
solver¶
-
class
orthrus.sparse.classifiers.svm.SSVMSelect(C: float = 1.0, tol: float = 0.001, solver: object = None, errorTrace: object = None, use_cuda: bool = False, verbosity: int = 0, debug: bool = False, jump_ratio: float = 5.0, n_features: int = None, show_plot: bool = True, corr_threshold: float = None)¶ Bases:
orthrus.sparse.classifiers.svm.SSVMClassifier-
fit(X, y)¶ Fit/training step for Sparse Support Vector Machines (SSVM). A model function
f(x)=w’*x - b
is found for vector w=len(x) and scalar b which optimally classify the training X, in the sense of solving the L1 minimization problem
min ||w||_1 + C*sum( xi_j ) s.t. y_j*(w’*x_j -b) <= 1-xi_j, j=1,…,n,
where x_j are vector input X, y_j are {-1,+1} class labels for each x_j, xi_j are scalar slack variables.
This code only supports binary classification right now.
The weight vector w and bias b are stored in
SSVMClassifier.weights_andSSVMClassifier.bias_respectively.
-
plot_weights()¶
-
select_features(X)¶
-
transform(X, y=None)¶
-