Class TrainData
- Namespace
- OpenCvSharp.ML
- Assembly
- OpenCvSharp.dll
Training data used by the ml algorithms
public class TrainData : CvPtrObject, IDisposable
- Inheritance
-
TrainData
- Implements
- Inherited Members
Methods
Create(InputArray, SampleTypes, InputArray, InputArray, InputArray, InputArray, InputArray)
Creates training data from in-memory arrays.
public static TrainData Create(InputArray samples, SampleTypes layout, InputArray responses, InputArray varIdx = default, InputArray sampleIdx = default, InputArray sampleWeights = default, InputArray varType = default)
Parameters
samplesInputArraymatrix of samples. It should have CV_32F type.
layoutSampleTypessee ml::SampleTypes.
responsesInputArraymatrix 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)
varIdxInputArrayvector 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.
sampleIdxInputArrayvector 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.
sampleWeightsInputArrayoptional vector with weights for each sample. It should have CV_32F type.
varTypeInputArrayoptional 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
GetClassLabels()
Returns the vector of class labels
public Mat GetClassLabels()
Returns
GetLayout()
Returns the layout (ml::SampleTypes) used by this training data.
public SampleTypes GetLayout()
Returns
GetMissing()
Returns the mask of missing values in the samples
public Mat GetMissing()
Returns
GetNAllVars()
Returns the number of variables including the responses
public int GetNAllVars()
Returns
GetNSamples()
Returns the total number of samples
public int GetNSamples()
Returns
GetNTestSamples()
Returns the number of test samples
public int GetNTestSamples()
Returns
GetNTrainSamples()
Returns the number of training samples
public int GetNTrainSamples()
Returns
GetNVars()
Returns the number of variables
public int GetNVars()
Returns
GetResponses()
Returns the vector of responses
public Mat GetResponses()
Returns
GetSamples()
Returns the matrix of all the samples
public Mat GetSamples()
Returns
GetTestResponses()
Returns the vector of responses for the test samples
public Mat GetTestResponses()
Returns
GetTestSampleIdx()
Returns the indices of the test samples
public Mat GetTestSampleIdx()
Returns
GetTestSamples()
Returns matrix of test samples
public Mat GetTestSamples()
Returns
GetTrainResponses()
Returns the vector of responses for the training samples
public Mat GetTrainResponses()
Returns
GetTrainSampleIdx()
Returns the indices of the training samples
public Mat GetTrainSampleIdx()
Returns
GetTrainSamples(SampleTypes, bool, bool)
Returns matrix of train samples
public Mat GetTrainSamples(SampleTypes layout = SampleTypes.RowSample, bool compressSamples = true, bool compressVars = true)
Parameters
layoutSampleTypesThe requested layout. If it's different from the initial one, the matrix is transposed. See ml::SampleTypes.
compressSamplesboolif true, the function returns only the training samples (specified by sampleIdx)
compressVarsboolif true, the function returns the shorter training samples, containing only the active variables.
Returns
GetVarIdx()
Returns the vector of variable indices used for training
public Mat GetVarIdx()
Returns
GetVarType()
Returns the type of each input and output variable
public Mat GetVarType()
Returns
LoadFromCSV(string, int, int, int, string, char, char)
Reads the dataset from a .csv file and returns the ready-to-use training data.
public static TrainData LoadFromCSV(string filename, int headerLineCount, int responseStartIdx = -1, int responseEndIdx = -1, string varTypeSpec = "", char delimiter = ',', char missch = '?')
Parameters
filenamestringThe input file name
headerLineCountintThe number of lines in the beginning to skip; besides the header, the function also skips empty lines and lines starting with '#'
responseStartIdxintIndex of the first output variable. If -1, the function considers the last variable as the response
responseEndIdxintIndex of the last output variable + 1. If -1, then there is single response variable at responseStartIdx.
varTypeSpecstringThe optional text string that specifies the variables' types. It has the format
ord[n1-n2,n3,n4-n5,...]cat[n6,n7-n8,...].delimitercharThe character used to separate values in each line.
misschcharThe character used to specify missing measurements. It should not be a digit.
Returns
SetTrainTestSplit(int, bool)
Splits the training data into the training and test parts
public void SetTrainTestSplit(int count, bool shuffle = true)
Parameters
SetTrainTestSplitRatio(double, bool)
Splits the training data into the training and test parts
public void SetTrainTestSplitRatio(double ratio, bool shuffle = true)
Parameters
ShuffleTrainTest()
Shuffles the training and test sample indices
public void ShuffleTrainTest()