mlpack
Functions
softmax_regression_main.cpp File Reference

Main program for softmax regression. More...

#include <mlpack/prereqs.hpp>
#include <mlpack/core/util/io.hpp>
#include <mlpack/core/util/mlpack_main.hpp>
#include <mlpack/methods/softmax_regression/softmax_regression.hpp>
#include <ensmallen.hpp>
#include <memory>
#include <set>
Include dependency graph for softmax_regression_main.cpp:
This graph shows which files directly or indirectly include this file:

Functions

 BINDING_NAME ("Softmax Regression")
 
 BINDING_SHORT_DESC ("An implementation of softmax regression for classification, which is a " "multiclass generalization of logistic regression. Given labeled data, a " "softmax regression model can be trained and saved for future use, or, a " "pre-trained softmax regression model can be used for classification of " "new points.")
 
 BINDING_LONG_DESC ("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 "+PRINT_PARAM_STRING("training")+" parameter and their" " corresponding labels with the "+PRINT_PARAM_STRING("labels")+" parameter. The number of classes can be manually specified with the "+PRINT_PARAM_STRING("number_of_classes")+" parameter, and the maximum "+"number of iterations of the L-BFGS optimizer can be specified with the "+PRINT_PARAM_STRING("max_iterations")+" parameter. The L2 regularization " "constant can be specified with the "+PRINT_PARAM_STRING("lambda")+" parameter and if an intercept term is not desired in the model, the "+PRINT_PARAM_STRING("no_intercept")+" parameter can be specified." "\" "The trained model can be saved with the "+PRINT_PARAM_STRING("output_model")+" output parameter. If training is not" " desired, but only testing is, a model can be loaded with the "+PRINT_PARAM_STRING("input_model")+" parameter. At the current time, a " "loaded model cannot be trained further, so specifying both "+PRINT_PARAM_STRING("input_model")+" and "+PRINT_PARAM_STRING("training")+" is not allowed." "\" "The program is also able to evaluate a model on test data. A test dataset" " can be specified with the "+PRINT_PARAM_STRING("test")+" parameter. " "Class predictions can be saved with the "+PRINT_PARAM_STRING("predictions")+" output parameter. If labels are " "specified for the test data with the "+PRINT_PARAM_STRING("test_labels")+" parameter, then the program will " "print the accuracy of the predictions on the given test set and its " "corresponding labels.")
 
 BINDING_EXAMPLE ("For example, to train a softmax regression model on the data "+PRINT_DATASET("dataset")+" with labels "+PRINT_DATASET("labels")+" with a maximum of 1000 iterations for training, saving the trained model " "to "+PRINT_MODEL("sr_model")+", the following command can be used: " "\"+PRINT_CALL("softmax_regression", "training", "dataset", "labels", "labels", "output_model", "sr_model")+"\" "Then, to use "+PRINT_MODEL("sr_model")+" to classify the test points " "in "+PRINT_DATASET("test_points")+", saving the output predictions to" " "+PRINT_DATASET("predictions")+", the following command can be used:" "\"+PRINT_CALL("softmax_regression", "input_model", "sr_model", "test", "test_points", "predictions", "predictions"))
 
 BINDING_SEE_ALSO ("@logistic_regression", "#logistic_regression")
 
 BINDING_SEE_ALSO ("@random_forest", "#random_forest")
 
 BINDING_SEE_ALSO ("Multinomial logistic regression (softmax regression) on " "Wikipedia", "https://en.wikipedia.org/wiki/Multinomial_logistic_regression")
 
 BINDING_SEE_ALSO ("mlpack::regression::SoftmaxRegression C++ class " "documentation", "@doxygen/classmlpack_1_1regression_1_1SoftmaxRegression.html")
 
 PARAM_MATRIX_IN ("training", "A matrix containing the training set (the matrix " "of predictors, X).", "t")
 
 PARAM_UROW_IN ("labels", "A matrix containing labels (0 or 1) for the points " "in the training set (y). The labels must order as a row.", "l")
 
 PARAM_MODEL_IN (SoftmaxRegression, "input_model", "File containing existing " "model (parameters).", "m")
 
 PARAM_MODEL_OUT (SoftmaxRegression, "output_model", "File to save trained " "softmax regression model to.", "M")
 
 PARAM_MATRIX_IN ("test", "Matrix containing test dataset.", "T")
 
 PARAM_UROW_OUT ("predictions", "Matrix to save predictions for test dataset " "into.", "p")
 
 PARAM_UROW_IN ("test_labels", "Matrix containing test labels.", "L")
 
 PARAM_INT_IN ("max_iterations", "Maximum number of iterations before " "termination.", "n", 400)
 
 PARAM_INT_IN ("number_of_classes", "Number of classes for classification; if " "unspecified (or 0), the number of classes found in the labels will be " "used.", "c", 0)
 
 PARAM_DOUBLE_IN ("lambda", "L2-regularization constant", "r", 0.0001)
 
 PARAM_FLAG ("no_intercept", "Do not add the intercept term to the model.", "N")
 
size_t CalculateNumberOfClasses (const size_t numClasses, const arma::Row< size_t > &trainLabels)
 
template<typename Model >
void TestClassifyAcc (const size_t numClasses, const Model &model)
 
template<typename Model >
Model * TrainSoftmax (const size_t maxIterations)
 

Detailed Description

Main program for softmax regression.

mlpack is free software; you may redistribute it and/or modify it under the terms of the 3-clause BSD license. You should have received a copy of the 3-clause BSD license along with mlpack. If not, see http://www.opensource.org/licenses/BSD-3-Clause for more information.