maxframe.learn.linear_model.LogisticRegression#

class maxframe.learn.linear_model.LogisticRegression(penalty='l2', *, tol=0.0001, C=1.0, fit_intercept=True, random_state=None, solver='lbfgs', max_iter=300, verbose=0, warm_start=False, l1_ratio=None, dual=False, intercept_scaling=1.0, class_weight=None)[source]#

Logistic Regression (aka logit, MaxEnt) classifier.

This class implements regularized logistic regression using the specified solver. Note that regularization is applied by default. It can handle both dense and sparse input. Use C-ordered arrays or CSR matrices containing 64-bit floats for optimal performance; any other input format will be converted (and copied).

Note

This is a MaxFrame distributed implementation. Supported solvers are lbfgs, newton-cg, newton-cholesky, and liblinear. The multi_class parameter is intentionally not provided, following scikit-learn’s deprecation (removed in sklearn 1.8). Multiclass problems always use the multinomial loss. The liblinear solver supports binary classification only; use OneVsRestClassifier for OvR multiclass.

Parameters:
  • penalty ({'l1', 'l2', 'elasticnet', 'none'}, default='l2') –

    Used to specify the norm used in the penalization. Not all penalties are supported by all solvers:

    Penalty

    Supported solvers

    l1

    liblinear

    l2

    lbfgs, newton-cg, newton-cholesky, liblinear

    elasticnet

    lbfgs

    none

    lbfgs, newton-cg, newton-cholesky

    If ‘none’, no regularization is applied.

  • C (float, default=1.0) – Inverse of regularization strength; must be a positive float. Smaller values specify stronger regularization.

  • fit_intercept (bool, default=True) – Specifies if a constant (a.k.a. bias or intercept) should be added to the decision function.

  • random_state (int, RandomState instance, default=None) – Seed for the random number generator used to initialize coefficients.

  • solver ({'lbfgs', 'newton-cg', 'newton-cholesky', 'liblinear'}, default='lbfgs') –

    Algorithm to use in the optimization problem.

    • lbfgs: Uses scipy.optimize.minimize with L-BFGS-B. Supports l1, l2, elasticnet, and none penalties. Multiclass: multinomial.

    • newton-cg: Newton’s method with CG linear solver. Supports l2 and none penalties only. Multiclass: multinomial.

    • newton-cholesky: Newton’s method with Cholesky factorization. Supports l2 and none penalties only. Multiclass: multinomial.

    • liblinear: Coordinate descent (wraps LIBLINEAR). Supports l1 and l2 penalties only. Binary classification only (raises ValueError for n_classes > 2).

    Note

    newton-cg and newton-cholesky compute the full Hessian matrix and require it to fit into AM memory. For high-dimensional data, lbfgs is recommended.

  • dual (bool, default=False) –

    Dual or primal formulation. Dual formulation is only implemented for l2 penalty with liblinear solver. Prefer dual=False when n_samples > n_features.

    Note

    This parameter is only used by the liblinear solver. For other solvers, this parameter has no effect.

  • intercept_scaling (float, default=1.0) –

    Useful only when solver=’liblinear’ and fit_intercept=True. In this case, the intercept term is scaled by intercept_scaling (i.e. a “synthetic” feature with constant value equal to intercept_scaling is added to the instance vector). The intercept becomes intercept_scaling * synthetic_feature_weight.

    Note

    The synthetic feature weight is subject to l1/l2 regularization as all other features. To lessen the effect of regularization on the intercept term, increase intercept_scaling.

    Note

    This parameter is only used by the liblinear solver. For other solvers, this parameter has no effect.

  • class_weight (dict or 'balanced', default=None) –

    Weights associated with classes in the form {class_label: weight}. If not given, all classes are supposed to have weight one.

    The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as n_samples / (n_classes * np.bincount(y)).

    Note

    class_weight is converted to per-sample weights before fitting and combined with sample_weight if both are provided. This is equivalent to passing class_weight directly for all solvers including liblinear.

  • max_iter (int, default=300) – Maximum number of iterations taken for the solver to converge.

  • verbose (int, default=0) –

    For the lbfgs solver set verbose to any positive number for verbosity.

    Note

    Not yet implemented. Currently has no effect on the optimization process.

  • warm_start (bool, default=False) – When set to True, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution.

  • l1_ratio (float, default=None) – The Elastic-Net mixing parameter, with 0 <= l1_ratio <= 1. Only used if penalty='elasticnet'. Setting l1_ratio=0 is equivalent to using penalty='l2', while l1_ratio=1 is equivalent to using penalty='l1'.

coef_#

Coefficient of the features in the decision function.

coef_ is of shape (1, n_features) when the given problem is binary.

Type:

ndarray of shape (1, n_features) or (n_classes, n_features)

intercept_#

Intercept (a.k.a. bias) added to the decision function.

If fit_intercept is set to False, the intercept is set to zero. intercept_ is of shape (1,) when the given problem is binary.

Type:

ndarray of shape (1,) or (n_classes,)

n_iter_#

Actual number of iterations for all classes.

Type:

int

classes_#

A list of class labels known to the classifier.

Type:

ndarray of shape (n_classes,)

See also

SGDClassifier

Incrementally trained logistic regression (when given the parameter loss="log").

LogisticRegressionCV

Logistic regression with built-in cross validation.

Examples

>>> from sklearn.datasets import load_iris
>>> from maxframe.learn.linear_model import LogisticRegression
>>> X, y = load_iris(return_X_y=True)
>>> clf = LogisticRegression(random_state=0).fit(X, y)
>>> clf.predict(X[:2, :])
array([0, 0])
__init__(penalty='l2', *, tol=0.0001, C=1.0, fit_intercept=True, random_state=None, solver='lbfgs', max_iter=300, verbose=0, warm_start=False, l1_ratio=None, dual=False, intercept_scaling=1.0, class_weight=None)[source]#

Methods

__init__([penalty, tol, C, fit_intercept, ...])

decision_function(X)

Predict confidence scores for samples.

execute([session, run_kwargs, extra_tileables])

fetch([session, run_kwargs])

fit(X, y[, sample_weight, execute, session, ...])

Fit the model according to the given training data.

predict(X[, execute, session, run_kwargs])

Predict class labels for samples in X.

predict_log_proba(X[, execute, session, ...])

Predict logarithm of probability estimates.

predict_proba(X[, execute, session, run_kwargs])

Probability estimates.

score(X, y[, sample_weight])

Return the mean accuracy on the given test data and labels.