Softmax Regression

>>> from mlpack import softmax_regression

This program performs softmax regression, a generalization of logistic regression to the multiclass case, and has support for L2 regularization. The program is able to train a model, load an existing model, and give predictions (and optionally their accuracy) for test data.

Training a softmax regression model is done by giving a file of training points with the 'training' parameter and their corresponding labels with the 'labels' parameter. The number of classes can be manually specified with the 'number_of_classes' parameter, and the maximum number of iterations of the L-BFGS optimizer can be specified with the 'max_iterations' parameter. The L2 regularization constant can be specified with the 'lambda_' parameter and if an intercept term is not desired in the model, the 'no_intercept' parameter can be specified.

The trained model can be saved with the 'output_model' output parameter. If training is not desired, but only testing is, a model can be loaded with the 'input_model' parameter. At the current time, a loaded model cannot be trained further, so specifying both 'input_model' and 'training' is not allowed.

The program is also able to evaluate a model on test data. A test dataset can be specified with the 'test' parameter. Class predictions can be saved with the 'predictions' output parameter. If labels are specified for the test data with the 'test_labels' parameter, then the program will print the accuracy of the predictions on the given test set and its corresponding labels.

For example, to train a softmax regression model on the data 'dataset' with labels 'labels' with a maximum of 1000 iterations for training, saving the trained model to 'sr_model', the following command can be used:

>>> output = softmax_regression(training=dataset, labels=labels)
>>> sr_model = output['output_model']

Then, to use 'sr_model' to classify the test points in 'test_points', saving the output predictions to 'predictions', the following command can be used:

>>> output = softmax_regression(input_model=sr_model, test=test_points)
>>> predictions = output['predictions']

input options

output options

The return value from the binding is a dict containing the following elements: