Class cv::ml::TrainData#
Class encapsulating training data. View details
#include <opencv2/ml.hpp>Collaboration diagram for cv::ml::TrainData:
Detailed 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
Constructor & Destructor Documentation#
~TrainData()#
Member Function Documentation#
create()#
static Ptr< TrainData > cv::ml::TrainData::create(
InputArray samples,
int layout,
InputArray responses,
InputArray varIdx = noArray(),
InputArray sampleIdx = noArray(),
InputArray sampleWeights = noArray(),
InputArray varType = noArray() )
Python:
cv.ml.TrainData.create(samples, layout, responses[, varIdx[, sampleIdx[, sampleWeights[, varType]]]]) -> retval
cv.ml.TrainData_create(samples, layout, responses[, varIdx[, sampleIdx[, sampleWeights[, varType]]]]) -> retval
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.
Here is the call graph for this function:
getSubMatrix()#
static Mat cv::ml::TrainData::getSubMatrix(
const Mat & matrix,
const Mat & idx,
int layout )
Python:
cv.ml.TrainData.getSubMatrix(matrix, idx, layout) -> retval
cv.ml.TrainData_getSubMatrix(matrix, idx, layout) -> retval
Extract from matrix rows/cols specified by passed indexes.
Parameters
matrix— input matrix (supported types: CV_32S, CV_32F, CV_64F)idx— 1D index vectorlayout— specifies to extract rows (cv::ml::ROW_SAMPLES) or to extract columns (cv::ml::COL_SAMPLES)
getSubVector()#
static Mat cv::ml::TrainData::getSubVector(
const Mat & vec,
const Mat & idx )
Python:
cv.ml.TrainData.getSubVector(vec, idx) -> retval
cv.ml.TrainData_getSubVector(vec, idx) -> retval
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
loadFromCSV()#
static Ptr< TrainData > cv::ml::TrainData::loadFromCSV(
const String & filename,
int headerLineCount,
int responseStartIdx = -1,
int responseEndIdx = -1,
const String & varTypeSpec = String(),
char delimiter = ‘,’,
char missch = ‘?’ )
Reads the dataset from a .csv file and returns the ready-to-use training data.
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.
Parameters
filename— The input file nameheaderLineCount— The number of lines in the beginning to skip; besides the header, the function also skips empty lines and lines starting with#responseStartIdx— Index of the first output variable. If -1, the function considers the last variable as the responseresponseEndIdx— 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 formatord[n1-n2,n3,n4-n5,...]cat[n6,n7-n8,...]. That is, variables fromn1 to n2(inclusive range),n3,n4 to n5… are considered ordered andn6,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.
missingValue()#
static float cv::ml::TrainData::missingValue()
getCatCount()#
int cv::ml::TrainData::getCatCount(int vi)
Python:
cv.ml.TrainData.getCatCount(vi) -> retval
getCatMap()#
Mat cv::ml::TrainData::getCatMap()
Python:
cv.ml.TrainData.getCatMap() -> retval
getCatOfs()#
Mat cv::ml::TrainData::getCatOfs()
Python:
cv.ml.TrainData.getCatOfs() -> retval
getClassLabels()#
Mat cv::ml::TrainData::getClassLabels()
Python:
cv.ml.TrainData.getClassLabels() -> retval
Returns the vector of class labels.
The function returns vector of unique labels occurred in the responses.
getDefaultSubstValues()#
Mat cv::ml::TrainData::getDefaultSubstValues()
Python:
cv.ml.TrainData.getDefaultSubstValues() -> retval
getLayout()#
int cv::ml::TrainData::getLayout()
Python:
cv.ml.TrainData.getLayout() -> retval
getMissing()#
Mat cv::ml::TrainData::getMissing()
Python:
cv.ml.TrainData.getMissing() -> retval
getNAllVars()#
int cv::ml::TrainData::getNAllVars()
Python:
cv.ml.TrainData.getNAllVars() -> retval
getNames()#
void cv::ml::TrainData::getNames(std::vector< String > & names)
Python:
cv.ml.TrainData.getNames(names)
Returns vector of symbolic names captured in loadFromCSV()
getNormCatResponses()#
Mat cv::ml::TrainData::getNormCatResponses()
Python:
cv.ml.TrainData.getNormCatResponses() -> retval
getNormCatValues()#
void cv::ml::TrainData::getNormCatValues(
int vi,
InputArray sidx,
int * values )
getNSamples()#
int cv::ml::TrainData::getNSamples()
Python:
cv.ml.TrainData.getNSamples() -> retval
getNTestSamples()#
int cv::ml::TrainData::getNTestSamples()
Python:
cv.ml.TrainData.getNTestSamples() -> retval
getNTrainSamples()#
int cv::ml::TrainData::getNTrainSamples()
Python:
cv.ml.TrainData.getNTrainSamples() -> retval
getNVars()#
int cv::ml::TrainData::getNVars()
Python:
cv.ml.TrainData.getNVars() -> retval
getResponses()#
Mat cv::ml::TrainData::getResponses()
Python:
cv.ml.TrainData.getResponses() -> retval
getResponseType()#
int cv::ml::TrainData::getResponseType()
Python:
cv.ml.TrainData.getResponseType() -> retval
getSample()#
void cv::ml::TrainData::getSample(
InputArray varIdx,
int sidx,
float * buf )
Python:
cv.ml.TrainData.getSample(varIdx, sidx, buf)
getSamples()#
Mat cv::ml::TrainData::getSamples()
Python:
cv.ml.TrainData.getSamples() -> retval
getSampleWeights()#
Mat cv::ml::TrainData::getSampleWeights()
Python:
cv.ml.TrainData.getSampleWeights() -> retval
getTestNormCatResponses()#
Mat cv::ml::TrainData::getTestNormCatResponses()
Python:
cv.ml.TrainData.getTestNormCatResponses() -> retval
getTestResponses()#
Mat cv::ml::TrainData::getTestResponses()
Python:
cv.ml.TrainData.getTestResponses() -> retval
getTestSampleIdx()#
Mat cv::ml::TrainData::getTestSampleIdx()
Python:
cv.ml.TrainData.getTestSampleIdx() -> retval
getTestSamples()#
Mat cv::ml::TrainData::getTestSamples()
Python:
cv.ml.TrainData.getTestSamples() -> retval
Returns matrix of test samples.
getTestSampleWeights()#
Mat cv::ml::TrainData::getTestSampleWeights()
Python:
cv.ml.TrainData.getTestSampleWeights() -> retval
getTrainNormCatResponses()#
Mat cv::ml::TrainData::getTrainNormCatResponses()
Python:
cv.ml.TrainData.getTrainNormCatResponses() -> retval
Returns the vector of normalized categorical responses.
The function returns vector of responses. Each response is integer from 0 to <number of classes>-1. The actual label value can be retrieved then from the class label vector, see TrainData::getClassLabels.
getTrainResponses()#
Mat cv::ml::TrainData::getTrainResponses()
Python:
cv.ml.TrainData.getTrainResponses() -> retval
Returns the vector of responses.
The function returns ordered or the original categorical responses. Usually it’s used in regression algorithms.
getTrainSampleIdx()#
Mat cv::ml::TrainData::getTrainSampleIdx()
Python:
cv.ml.TrainData.getTrainSampleIdx() -> retval
getTrainSamples()#
Mat cv::ml::TrainData::getTrainSamples(
int layout = ROW_SAMPLE,
bool compressSamples = true,
bool compressVars = true )
Python:
cv.ml.TrainData.getTrainSamples([, layout[, compressSamples[, compressVars]]]) -> retval
Returns matrix of train samples.
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).
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.
getTrainSampleWeights()#
Mat cv::ml::TrainData::getTrainSampleWeights()
Python:
cv.ml.TrainData.getTrainSampleWeights() -> retval
getValues()#
void cv::ml::TrainData::getValues(
int vi,
InputArray sidx,
float * values )
Python:
cv.ml.TrainData.getValues(vi, sidx, values)
getVarIdx()#
Mat cv::ml::TrainData::getVarIdx()
Python:
cv.ml.TrainData.getVarIdx() -> retval
getVarSymbolFlags()#
Mat cv::ml::TrainData::getVarSymbolFlags()
Python:
cv.ml.TrainData.getVarSymbolFlags() -> retval
getVarType()#
Mat cv::ml::TrainData::getVarType()
Python:
cv.ml.TrainData.getVarType() -> retval
setTrainTestSplit()#
void cv::ml::TrainData::setTrainTestSplit(
int count,
bool shuffle = true )
Python:
cv.ml.TrainData.setTrainTestSplit(count[, shuffle])
Splits the training data into the training and test parts.
See also
setTrainTestSplitRatio()#
void cv::ml::TrainData::setTrainTestSplitRatio(
double ratio,
bool shuffle = true )
Python:
cv.ml.TrainData.setTrainTestSplitRatio(ratio[, 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 also
shuffleTrainTest()#
void cv::ml::TrainData::shuffleTrainTest()
Python:
cv.ml.TrainData.shuffleTrainTest()
Source file#
The documentation for this class was generated from the following file:
opencv2/ml.hpp