Documentation
Classes
LogisticRegressionCV

LogisticRegressionCV

Logistic Regression CV (aka logit, MaxEnt) classifier.

See glossary entry for cross-validation estimator.

This class implements logistic regression using liblinear, newton-cg, sag of lbfgs optimizer. The newton-cg, sag and lbfgs solvers support only L2 regularization with primal formulation. The liblinear solver supports both L1 and L2 regularization, with a dual formulation only for the L2 penalty. Elastic-Net penalty is only supported by the saga solver.

For the grid of Cs values and l1\_ratios values, the best hyperparameter is selected by the cross-validator StratifiedKFold, but it can be changed using the cv parameter. The ‘newton-cg’, ‘sag’, ‘saga’ and ‘lbfgs’ solvers can warm-start the coefficients (see Glossary).

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new LogisticRegressionCV(opts?: object): LogisticRegressionCV;

Parameters

NameTypeDescription
opts?object-
opts.Cs?numberEach of the values in Cs describes the inverse of regularization strength. If Cs is as an int, then a grid of Cs values are chosen in a logarithmic scale between 1e-4 and 1e4. Like in support vector machines, smaller values specify stronger regularization. Default Value 10
opts.class_weight?anyWeights 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 that these weights will be multiplied with sample_weight (passed through the fit method) if sample_weight is specified.
opts.cv?numberThe default cross-validation generator used is Stratified K-Folds. If an integer is provided, then it is the number of folds used. See the module sklearn.model\_selection module for the list of possible cross-validation objects.
opts.dual?booleanDual or primal formulation. Dual formulation is only implemented for l2 penalty with liblinear solver. Prefer dual=false when n_samples > n_features. Default Value false
opts.fit_intercept?booleanSpecifies if a constant (a.k.a. bias or intercept) should be added to the decision function. Default Value true
opts.intercept_scaling?numberUseful only when the solver ‘liblinear’ is used and self.fit_intercept is set to true. In this case, x becomes [x, self.intercept_scaling], i.e. a “synthetic” feature with constant value equal to intercept_scaling is appended 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 synthetic feature weight (and therefore on the intercept) intercept_scaling has to be increased. Default Value 1
opts.l1_ratios?anyThe list of Elastic-Net mixing parameter, with 0 <= l1\_ratio <= 1. Only used if penalty='elasticnet'. A value of 0 is equivalent to using penalty='l2', while 1 is equivalent to using penalty='l1'. For 0 < l1\_ratio <1, the penalty is a combination of L1 and L2.
opts.max_iter?numberMaximum number of iterations of the optimization algorithm. Default Value 100
opts.multi_class?"ovr" | "multinomial"If the option chosen is ‘ovr’, then a binary problem is fit for each label. For ‘multinomial’ the loss minimised is the multinomial loss fit across the entire probability distribution, even when the data is binary. ‘multinomial’ is unavailable when solver=’liblinear’. ‘auto’ selects ‘ovr’ if the data is binary, or if solver=’liblinear’, and otherwise selects ‘multinomial’. Default Value 'auto'
opts.n_jobs?numberNumber of CPU cores used during the cross-validation loop. undefined means 1 unless in a joblib.parallel\_backend (opens in a new tab) context. \-1 means using all processors. See Glossary for more details.
opts.penalty?"l1" | "l2" | "elasticnet"Specify the norm of the penalty: Default Value 'l2'
opts.random_state?numberUsed when solver='sag', ‘saga’ or ‘liblinear’ to shuffle the data. Note that this only applies to the solver and not the cross-validation generator. See Glossary for details.
opts.refit?booleanIf set to true, the scores are averaged across all folds, and the coefs and the C that corresponds to the best score is taken, and a final refit is done using these parameters. Otherwise the coefs, intercepts and C that correspond to the best scores across folds are averaged. Default Value true
opts.scoring?stringA string (see model evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y). For a list of scoring functions that can be used, look at sklearn.metrics. The default scoring option used is ‘accuracy’.
opts.solver?"lbfgs" | "newton-cholesky" | "liblinear" | "newton-cg" | "sag" | "saga"Algorithm to use in the optimization problem. Default is ‘lbfgs’. To choose a solver, you might want to consider the following aspects: Default Value 'lbfgs'
opts.tol?numberTolerance for stopping criteria. Default Value 0.0001
opts.verbose?numberFor the ‘liblinear’, ‘sag’ and ‘lbfgs’ solvers set verbose to any positive number for verbosity. Default Value 0

