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:
Model
Solver 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, coef_, grad_per_sample)[source]¶
Evaluate the gradient from the given parameters.
- Parameters:
X (
List
[List
[SecureFixedPoint
]]) – Independent variablesy (
List
[SecureFixedPoint
]) – Dependent variablescoef – Current coefficients vector
grad_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, coef_, **_kwargs)[source]¶
Predicts target values for input data to regression model.
- Parameters:
X (
List
[List
[SecureFixedPoint
]]) – Input data with all featurescoef – Coefficient vector of regression model
_kwargs (
None
) – Not used
- Return type:
List
[SecureFixedPoint
]- Returns:
Target values of regression model