Package org.opencv.ml
Class TrainData
- java.lang.Object
- 
- org.opencv.ml.TrainData
 
- 
 public class TrainData extends java.lang.ObjectClass 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: REF: ml_intro_data
- 
- 
Field SummaryFields Modifier and Type Field Description protected longnativeObj
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedTrainData(long addr)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static TrainData__fromPtr__(long addr)static TrainDatacreate(Mat samples, int layout, Mat responses)Creates training data from in-memory arrays.static TrainDatacreate(Mat samples, int layout, Mat responses, Mat varIdx)Creates training data from in-memory arrays.static TrainDatacreate(Mat samples, int layout, Mat responses, Mat varIdx, Mat sampleIdx)Creates training data from in-memory arrays.static TrainDatacreate(Mat samples, int layout, Mat responses, Mat varIdx, Mat sampleIdx, Mat sampleWeights)Creates training data from in-memory arrays.static TrainDatacreate(Mat samples, int layout, Mat responses, Mat varIdx, Mat sampleIdx, Mat sampleWeights, Mat varType)Creates training data from in-memory arrays.protected voidfinalize()intgetCatCount(int vi)MatgetCatMap()MatgetCatOfs()MatgetClassLabels()Returns the vector of class labels The function returns vector of unique labels occurred in the responses.MatgetDefaultSubstValues()intgetLayout()MatgetMissing()intgetNAllVars()voidgetNames(java.util.List<java.lang.String> names)Returns vector of symbolic names captured in loadFromCSV()longgetNativeObjAddr()MatgetNormCatResponses()intgetNSamples()intgetNTestSamples()intgetNTrainSamples()intgetNVars()MatgetResponses()intgetResponseType()voidgetSample(Mat varIdx, int sidx, float buf)MatgetSamples()MatgetSampleWeights()static MatgetSubMatrix(Mat matrix, Mat idx, int layout)Extract from matrix rows/cols specified by passed indexes.static MatgetSubVector(Mat vec, Mat idx)Extract from 1D vector elements specified by passed indexes.MatgetTestNormCatResponses()MatgetTestResponses()MatgetTestSampleIdx()MatgetTestSamples()Returns matrix of test samplesMatgetTestSampleWeights()MatgetTrainNormCatResponses()Returns the vector of normalized categorical responses The function returns vector of responses.MatgetTrainResponses()Returns the vector of responses The function returns ordered or the original categorical responses.MatgetTrainSampleIdx()MatgetTrainSamples()Returns matrix of train samples transposed.MatgetTrainSamples(int layout)Returns matrix of train samplesMatgetTrainSamples(int layout, boolean compressSamples)Returns matrix of train samplesMatgetTrainSamples(int layout, boolean compressSamples, boolean compressVars)Returns matrix of train samplesMatgetTrainSampleWeights()voidgetValues(int vi, Mat sidx, float values)MatgetVarIdx()MatgetVarSymbolFlags()MatgetVarType()voidsetTrainTestSplit(int count)Splits the training data into the training and test parts SEE: TrainData::setTrainTestSplitRatiovoidsetTrainTestSplit(int count, boolean shuffle)Splits the training data into the training and test parts SEE: TrainData::setTrainTestSplitRatiovoidsetTrainTestSplitRatio(double ratio)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.voidsetTrainTestSplitRatio(double ratio, boolean shuffle)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.voidshuffleTrainTest()
 
- 
- 
- 
Method Detail- 
getNativeObjAddrpublic long getNativeObjAddr() 
 - 
__fromPtr__public static TrainData __fromPtr__(long addr) 
 - 
getCatMappublic Mat getCatMap() 
 - 
getCatOfspublic Mat getCatOfs() 
 - 
getClassLabelspublic Mat getClassLabels() Returns the vector of class labels The function returns vector of unique labels occurred in the responses.- Returns:
- automatically generated
 
 - 
getDefaultSubstValuespublic Mat getDefaultSubstValues() 
 - 
getMissingpublic Mat getMissing() 
 - 
getNormCatResponsespublic Mat getNormCatResponses() 
 - 
getResponsespublic Mat getResponses() 
 - 
getSampleWeightspublic Mat getSampleWeights() 
 - 
getSamplespublic Mat getSamples() 
 - 
getSubMatrixpublic static Mat getSubMatrix(Mat matrix, Mat idx, int layout) 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)
- Returns:
- automatically generated
 
 - 
getSubVectorpublic static Mat getSubVector(Mat vec, Mat idx) 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
- Returns:
- automatically generated
 
 - 
getTestNormCatResponsespublic Mat getTestNormCatResponses() 
 - 
getTestResponsespublic Mat getTestResponses() 
 - 
getTestSampleIdxpublic Mat getTestSampleIdx() 
 - 
getTestSampleWeightspublic Mat getTestSampleWeights() 
 - 
getTestSamplespublic Mat getTestSamples() Returns matrix of test samples- Returns:
- automatically generated
 
 - 
getTrainNormCatResponsespublic Mat getTrainNormCatResponses() Returns the vector of normalized categorical responses The function returns vector of responses. Each response is integer from0to `<number of classes>-1`. The actual label value can be retrieved then from the class label vector, see TrainData::getClassLabels.- Returns:
- automatically generated
 
 - 
getTrainResponsespublic Mat getTrainResponses() Returns the vector of responses The function returns ordered or the original categorical responses. Usually it's used in regression algorithms.- Returns:
- automatically generated
 
 - 