Returns

LogisticRegressionCV

Defined in: generated/linear_model/LogisticRegressionCV.ts:29 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/linear_model/LogisticRegressionCV.ts:27 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/linear_model/LogisticRegressionCV.ts:26 (opens in a new tab)

_py

PythonBridge

Defined in: generated/linear_model/LogisticRegressionCV.ts:25 (opens in a new tab)

id

string

Defined in: generated/linear_model/LogisticRegressionCV.ts:22 (opens in a new tab)

opts

any

Defined in: generated/linear_model/LogisticRegressionCV.ts:23 (opens in a new tab)

Accessors

C_

Array of C that maps to the best scores across every class. If refit is set to false, then for each class, the best C is the average of the C’s that correspond to the best scores for each fold. C\_ is of shape(n_classes,) when the problem is binary.

Signature

C_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/linear_model/LogisticRegressionCV.ts:754 (opens in a new tab)

Cs_

Array of C i.e. inverse of regularization parameter values used for cross-validation.

Signature

Cs_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/linear_model/LogisticRegressionCV.ts:646 (opens in a new tab)

classes_

A list of class labels known to the classifier.

Signature

classes_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/linear_model/LogisticRegressionCV.ts:561 (opens in a new tab)

coef_

Coefficient of the features in the decision function.

coef\_ is of shape (1, n_features) when the given problem is binary.

Signature

coef_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/linear_model/LogisticRegressionCV.ts:590 (opens in a new tab)

coefs_paths_

dict with classes as the keys, and the path of coefficients obtained during cross-validating across each fold and then across each Cs after doing an OvR for the corresponding class as values. If the ‘multi_class’ option is set to ‘multinomial’, then the coefs_paths are the coefficients corresponding to each class. Each dict value has shape (n\_folds, n\_cs, n\_features) or (n\_folds, n\_cs, n\_features + 1) depending on whether the intercept is fit or not. If penalty='elasticnet', the shape is (n\_folds, n\_cs, n\_l1\_ratios\_, n\_features) or (n\_folds, n\_cs, n\_l1\_ratios\_, n\_features + 1).

Signature

coefs_paths_(): Promise<ArrayLike[][]>;

Returns

Promise<ArrayLike[][]>

Defined in: generated/linear_model/LogisticRegressionCV.ts:700 (opens in a new tab)

feature_names_in_

Names of features seen during fit. Defined only when X has feature names that are all strings.

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/linear_model/LogisticRegressionCV.ts:862 (opens in a new tab)

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 problem is binary.

Signature

intercept_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/linear_model/LogisticRegressionCV.ts:619 (opens in a new tab)

l1_ratio_

Array of l1_ratio that maps to the best scores across every class. If refit is set to false, then for each class, the best l1_ratio is the average of the l1_ratio’s that correspond to the best scores for each fold. l1\_ratio\_ is of shape(n_classes,) when the problem is binary.

Signature

l1_ratio_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/linear_model/LogisticRegressionCV.ts:781 (opens in a new tab)

l1_ratios_

Array of l1_ratios used for cross-validation. If no l1_ratio is used (i.e. penalty is not ‘elasticnet’), this is set to \[undefined\]

Signature

l1_ratios_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/linear_model/LogisticRegressionCV.ts:673 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/linear_model/LogisticRegressionCV.ts:835 (opens in a new tab)

n_iter_

Actual number of iterations for all classes, folds and Cs. In the binary or multinomial cases, the first dimension is equal to 1. If penalty='elasticnet', the shape is (n\_classes, n\_folds, n\_cs, n\_l1\_ratios) or (1, n\_folds, n\_cs, n\_l1\_ratios).

Signature

n_iter_(): Promise<ArrayLike[][]>;

Returns

Promise<ArrayLike[][]>

