[−][src]Trait opencv::ml::StatModel
Base class for statistical models in OpenCV ML.
Required methods
fn as_raw_StatModel(&self) -> *mut c_void
Provided methods
fn get_var_count(&self) -> Result<i32>
Returns the number of variables in training samples
fn empty(&self) -> Result<bool>
fn is_trained(&self) -> Result<bool>
Returns true if the model is trained
fn is_classifier(&self) -> Result<bool>
Returns true if the model is classifier
fn train_with_data(
&mut self,
train_data: &PtrOfTrainData,
flags: i32
) -> Result<bool>
&mut self,
train_data: &PtrOfTrainData,
flags: i32
) -> Result<bool>
Trains the statistical model
Parameters
- trainData: training data that can be loaded from file using TrainData::loadFromCSV or created with TrainData::create.
- flags: optional flags, depending on the model. Some of the models can be updated with the new training samples, not completely overwritten (such as NormalBayesClassifier or ANN_MLP).
C++ default parameters
- flags: 0
fn train(
&mut self,
samples: &dyn ToInputArray,
layout: i32,
responses: &dyn ToInputArray
) -> Result<bool>
&mut self,
samples: &dyn ToInputArray,
layout: i32,
responses: &dyn ToInputArray
) -> Result<bool>
Trains the statistical model
Parameters
- samples: training samples
- layout: See ml::SampleTypes.
- responses: vector of responses associated with the training samples.
fn calc_error(
&self,
data: &PtrOfTrainData,
test: bool,
resp: &mut dyn ToOutputArray
) -> Result<f32>
&self,
data: &PtrOfTrainData,
test: bool,
resp: &mut dyn ToOutputArray
) -> Result<f32>
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%).
fn predict(
&self,
samples: &dyn ToInputArray,
results: &mut dyn ToOutputArray,
flags: i32
) -> Result<f32>
&self,
samples: &dyn ToInputArray,
results: &mut dyn ToOutputArray,
flags: i32
) -> Result<f32>
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