>>> 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:
>>> 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:
>>> softmax_regression(input_model=sr_model, test=test_points)
>>> predictions = output['predictions']
- copy_all_inputs (bool): If specified, all input parameters will be deep copied before the method is run. This is useful for debugging problems where the input parameters are being modified by the algorithm, but can slow down the code.
- input_model (mlpack.SoftmaxRegressionType): File containing existing model (parameters).
- labels (numpy vector or array, int/long dtype): A matrix containing labels (0 or 1) for the points in the training set (y). The labels must order as a row.
- lambda_ (float): L2-regularization constant Default value 0.0001.
- max_iterations (int): Maximum number of iterations before termination. Default value 400.
- no_intercept (bool): Do not add the intercept term to the model.
- number_of_classes (int): Number of classes for classification; if unspecified (or 0), the number of classes found in the labels will be used. Default value 0.
- test (numpy matrix or arraylike, float dtype): Matrix containing test dataset.
- test_labels (numpy vector or array, int/long dtype): Matrix containing test labels.
- training (numpy matrix or arraylike, float dtype): A matrix containing the training set (the matrix of predictors, X).
- verbose (bool): Display informational messages and the full list of parameters and timers at the end of execution.
The return value from the binding is a dict containing the following elements:
- output_model (mlpack.SoftmaxRegressionType): File to save trained softmax regression model to.
- predictions (numpy vector, int dtype): Matrix to save predictions for test dataset into.