SimpleCV< MLAlgorithm, Metric, MatType, PredictionsType, WeightsType > Class Template Reference

SimpleCV splits data into two sets - training and validation sets - and then runs training on the training set and evaluates performance on the validation set. More...

Public Member Functions

template
<
typename
MatInType
,
typename
PredictionsInType
>
 SimpleCV (const double validationSize, MatInType &&xs, PredictionsInType &&ys)
 This constructor can be used for regression algorithms and for binary classification algorithms. More...

 
template
<
typename
MatInType
,
typename
PredictionsInType
>
 SimpleCV (const double validationSize, MatInType &&xs, PredictionsInType &&ys, const size_t numClasses)
 This constructor can be used for multiclass classification algorithms. More...

 
template
<
typename
MatInType
,
typename
PredictionsInType
>
 SimpleCV (const double validationSize, MatInType &&xs, const data::DatasetInfo &datasetInfo, PredictionsInType &&ys, const size_t numClasses)
 This constructor can be used for multiclass classification algorithms that can take a data::DatasetInfo parameter. More...

 
template
<
typename
MatInType
,
typename
PredictionsInType
,
typename
WeightsInType
>
 SimpleCV (const double validationSize, MatInType &&xs, PredictionsInType &&ys, WeightsInType &&weights)
 This constructor can be used for regression and binary classification algorithms that support weighted learning. More...

 
template
<
typename
MatInType
,
typename
PredictionsInType
,
typename
WeightsInType
>
 SimpleCV (const double validationSize, MatInType &&xs, PredictionsInType &&ys, const size_t numClasses, WeightsInType &&weights)
 This constructor can be used for multiclass classification algorithms that support weighted learning. More...

 
template
<
typename
MatInType
,
typename
PredictionsInType
,
typename
WeightsInType
>
 SimpleCV (const double validationSize, MatInType &&xs, const data::DatasetInfo &datasetInfo, PredictionsInType &&ys, const size_t numClasses, WeightsInType &&weights)
 This constructor can be used for multiclass classification algorithms that can take a data::DatasetInfo parameter and support weighted learning. More...

 
template<typename... MLAlgorithmArgs>
double Evaluate (const MLAlgorithmArgs &... args)
 Train on the training set and assess performance on the validation set by using the class Metric. More...

 
MLAlgorithm & Model ()
 Access and modify the last trained model. More...

 

Detailed Description


template<typename MLAlgorithm, typename Metric, typename MatType = arma::mat, typename PredictionsType = typename MetaInfoExtractor<MLAlgorithm, MatType>::PredictionsType, typename WeightsType = typename MetaInfoExtractor<MLAlgorithm, MatType, PredictionsType>::WeightsType>
class mlpack::cv::SimpleCV< MLAlgorithm, Metric, MatType, PredictionsType, WeightsType >

SimpleCV splits data into two sets - training and validation sets - and then runs training on the training set and evaluates performance on the validation set.

To construct a SimpleCV object you need to pass the validationSize parameter and arguments that specify data. For example, SoftmaxRegression can be validated in the following way.

// 100-point 5-dimensional random dataset.
arma::mat data = arma::randu<arma::mat>(5, 100);
// Random labels in the [0, 4] interval.
arma::Row<size_t> labels =
arma::randi<arma::Row<size_t>>(100, arma::distr_param(0, 4));
size_t numClasses = 5;
double validationSize = 0.2;
SimpleCV<SoftmaxRegression<>, Accuracy> cv(validationSize, data, labels,
numClasses);
double lambda = 0.1;
double softmaxAccuracy = cv.Evaluate(lambda);

In the example above, 80% of the passed dataset will be used for training, and remaining 20% will be used for calculating the accuracy metric.

Template Parameters
MLAlgorithmA machine learning algorithm.
MetricA metric to assess the quality of a trained model.
MatTypeThe type of data.
PredictionsTypeThe type of predictions (should be passed when the predictions type is a template parameter in Train methods of the given MLAlgorithm; arma::Row<size_t> will be used otherwise).
WeightsTypeThe type of weights (should be passed when weighted learning is supported, and the weights type is a template parameter in Train methods of the given MLAlgorithm; arma::vec will be used otherwise).

Definition at line 68 of file simple_cv.hpp.

Constructor & Destructor Documentation

◆ SimpleCV() [1/6]

SimpleCV ( const double  validationSize,
MatInType &&  xs,
PredictionsInType &&  ys 
)

