pub trait TrainData: TrainDataConst {
    fn as_raw_mut_TrainData(&mut self) -> *mut c_void;

    fn set_train_test_split(&mut self, count: i32, shuffle: bool) -> Result<()> { ... }
    fn set_train_test_split_ratio(
        &mut self,
        ratio: f64,
        shuffle: bool
    ) -> Result<()> { ... } fn shuffle_train_test(&mut self) -> Result<()> { ... } }

Required Methods

Provided Methods

Splits the training data into the training and test parts

See also

TrainData::setTrainTestSplitRatio

C++ default parameters
  • shuffle: true

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.

See also

TrainData::setTrainTestSplit

C++ default parameters
  • shuffle: true

Implementations

Extract from 1D vector elements specified by passed indexes.

Parameters
  • vec: input vector (supported types: CV_32S, CV_32F, CV_64F)
  • idx: 1D index vector

Extract from matrix rows/cols specified by passed indexes.

Parameters
  • matrix: input matrix (supported types: CV_32S, CV_32F, CV_64F)
  • idx: 1D index vector
  • layout: specifies to extract rows (cv::ml::ROW_SAMPLES) or to extract columns (cv::ml::COL_SAMPLES)

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 staring 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 ord[n1-n2,n3,n4-n5,...]cat[n6,n7-n8,...]. That is, variables from n1 to n2 (inclusive range), n3, n4 to n5 … are considered ordered and n6, n7 to n8 … are considered as categorical. The range [n1..n2] + [n3] + [n4..n5] + ... + [n6] + [n7..n8] should cover all the variables. If varTypeSpec is not specified, then algorithm uses the following rules:
    • 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.

Note: If the dataset only contains input variables and no responses, use responseStartIdx = -2 and responseEndIdx = 0. The output variables vector will just contain zeros.

C++ default parameters
  • response_start_idx: -1
  • response_end_idx: -1
  • var_type_spec: String()
  • delimiter: ‘,’
  • missch: ‘?’

Creates training data from in-memory arrays.

Parameters
  • samples: matrix of samples. It should have CV_32F type.
  • layout: see ml::SampleTypes.
  • responses: 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.
  • sampleWeights: 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.
C++ default parameters
  • var_idx: noArray()
  • sample_idx: noArray()
  • sample_weights: noArray()
  • var_type: noArray()

Implementors