12 #ifndef MLPACK_METHODS_SOFTMAX_REGRESSION_SOFTMAX_REGRESSION_HPP 13 #define MLPACK_METHODS_SOFTMAX_REGRESSION_SOFTMAX_REGRESSION_HPP 16 #include <ensmallen.hpp> 21 namespace regression {
72 const size_t numClasses = 0,
73 const bool fitIntercept =
false);
90 template<
typename OptimizerType = ens::L_BFGS>
92 const arma::Row<size_t>& labels,
93 const size_t numClasses,
94 const double lambda = 0.0001,
95 const bool fitIntercept =
false,
96 OptimizerType optimizer = OptimizerType());
107 void Classify(
const arma::mat& dataset, arma::Row<size_t>& labels)
const;
117 template<
typename VecType>
118 size_t Classify(
const VecType& point)
const;
131 void Classify(
const arma::mat& dataset,
132 arma::Row<size_t>& labels,
133 arma::mat& probabilites)
const;
141 void Classify(
const arma::mat& dataset,
142 arma::mat& probabilities)
const;
153 const arma::Row<size_t>& labels)
const;
165 template<
typename OptimizerType = ens::L_BFGS>
166 double Train(
const arma::mat& data,
167 const arma::Row<size_t>& labels,
168 const size_t numClasses,
169 OptimizerType optimizer = OptimizerType());
191 {
return fitIntercept ? parameters.n_cols - 1 :
197 template<
typename Archive>
200 ar & BOOST_SERIALIZATION_NVP(parameters);
201 ar & BOOST_SERIALIZATION_NVP(numClasses);
202 ar & BOOST_SERIALIZATION_NVP(lambda);
203 ar & BOOST_SERIALIZATION_NVP(fitIntercept);
208 arma::mat parameters;
221 #include "softmax_regression_impl.hpp" SoftmaxRegression(const size_t inputSize=0, const size_t numClasses=0, const bool fitIntercept=false)
Initialize the SoftmaxRegression without performing training.
The core includes that mlpack expects; standard C++ includes and Armadillo.
double Lambda() const
Gets the regularization parameter.
bool FitIntercept() const
Gets the intercept term flag. We can't change this after training.
size_t NumClasses() const
Gets the number of classes.
double Train(const arma::mat &data, const arma::Row< size_t > &labels, const size_t numClasses, OptimizerType optimizer=OptimizerType())
Train the softmax regression with the given training data.
Softmax Regression is a classifier which can be used for classification when the data available can t...
arma::mat & Parameters()
Get the model parameters.
void serialize(Archive &ar, const unsigned int)
Serialize the SoftmaxRegression model.
double ComputeAccuracy(const arma::mat &testData, const arma::Row< size_t > &labels) const
Computes accuracy of the learned model given the feature data and the labels associated with each dat...
double & Lambda()
Sets the regularization parameter.
size_t FeatureSize() const
Gets the features size of the training data.
size_t & NumClasses()
Sets the number of classes.
void Classify(const arma::mat &dataset, arma::Row< size_t > &labels) const
Classify the given points, returning the predicted labels for each point.
const arma::mat & Parameters() const
Get the model parameters.