Defined in: generated/linear_model/LogisticRegressionCV.ts:808 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/linear_model/LogisticRegressionCV.ts:153 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/linear_model/LogisticRegressionCV.ts:157 (opens in a new tab)

scores_

dict with classes as the keys, and the values as the grid of scores obtained during cross-validating each fold, after doing an OvR for the corresponding class. If the ‘multi_class’ option given is ‘multinomial’ then the same scores are repeated across all classes, since this is the multinomial class. Each dict value has shape (n\_folds, n\_cs) or (n\_folds, n\_cs, n\_l1\_ratios) if penalty='elasticnet'.

Signature

scores_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/linear_model/LogisticRegressionCV.ts:727 (opens in a new tab)

Methods

decision_function()

Predict confidence scores for samples.

The confidence score for a sample is proportional to the signed distance of that sample to the hyperplane.

Signature

decision_function(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe data matrix for which we want to get the confidence scores.

Returns

Promise<ArrayLike>

Defined in: generated/linear_model/LogisticRegressionCV.ts:247 (opens in a new tab)

densify()

Convert coefficient matrix to dense array format.

Converts the coef\_ member (back) to a numpy.ndarray. This is the default format of coef\_ and is required for fitting, so calling this method is only required on models that have previously been sparsified; otherwise, it is a no-op.

Signature

densify(opts: object): Promise<any>;

Parameters

NameType
optsobject

Returns

Promise<any>

Defined in: generated/linear_model/LogisticRegressionCV.ts:287 (opens in a new tab)

dispose()

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/linear_model/LogisticRegressionCV.ts:228 (opens in a new tab)

fit()

Fit the model according to the given training data.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeTraining vector, where n\_samples is the number of samples and n\_features is the number of features.
opts.sample_weight?anyArray of weights that are assigned to individual samples. If not provided, then each sample is given unit weight.
opts.y?ArrayLikeTarget vector relative to X.

Returns

Promise<any>

Defined in: generated/linear_model/LogisticRegressionCV.ts:315 (opens in a new tab)

init()

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/linear_model/LogisticRegressionCV.ts:166 (opens in a new tab)

predict()

Predict class labels for samples in X.

Signature

predict(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe data matrix for which we want to get the predictions.

Returns

Promise<ArrayLike>

Defined in: generated/linear_model/LogisticRegressionCV.ts:364 (opens in a new tab)

predict_log_proba()

Predict logarithm of probability estimates.

The returned estimates for all classes are ordered by the label of classes.

Signature

predict_log_proba(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Vector to be scored, where n\_samples is the number of samples and n\_features is the number of features.

Returns

Promise<ArrayLike[]>

Defined in: generated/linear_model/LogisticRegressionCV.ts:401 (opens in a new tab)

predict_proba()

Probability estimates.

The returned estimates for all classes are ordered by the label of classes.

For a multi_class problem, if multi_class is set to be “multinomial” the softmax function is used to find the predicted probability of each class. Else use a one-vs-rest approach, i.e calculate the probability of each class assuming it to be positive using the logistic function. and normalize these values across all the classes.

Signature

predict_proba(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Vector to be scored, where n\_samples is the number of samples and n\_features is the number of features.

Returns

Promise<ArrayLike[]>

Defined in: generated/linear_model/LogisticRegressionCV.ts:443 (opens in a new tab)

score()

Score using the scoring option on the given test data and labels.

Signature

score(opts: object): Promise<number>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Test samples.
opts.sample_weight?ArrayLikeSample weights.
opts.y?ArrayLikeTrue labels for X.

Returns

Promise<number>

Defined in: generated/linear_model/LogisticRegressionCV.ts:480 (opens in a new tab)

sparsify()

Convert coefficient matrix to sparse format.

Converts the coef\_ member to a scipy.sparse matrix, which for L1-regularized models can be much more memory- and storage-efficient than the usual numpy.ndarray representation.

The intercept\_ member is not converted.

Signature

sparsify(opts: object): Promise<any>;

Parameters

NameType
optsobject

Returns

Promise<any>

Defined in: generated/linear_model/LogisticRegressionCV.ts:533 (opens in a new tab)