This constructor can be used for regression algorithms and for binary classification algorithms.

Parameters
validationSizeA proportion (between 0 and 1) of data used as a validation set.
xsData points to cross-validate on.
ysPredictions (labels for classification algorithms and responses for regression algorithms) for each data point.
Template Parameters
MatInTypeA type that can be converted to MatType.
PredictionsInTypeA type that can be converted to PredictionsType.

◆ SimpleCV() [2/6]

SimpleCV ( const double  validationSize,
MatInType &&  xs,
PredictionsInType &&  ys,
const size_t  numClasses 
)

This constructor can be used for multiclass classification algorithms.

Parameters
validationSizeA proportion (between 0 and 1) of data used as a validation set.
xsData points to cross-validate on.
ysLabels for each data point.
numClassesNumber of classes in the dataset.
Template Parameters
MatInTypeA type that can be converted to MatType.
PredictionsInTypeA type that can be converted to PredictionsType.

◆ SimpleCV() [3/6]

SimpleCV ( const double  validationSize,
MatInType &&  xs,
const data::DatasetInfo datasetInfo,
PredictionsInType &&  ys,
const size_t  numClasses 
)

This constructor can be used for multiclass classification algorithms that can take a data::DatasetInfo parameter.

Parameters
validationSizeA proportion (between 0 and 1) of data used as a validation set.
xsData points to cross-validate on.
datasetInfoType information for each dimension of the dataset.
ysLabels for each data point.
numClassesNumber of classes in the dataset.
Template Parameters
MatInTypeA type that can be converted to MatType.
PredictionsInTypeA type that can be converted to PredictionsType.

◆ SimpleCV() [4/6]

SimpleCV ( const double  validationSize,
MatInType &&  xs,
PredictionsInType &&  ys,
WeightsInType &&  weights 
)

This constructor can be used for regression and binary classification algorithms that support weighted learning.

Parameters
validationSizeA proportion (between 0 and 1) of data used as a validation set.
xsData points to cross-validate on.
ysPredictions (labels for classification algorithms and responses for regression algorithms) for each data point.
weightsObservation weights (for boosting).
Template Parameters
MatInTypeA type that can be converted to MatType.
PredictionsInTypeA type that can be converted to PredictionsType.
WeightsInTypeA type that can be converted to WeightsType.

◆ SimpleCV() [5/6]

SimpleCV ( const double  validationSize,
MatInType &&  xs,
PredictionsInType &&  ys,
const size_t  numClasses,
WeightsInType &&  weights 
)

This constructor can be used for multiclass classification algorithms that support weighted learning.

Parameters
validationSizeA proportion (between 0 and 1) of data used as a validation set.
xsData points to cross-validate on.
ysLabels for each data point.
numClassesNumber of classes in the dataset.
weightsObservation weights (for boosting).
Template Parameters
MatInTypeA type that can be converted to MatType.
PredictionsInTypeA type that can be converted to PredictionsType.
WeightsInTypeA type that can be converted to WeightsType.

◆ SimpleCV() [6/6]

SimpleCV ( const double  validationSize,
MatInType &&  xs,
const data::DatasetInfo datasetInfo,
PredictionsInType &&  ys,
const size_t  numClasses,
WeightsInType &&  weights 
)

This constructor can be used for multiclass classification algorithms that can take a data::DatasetInfo parameter and support weighted learning.

Parameters
validationSizeA proportion (between 0 and 1) of data used as a validation set.
xsData points to cross-validate on.
datasetInfoType information for each dimension of the dataset.
ysLabels for each data point.
numClassesNumber of classes in the dataset.
weightsObservation weights (for boosting).
Template Parameters
MatInTypeA type that can be converted to MatType.
PredictionsInTypeA type that can be converted to PredictionsType.
WeightsInTypeA type that can be converted to WeightsType.

Member Function Documentation

◆ Evaluate()

double Evaluate ( const MLAlgorithmArgs &...  args)

Train on the training set and assess performance on the validation set by using the class Metric.

Parameters
argsArguments for the given MLAlgorithm taken by its constructor (in addition to the passed ones in the SimpleCV constructor).

◆ Model()

MLAlgorithm& Model ( )

Access and modify the last trained model.


The documentation for this class was generated from the following file:
  • /home/ryan/src/mlpack.org/_src/mlpack-git/src/mlpack/core/cv/simple_cv.hpp