Package org.opencv.ml
Class StatModel
- java.lang.Object
- 
- org.opencv.core.Algorithm
- 
- org.opencv.ml.StatModel
 
 
- 
- Direct Known Subclasses:
- ANN_MLP,- DTrees,- EM,- KNearest,- LogisticRegression,- NormalBayesClassifier,- SVM,- SVMSGD
 
 public class StatModel extends Algorithm Base class for statistical models in OpenCV ML.
- 
- 
Field SummaryFields Modifier and Type Field Description static intCOMPRESSED_INPUTstatic intPREPROCESSED_INPUTstatic intRAW_OUTPUTstatic intUPDATE_MODEL
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedStatModel(long addr)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StatModel__fromPtr__(long addr)floatcalcError(TrainData data, boolean test, Mat resp)Computes error on the training or test datasetbooleanempty()Returns true if the Algorithm is empty (e.g.protected voidfinalize()intgetVarCount()Returns the number of variables in training samplesbooleanisClassifier()Returns true if the model is classifierbooleanisTrained()Returns true if the model is trainedfloatpredict(Mat samples)Predicts response(s) for the provided sample(s)floatpredict(Mat samples, Mat results)Predicts response(s) for the provided sample(s)floatpredict(Mat samples, Mat results, int flags)Predicts response(s) for the provided sample(s)booleantrain(Mat samples, int layout, Mat responses)Trains the statistical modelbooleantrain(TrainData trainData)Trains the statistical modelbooleantrain(TrainData trainData, int flags)Trains the statistical model- 
Methods inherited from class org.opencv.core.Algorithmclear, getDefaultName, getNativeObjAddr, save
 
- 
 
- 
- 
- 
Field Detail- 
UPDATE_MODELpublic static final int UPDATE_MODEL - See Also:
- Constant Field Values
 
 - 
RAW_OUTPUTpublic static final int RAW_OUTPUT - See Also:
- Constant Field Values
 
 - 
COMPRESSED_INPUTpublic static final int COMPRESSED_INPUT - See Also:
- Constant Field Values
 
 - 
PREPROCESSED_INPUTpublic static final int PREPROCESSED_INPUT - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
__fromPtr__public static StatModel __fromPtr__(long addr) 
 - 
getVarCountpublic int getVarCount() Returns the number of variables in training samples- Returns:
- automatically generated
 
 - 
emptypublic boolean empty() Description copied from class:AlgorithmReturns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read
 - 
isTrainedpublic boolean isTrained() Returns true if the model is trained- Returns:
- automatically generated
 
 - 
isClassifierpublic boolean isClassifier() Returns true if the model is classifier- Returns:
- automatically generated
 
 - 
trainpublic boolean train(TrainData trainData, int flags) 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).
- Returns:
- automatically generated
 
 - 
trainpublic boolean train(TrainData trainData) Trains the statistical model- Parameters:
- trainData- training data that can be loaded from file using TrainData::loadFromCSV or created with TrainData::create. new training samples, not completely overwritten (such as NormalBayesClassifier or ANN_MLP).
- Returns:
- automatically generated
 
 - 
trainpublic boolean train(Mat samples, int layout, Mat responses) Trains the statistical model- Parameters:
- samples- training samples
- layout- See ml::SampleTypes.
- responses- vector of responses associated with the training samples.
- Returns:
- automatically generated
 
 - 
calcErrorpublic float calcError(TrainData data, boolean test, Mat resp) 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%).
- Returns:
- automatically generated
 
 - 
predictpublic float predict(Mat samples, Mat results, int flags) 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.
- Returns:
- automatically generated
 
 - 
predictpublic float predict(Mat samples, Mat results) Predicts response(s) for the provided sample(s)- Parameters:
- samples- The input samples, floating-point matrix
- results- The optional output matrix of results.
- Returns:
- automatically generated
 
 - 
predictpublic float predict(Mat samples) Predicts response(s) for the provided sample(s)- Parameters:
- samples- The input samples, floating-point matrix
- Returns:
- automatically generated
 
 
- 
 
-