pub trait StatModelConst: AlgorithmTraitConst {
    fn as_raw_StatModel(&self) -> *const c_void;

    fn get_var_count(&self) -> Result<i32> { ... }
    fn empty(&self) -> Result<bool> { ... }
    fn is_trained(&self) -> Result<bool> { ... }
    fn is_classifier(&self) -> Result<bool> { ... }
    fn calc_error(
        &self,
        data: &Ptr<dyn TrainData>,
        test: bool,
        resp: &mut dyn ToOutputArray
    ) -> Result<f32> { ... } fn predict(
        &self,
        samples: &dyn ToInputArray,
        results: &mut dyn ToOutputArray,
        flags: i32
    ) -> Result<f32> { ... } }
Expand description

Base class for statistical models in OpenCV ML.

Required Methods

Provided Methods

Returns the number of variables in training samples

Returns true if the model is trained

Returns true if the model is classifier

Computes error on the training or test dataset

Parameters
  • data: the training data
  • test: if true, the error is computed over the test subset of the data, otherwise it’s computed over the training subset of the data. Please note that if you loaded a completely different dataset to evaluate already trained classifier, you will probably want not to set the test subset at all with TrainData::setTrainTestSplitRatio and specify test=false, so that the error is computed for the whole new set. Yes, this sounds a bit confusing.
  • resp: the optional output responses.

The method uses StatModel::predict to compute the error. For regression models the error is computed as RMS, for classifiers - as a percent of missclassified samples (0%-100%).

Predicts response(s) for the provided sample(s)

Parameters
  • samples: The input samples, floating-point matrix
  • results: The optional output matrix of results.
  • flags: The optional flags, model-dependent. See cv::ml::StatModel::Flags.
C++ default parameters
  • results: noArray()
  • flags: 0

Implementors