secure_learning.models.secure_linear module¶
Implementation of Linear regression model.
- class secure_learning.models.secure_linear.Linear(solver_type=SolverTypes.GD, penalty=PenaltyTypes.NONE, **penalty_args)[source]¶
Bases:
ModelSolver for Linear regression. Optimizes a model with objective function: $$frac{1}{{2n}_textrm{samples}} times ||y - Xw||^2_2$$
The gradient is given by: $$g(X, y, w) = frac{1}{{2n}_textrm{samples}} times X^T (Xw - y)$$
See secure_model.py docstrings for more information on solver types and penalties.
- __init__(solver_type=SolverTypes.GD, penalty=PenaltyTypes.NONE, **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, weights, grad_per_sample)[source]¶
Evaluate the gradient from the given parameters.
- Parameters:
X (
List[List[SecureFixedPoint]]) – Independent variablesy (
List[SecureFixedPoint]) – Dependent variablesweights (
List[SecureFixedPoint]) – Current weights vectorgrad_per_sample (
bool) – Return a list with gradient per sample instead of aggregated (summed) gradient
- Return type:
Union[List[List[SecureFixedPoint]],List[SecureFixedPoint]]- Returns:
Gradient of objective function as specified in class docstring, evaluated from the provided parameters
- name = 'Linear regression'¶
- static predict(X, weights, **_kwargs)[source]¶
Predicts target values for input data to regression model.
- Parameters:
X (
List[List[SecureFixedPoint]]) – Input data with all featuresweights (
Union[List[float],List[SecureFixedPoint]]) – Weight vector of regression model_kwargs (
None) – Not used
- Return type:
List[SecureFixedPoint]- Returns:
Target values of regression model
- score(X, y, weights)[source]¶
Compute the coefficient of determination $R^2$ of the prediction.
- Parameters:
X (
List[List[SecureFixedPoint]]) – Test data.y (
List[SecureFixedPoint]) – True value for $X$.weights (
Union[List[float],List[SecureFixedPoint]]) – Weight vector.
- Return type:
SecureFixedPoint- Returns:
Score of the model prediction.