---
name: "mlpack_logistic_regression"
section: "1"
platform: "linux"
package: "mlpack-bin"
version: "4.6.0-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mlpack_logistic_regression"
---

# mlpack\_logistic\_regression(1)

l2-regularized logistic regression and prediction

## NAME

**mlpack\_logistic\_regression** - l2-regularized logistic regression and prediction

## SYNOPSIS

```
 mlpack_logistic_regression [-b int] [-d double] [-m unknown] [-l unknown] [-L double] [-n int] [-O string] [-a bool] [-s double] [-T unknown] [-e double] [-t unknown] [-V bool] [-M unknown] [-P unknown] [-p unknown] [-h -v]
```

## DESCRIPTION

An implementation of L2-regularized logistic regression using either the L-BFGS optimizer or SGD (stochastic gradient descent). This solves the regression problem

```
  y = (1 / 1 + e^-(X * b)).
```

In this setting, y corresponds to class labels and X corresponds to data.

This program allows loading a logistic regression model (via the ’**--input\_model\_file** (**-m**)' parameter) or training a logistic regression model given training data (specified with the '**--training\_file** (**-t**)' parameter), or both those things at once. In addition, this program allows classification on a test dataset (specified with the '**--test\_file** (**-T**)' parameter) and the classification results may be saved with the '**--predictions\_file** (**-P**)' output parameter. The trained logistic regression model may be saved using the ’**--output\_model\_file** (**-M**)' output parameter.

The training data, if specified, may have class labels as its last dimension.  Alternately, the '**--labels\_file** (**-l**)' parameter may be used to specify a separate matrix of labels.

When a model is being trained, there are many options. L2 regularization (to prevent overfitting) can be specified with the '**--lambda** (**-L**)' option, and the optimizer used to train the model can be specified with the '**--optimizer** (**-O**)' parameter. Available options are 'sgd' (stochastic gradient descent) and ’lbfgs' (the L-BFGS optimizer). There are also various parameters for the optimizer; the '**--max\_iterations** (**-n**)' parameter specifies the maximum number of allowed iterations, and the '**--tolerance** (**-e**)' parameter specifies the tolerance for convergence. For the SGD optimizer, the '**--step\_size** (**-s**)' parameter controls the step size taken at each iteration by the optimizer.  The batch size for SGD is controlled with the '**--batch\_size** (**-b**)' parameter. If the objective function for your data is oscillating between Inf and 0, the step size is probably too large. There are more parameters for the optimizers, but the C++ interface must be used to access these.

For SGD, an iteration refers to a single point. So to take a single pass over the dataset with SGD, '**--max\_iterations** (**-n**)' should be set to the number of points in the dataset.

Optionally, the model can be used to predict the responses for another matrix of data points, if '**--test\_file** (**-T**)' is specified. The '**--test\_file** (**-T**)' parameter can be specified without the '**--training\_file** (**-t**)' parameter, so long as an existing logistic regression model is given with the ’**--input\_model\_file** (**-m**)' parameter. The output predictions from the logistic regression model may be saved with the '**--predictions\_file** (**-P**)' parameter.

This implementation of logistic regression does not support the general multi-class case but instead only the two-class case. Any labels must be either 0 or 1. For more classes, see the softmax regression implementation.

As an example, to train a logistic regression model on the data ''data.csv'' with labels ''labels.csv'' with L2 regularization of 0.1, saving the model to ’'lr\_model.bin'', the following command may be used:

$ **mlpack\_logistic\_regression** **--training\_file** data.csv **--labels\_file** labels.csv **--lambda** 0.1 **--output\_model\_file** lr\_model.bin **--print\_training\_accuracy**

Then, to use that model to predict classes for the dataset ''test.csv'', storing the output predictions in ''predictions.csv'', the following command may be used:

$ **mlpack\_logistic\_regression** **--input\_model\_file** lr\_model.bin **--test\_file** test.csv **--predictions\_file** predictions.csv

## OPTIONAL INPUT OPTIONS

- **--batch\_size (-b) \[*int*\]**

  Batch size for SGD. Default value 64.

- **--decision\_boundary (-d) \[*double*\]**

  Decision boundary for prediction; if the logistic function for a point is less than the boundary, the class is taken to be 0; otherwise, the class is 1. Default value 0.5.

- **--help (-h) \[*bool*\]**

  Default help info.

- **--info \[*string*\]**

  Print help on a specific option. Default value ''.

- **--input\_model\_file (-m) \[*unknown*\]**

  Existing model (parameters).  **--labels\_file** (**-l**) \[*unknown*\] A matrix containing labels (0 or 1) for the points in the training set (y).

- **--lambda (-L) \[*double*\]**

  L2-regularization parameter for training.  Default value 0.

- **--max\_iterations (-n) \[*int*\]**

  Maximum iterations for optimizer (0 indicates no limit). Default value 10000.

- **--optimizer (-O) \[*string*\]**

  Optimizer to use for training ('lbfgs' or 'sgd'). Default value 'lbfgs'.

- **--print\_training\_accuracy (-a) \[*bool*\]**

  If set, then the accuracy of the model on the training set will be printed (verbose must also be specified).

- **--step\_size (-s) \[*double*\]**

  Step size for SGD optimizer. Default value 0.01.

- **--test\_file (-T) \[*unknown*\]**

  Matrix containing test dataset.

- **--tolerance (-e) \[*double*\]**

  Convergence tolerance for optimizer. Default value 1e-10.

- **--training\_file (-t) \[*unknown*\]**

  A matrix containing the training set (the matrix of predictors, X).

- **--verbose (-v) \[*bool*\]**

  Display informational messages and the full list of parameters and timers at the end of execution.

- **--version (-V) \[*bool*\]**

  Display the version of mlpack.

## OPTIONAL OUTPUT OPTIONS

- **--output\_model\_file (-M) \[*unknown*\]**

  Output for trained logistic regression model.

- **--predictions\_file (-P) \[*unknown*\]**

  If test data is specified, this matrix is where the predictions for the test set will be saved.

- **--probabilities\_file (-p) \[*unknown*\]**

  If test data is specified, this matrix is where the class probabilities for the test set will be saved.

## ADDITIONAL INFORMATION

For further information, including relevant papers, citations, and theory, consult the documentation found at http://www.mlpack.org or included with your distribution of mlpack.