getTrainSampleIdxpublic Mat getTrainSampleIdx() 
 - 
getTrainSampleWeightspublic Mat getTrainSampleWeights() 
 - 
getTrainSamplespublic Mat getTrainSamples(int layout, boolean compressSamples, boolean compressVars) Returns matrix of train samples- Parameters:
- layout- The requested layout. If it's different from the initial one, the matrix is transposed. See ml::SampleTypes.
- compressSamples- if true, the function returns only the training samples (specified by sampleIdx)
- compressVars- if true, the function returns the shorter training samples, containing only the active variables. In current implementation the function tries to avoid physical data copying and returns the matrix stored inside TrainData (unless the transposition or compression is needed).
- Returns:
- automatically generated
 
 - 
getTrainSamplespublic Mat getTrainSamples(int layout, boolean compressSamples) Returns matrix of train samples- Parameters:
- layout- The requested layout. If it's different from the initial one, the matrix is transposed. See ml::SampleTypes.
- compressSamples- if true, the function returns only the training samples (specified by sampleIdx) the active variables. In current implementation the function tries to avoid physical data copying and returns the matrix stored inside TrainData (unless the transposition or compression is needed).
- Returns:
- automatically generated
 
 - 
getTrainSamplespublic Mat getTrainSamples(int layout) Returns matrix of train samples- Parameters:
- layout- The requested layout. If it's different from the initial one, the matrix is transposed. See ml::SampleTypes. sampleIdx) the active variables. In current implementation the function tries to avoid physical data copying and returns the matrix stored inside TrainData (unless the transposition or compression is needed).
- Returns:
- automatically generated
 
 - 
getTrainSamplespublic Mat getTrainSamples() Returns matrix of train samples transposed. See ml::SampleTypes. sampleIdx) the active variables. In current implementation the function tries to avoid physical data copying and returns the matrix stored inside TrainData (unless the transposition or compression is needed).- Returns:
- automatically generated
 
 - 
getVarIdxpublic Mat getVarIdx() 
 - 
getVarSymbolFlagspublic Mat getVarSymbolFlags() 
 - 
getVarTypepublic Mat getVarType() 
 - 
createpublic static TrainData create(Mat samples, int layout, Mat responses, Mat varIdx, Mat sampleIdx, Mat sampleWeights, Mat varType) 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.
- Returns:
- automatically generated
 
 - 
createpublic static TrainData create(Mat samples, int layout, Mat responses, Mat varIdx, Mat sampleIdx, Mat sampleWeights) 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. <number_of_variables_in_responses>`, containing types of each input and output variable. See ml::VariableTypes.
- Returns:
- automatically generated
 
 - 
createpublic static TrainData create(Mat samples, int layout, Mat responses, Mat varIdx, Mat sampleIdx) 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. <number_of_variables_in_responses>`, containing types of each input and output variable. See ml::VariableTypes.
- Returns:
- automatically generated
 
 - 
createpublic static TrainData create(Mat samples, int layout, Mat responses, Mat varIdx) 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. vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask of training samples. <number_of_variables_in_responses>`, containing types of each input and output variable. See ml::VariableTypes.
- Returns:
- automatically generated
 
 - 
createpublic static TrainData create(Mat samples, int layout, Mat responses) 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) (CV_32S) containing 0-based variable indices or byte vector (CV_8U) containing a mask of active variables. vector (CV_32S) containing 0-based sample indices or byte vector (CV_8U) containing a mask of training samples. <number_of_variables_in_responses>`, containing types of each input and output variable. See ml::VariableTypes.
- Returns:
- automatically generated
 
 - 
getCatCountpublic int getCatCount(int vi) 
 - 
getLayoutpublic int getLayout() 
 - 
getNAllVarspublic int getNAllVars() 
 - 
getNSamplespublic int getNSamples() 
 - 
getNTestSamplespublic int getNTestSamples() 
 - 
getNTrainSamplespublic int getNTrainSamples() 
 - 
getNVarspublic int getNVars() 
 - 
getResponseTypepublic int getResponseType() 
 - 
getNamespublic void getNames(java.util.List<java.lang.String> names) Returns vector of symbolic names captured in loadFromCSV()- Parameters:
- names- automatically generated
 
 - 
getSamplepublic void getSample(Mat varIdx, int sidx, float buf) 
 - 
getValuespublic void getValues(int vi, Mat sidx, float values)
 - 
setTrainTestSplitpublic void setTrainTestSplit(int count, boolean shuffle)Splits the training data into the training and test parts SEE: TrainData::setTrainTestSplitRatio- Parameters:
- count- automatically generated
- shuffle- automatically generated
 
 - 
setTrainTestSplitpublic void setTrainTestSplit(int count) Splits the training data into the training and test parts SEE: TrainData::setTrainTestSplitRatio- Parameters:
- count- automatically generated
 
 - 
setTrainTestSplitRatiopublic void setTrainTestSplitRatio(double ratio, boolean shuffle)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: TrainData::setTrainTestSplit- Parameters:
- ratio- automatically generated
- shuffle- automatically generated
 
 - 
setTrainTestSplitRatiopublic void setTrainTestSplitRatio(double ratio) 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: TrainData::setTrainTestSplit- Parameters:
- ratio- automatically generated
 
 - 
shuffleTrainTestpublic void shuffleTrainTest() 
 - 
finalizeprotected void finalize() throws java.lang.Throwable- Overrides:
- finalizein class- java.lang.Object
- Throws:
- java.lang.Throwable
 
 
- 
 
-