Mojo struct
LogisticRegression
@memory_only
struct LogisticRegression
A Gradient Descent based logistic regression with binary cross entropy as the loss function.
Aliases
MODEL_ID = 3
Fields
- lr (
Float32): Learning rate used for gradient method. - damping (
Float32): Damping value used for newton method. - n_iters (
Int): The maximum number of iterations. - method (
String): Weight update method -> 'gradient' uses first derivative, 'newton' uses second derivative. - reg_alpha (
Float32): Constant that multiplies the regularization term. - l1_ratio (
Float32): The Elastic Net mixing parameter, with 0 <= l1_ratio <= 1. l1_ratio=0 corresponds to L2 penalty, l1_ratio=1 to L1. - tol (
Float32): The stopping criterion based on loss. - batch_size (
Int): Batch size, with batch_size=1 corresponds to SGD, 1 < batch_size < n_samples corresponds to Mini-Batch Gradient Descent. - random_state (
Int): Used for shuffling the data. - weights (
Matrix): Weights per feature. - bias (
Float32): Bias term.
Implemented traits
AnyType, CV, Copyable, ImplicitlyDestructible, Movable
Methods
__init__
def __init__(out self, learning_rate: Float32 = 0.001, damping: Float32 = 1.0E-4, n_iters: Int = 1000, method: String = "gradient", reg_alpha: Float32 = 0, l1_ratio: Float32 = 0, tol: Float32 = 0, batch_size: Int = 0, random_state: Int = -1)
Args:
- learning_rate (
Float32) - damping (
Float32) - n_iters (
Int) - method (
String) - reg_alpha (
Float32) - l1_ratio (
Float32) - tol (
Float32) - batch_size (
Int) - random_state (
Int) - self (
Self)
Returns:
Self
def __init__(out self, params: Dict[String, String])
Args:
- params (
Dict) - self (
Self)
Returns:
Self
Raises:
fit
def fit(mut self, X: Matrix, y: Matrix)
Fit the model.
Args:
- self (
Self) - X (
Matrix) - y (
Matrix)
Raises:
predict
def predict(self, X: Matrix) -> Matrix
Predict class for X.
Args:
- self (
Self) - X (
Matrix)
Returns:
Matrix: The predicted classes.
Raises:
save
def save(self, path: String)
Save model data necessary for prediction to the specified path.
Args:
- self (
Self) - path (
String)
Raises:
load
@staticmethod
def load(path: String) -> Self
Load a saved model from the specified path for prediction.
Args:
- path (
String)
Returns:
Self
Raises: