secure_learning.models.secure_svm module¶
Implementation of Support Vector Machine regression model.
- class secure_learning.models.secure_svm.SVM(solver_type=SolverTypes.GD, penalty=PenaltyTypes.L2, **penalty_args)[source]¶
Bases:
Model
Solver for support vector machine. Optimizes a model with objective function: $$frac{1}{n_{textrm{samples}}} sum_{i=1}^{n_{textrm{samples}}} h_w(x_i, y_i).$$
Here, $h_w(x, y)$ is the hinge loss, defined as: $$max(0, 1 - y times (w^T x))$$
Labels $y_i$ are assumed to obtain values $-1$ and $1$.
- __init__(solver_type=SolverTypes.GD, penalty=PenaltyTypes.L2, **penalty_args)[source]¶
Constructor method.
- Parameters:
solver_type (
SolverTypes
) – Solver type to use (e.g. Gradient Descent aka GD)penalty (
PenaltyTypes
) – Choose whether using L1, L2 or no penaltypenalty_args (
float
) – Necessary arguments for chosen penalty
- gradient_function(X, y, coef_, grad_per_sample)[source]¶
This function calculates the gradient as if the input data consists out of all data samples. That is, it does not incorporate coefficients for gradients of partial input data.
The gradient itself is given by $$1 / n * sum_{i=1} [0 if y times (w^T X_i) geq 1 else y_i * X_i]$$
- Parameters:
X (
List
[List
[SecureFixedPoint
]]) – Input matrixy (
List
[SecureFixedPoint
]) – Dependent variablecoef – Current coefficients vector
grad_per_sample (
bool
) – Return a list with gradient per sample instead of aggregated (summed) gradient
- Return type:
Union
[List
[SecureFixedPoint
],List
[List
[SecureFixedPoint
]]]- Returns:
Gradient of SVM objective function.
- name = 'SVM'¶
- static predict(X, coef_, **_kwargs)[source]¶
Predicts labels for input data to classification model. Label $-1$ is assigned of the predicted probability is less then prob, otherwise label $+1$ is assigned.
- Parameters:
X (
List
[List
[SecureFixedPoint
]]) – Input data with all featurescoef – Coefficient vector of classification model
_kwargs (
None
) – Not used
- Return type:
List
[SecureFixedPoint
]- Returns:
Target labels of classification model