Struct TrainData

Source
pub struct TrainData { /* private fields */ }
Expand description

Class encapsulating training data.

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.

§See also

[ml_intro_data]

Implementations§

Source§

impl TrainData

Source

pub fn missing_value() -> Result<f32>

Source

pub fn get_sub_vector( vec: &impl MatTraitConst, idx: &impl MatTraitConst, ) -> Result<Mat>

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
Source

pub fn get_sub_matrix( matrix: &impl MatTraitConst, idx: &impl MatTraitConst, layout: i32, ) -> Result<Mat>

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)
Source

pub fn load_from_csv( filename: &str, header_line_count: i32, response_start_idx: i32, response_end_idx: i32, var_type_spec: &str, delimiter: char, missch: char, ) -> Result<Ptr<TrainData>>

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: ‘?’
Source

pub fn load_from_csv_def( filename: &str, header_line_count: i32, ) -> Result<Ptr<TrainData>>

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.

§Note

This alternative version of TrainData::load_from_csv function uses the following default values for its arguments:

  • response_start_idx: -1
  • response_end_idx: -1
  • var_type_spec: String()
  • delimiter: ‘,’
  • missch: ‘?’
Source

pub fn create( samples: &impl ToInputArray, layout: i32, responses: &impl ToInputArray, var_idx: &impl ToInputArray, sample_idx: &impl ToInputArray, sample_weights: &impl ToInputArray, var_type: &impl ToInputArray, ) -> Result<Ptr<TrainData>>

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()
Source

pub fn create_def( samples: &impl ToInputArray, layout: i32, responses: &impl ToInputArray, ) -> Result<Ptr<TrainData>>

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.
§Note

This alternative version of TrainData::create function uses the following default values for its arguments:

  • var_idx: noArray()
  • sample_idx: noArray()
  • sample_weights: noArray()
  • var_type: noArray()

Trait Implementations§

Source§

impl Boxed for TrainData

Source§

unsafe fn from_raw(ptr: <TrainData as OpenCVFromExtern>::ExternReceive) -> Self

Wrap the specified raw pointer Read more
Source§

fn into_raw(self) -> <TrainData as OpenCVTypeExternContainer>::ExternSendMut

Return the underlying raw pointer while consuming this wrapper. Read more
Source§

fn as_raw(&self) -> <TrainData as OpenCVTypeExternContainer>::ExternSend

Return the underlying raw pointer. Read more
Source§

fn as_raw_mut( &mut self, ) -> <TrainData as OpenCVTypeExternContainer>::ExternSendMut

Return the underlying mutable raw pointer Read more
Source§

impl Debug for TrainData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for TrainData

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl TrainDataTrait for TrainData

Source§

fn as_raw_mut_TrainData(&mut self) -> *mut c_void

Source§

fn set_train_test_split(&mut self, count: i32, shuffle: bool) -> Result<()>

Splits the training data into the training and test parts Read more
Source§

fn set_train_test_split_def(&mut self, count: i32) -> Result<()>

Splits the training data into the training and test parts Read more
Source§

fn set_train_test_split_ratio( &mut self, ratio: f64, shuffle: bool, ) -> Result<()>

Splits the training data into the training and test parts Read more
Source§

fn set_train_test_split_ratio_def(&mut self, ratio: f64) -> Result<()>

Splits the training data into the training and test parts Read more
Source§

fn shuffle_train_test(&mut self) -> Result<()>

Source§

impl TrainDataTraitConst for TrainData

Source§

fn as_raw_TrainData(&self) -> *const c_void

Source§

fn get_layout(&self) -> Result<i32>

Source§

fn get_n_train_samples(&self) -> Result<i32>

Source§

fn get_n_test_samples(&self) -> Result<i32>

Source§

fn get_n_samples(&self) -> Result<i32>

Source§

fn get_n_vars(&self) -> Result<i32>

Source§

fn get_n_all_vars(&self) -> Result<i32>

Source§

fn get_sample( &self, var_idx: &impl ToInputArray, sidx: i32, buf: &mut f32, ) -> Result<()>

Source§

fn get_samples(&self) -> Result<Mat>

Source§

fn get_missing(&self) -> Result<Mat>

Source§

fn get_train_samples( &self, layout: i32, compress_samples: bool, compress_vars: bool, ) -> Result<Mat>

Returns matrix of train samples Read more
Source§

fn get_train_samples_def(&self) -> Result<Mat>

Returns matrix of train samples Read more
Source§

fn get_train_responses(&self) -> Result<Mat>

Returns the vector of responses Read more
Source§

fn get_train_norm_cat_responses(&self) -> Result<Mat>

Returns the vector of normalized categorical responses Read more
Source§

fn get_test_responses(&self) -> Result<Mat>

Source§

fn get_test_norm_cat_responses(&self) -> Result<Mat>

Source§

fn get_responses(&self) -> Result<Mat>

Source§

fn get_norm_cat_responses(&self) -> Result<Mat>

Source§

fn get_sample_weights(&self) -> Result<Mat>

Source§

fn get_train_sample_weights(&self) -> Result<Mat>

Source§

fn get_test_sample_weights(&self) -> Result<Mat>

Source§

fn get_var_idx(&self) -> Result<Mat>

Source§

fn get_var_type(&self) -> Result<Mat>

Source§

fn get_var_symbol_flags(&self) -> Result<Mat>

Source§

fn get_response_type(&self) -> Result<i32>

Source§

fn get_train_sample_idx(&self) -> Result<Mat>

Source§

fn get_test_sample_idx(&self) -> Result<Mat>

Source§

fn get_values( &self, vi: i32, sidx: &impl ToInputArray, values: &mut f32, ) -> Result<()>

Source§

fn get_norm_cat_values( &self, vi: i32, sidx: &impl ToInputArray, values: &mut i32, ) -> Result<()>

Source§

fn get_default_subst_values(&self) -> Result<Mat>

Source§

fn get_cat_count(&self, vi: i32) -> Result<i32>

Source§

fn get_class_labels(&self) -> Result<Mat>

Returns the vector of class labels Read more
Source§

fn get_cat_ofs(&self) -> Result<Mat>

Source§

fn get_cat_map(&self) -> Result<Mat>

Source§

fn get_test_samples(&self) -> Result<Mat>

Returns matrix of test samples
Source§

fn get_names(&self, names: &mut Vector<String>) -> Result<()>

Returns vector of symbolic names captured in loadFromCSV()
Source§

impl Send for TrainData

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Mat> ModifyInplace for Mat
where Mat: Boxed,

Source§

unsafe fn modify_inplace<Res>( &mut self, f: impl FnOnce(&Mat, &mut Mat) -> Res, ) -> Res

Helper function to call OpenCV functions that allow in-place modification of a Mat or another similar object. By passing a mutable reference to the Mat to this function your closure will get called with the read reference and a write references to the same Mat. This is unsafe in a general case as it leads to having non-exclusive mutable access to the internal data, but it can be useful for some performance sensitive operations. One example of an OpenCV function that allows such in-place modification is imgproc::threshold. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.