Please note that the class only specifies the interface of training data, but not implementation. All the statistical model classes in ml module accepts Ptr<TrainData> as parameter. In other words, you can create your own class derived from TrainData and pass smart pointer to the instance of this class into StatModel::train.
matrix of responses. If the responses are scalar, they should be stored as a single row or as a single column. The matrix should have type CV_32F or CV_32S (in the former case the responses are considered as ordered by default; in the latter case - as categorical)
varIdx
vector specifying which variables to use for training. It can be an integer vector (CV_32S) containing 0-based variable indices or byte vector (CV_8U) containing a mask of active variables.
sampleIdx
vector specifying which samples to use for training. It can be an integer vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask of training samples.
virtual Mat cv::ml::TrainData::getTestSampleWeights
(
)
const
pure virtual
Python:
cv.ml.TrainData.getTestSampleWeights(
) ->
retval
getTrainNormCatResponses()
virtual Mat cv::ml::TrainData::getTrainNormCatResponses
(
)
const
pure virtual
Python:
cv.ml.TrainData.getTrainNormCatResponses(
) ->
retval
Returns the vector of normalized categorical responses.
The function returns vector of responses. Each response is integer from 0 to <number of classes>-1. The actual label value can be retrieved then from the class label vector, see TrainData::getClassLabels.
The requested layout. If it's different from the initial one, the matrix is transposed. See ml::SampleTypes.
compressSamples
if true, the function returns only the training samples (specified by sampleIdx)
compressVars
if true, the function returns the shorter training samples, containing only the active variables.
In current implementation the function tries to avoid physical data copying and returns the matrix stored inside TrainData (unless the transposition or compression is needed).
getTrainSampleWeights()
virtual Mat cv::ml::TrainData::getTrainSampleWeights
Reads the dataset from a .csv file and returns the ready-to-use training data.
Parameters
filename
The input file name
headerLineCount
The number of lines in the beginning to skip; besides the header, the function also skips empty lines and lines starting with #
responseStartIdx
Index of the first output variable. If -1, the function considers the last variable as the response
responseEndIdx
Index of the last output variable + 1. If -1, then there is single response variable at responseStartIdx.
varTypeSpec
The optional text string that specifies the variables' types. It has the format . That is, variables from (inclusive range), , ... are considered ordered and , ... are considered as categorical. The range should cover all the variables. If varTypeSpec is not specified, then algorithm uses the following rules:
missingValue()
static float cv::ml::TrainData::missingValue
(
)
inlinestatic
setTrainTestSplit()
virtual void cv::ml::TrainData::setTrainTestSplit
(
int
count,
bool
shuffle = true )
pure virtual
Python:
cv.ml.TrainData.setTrainTestSplit(
count[, shuffle]
) ->
None
Splits the training data into the training and test parts.
Splits the training data into the training and test parts.
The function selects a subset of specified relative size and then returns it as the training set. If the function is not called, all the data is used for training. Please, note that for each of TrainData::getTrain* there is corresponding TrainData::getTest*, so that the test subset can be retrieved and processed as well.
optional vector with weights for each sample. It should have CV_32F type.
varType
optional vector of type CV_8U and size <number_of_variables_in_samples> + <number_of_variables_in_responses>, containing types of each input and output variable. See ml::VariableTypes.
all input variables are considered ordered by default. If some column contains has non- numerical values, e.g. 'apple', 'pear', 'apple', 'apple', 'mango', the corresponding variable is considered categorical.
if there are several output variables, they are all considered as ordered. Error is reported when non-numerical values are used.
if there is a single output variable, then if its values are non-numerical or are all integers, then it's considered categorical. Otherwise, it's considered ordered.
delimiter
The character used to separate values in each line.
missch
The character used to specify missing measurements. It should not be a digit. Although it's a non-numerical value, it surely does not affect the decision of whether the variable ordered or categorical.