ml_TrainData
import { ml_TrainData } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Native object: release it with using or delete(). Factories can return null; check before calling methods.
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: ml_intro_data
Constructors and members
static getSubVector
Extract from 1D vector elements specified by passed indexes.
getSubVector(vec: Mat, idx: Mat): Mat;vecinput vector (supported types: CV_32S, CV_32F, CV_64F)
idx1D index vector
The Mat result. Release returned native handles with using or delete(), including handles nested in results.
static getSubMatrix
Extract from matrix rows/cols specified by passed indexes.
getSubMatrix(matrix: Mat, idx: Mat, layout: number): Mat;matrixinput matrix (supported types: CV_32S, CV_32F, CV_64F)
idx1D index vector
layoutspecifies to extract rows (cv::ml::ROW_SAMPLES) or to extract columns (cv::ml::COL_SAMPLES)
The Mat result. Release returned native handles with using or delete(), including handles nested in results.
static create
Creates training data from in-memory arrays.
create(samples: Mat, layout: number, responses: Mat, varIdx: Mat, sampleIdx: Mat, sampleWeights: Mat, varType: Mat): ml_TrainData | null;5 available overloads
create(samples: Mat, layout: number, responses: Mat): ml_TrainData | null;create(samples: Mat, layout: number, responses: Mat, varIdx: Mat): ml_TrainData | null;create(samples: Mat, layout: number, responses: Mat, varIdx: Mat, sampleIdx: Mat): ml_TrainData | null;create(samples: Mat, layout: number, responses: Mat, varIdx: Mat, sampleIdx: Mat, sampleWeights: Mat): ml_TrainData | null;create(samples: Mat, layout: number, responses: Mat, varIdx: Mat, sampleIdx: Mat, sampleWeights: Mat, varType: Mat): ml_TrainData | null;samplesmatrix of samples. It should have CV_32F type.
layoutsee ml::SampleTypes.
responsesmatrix 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)
varIdxvector 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.
sampleIdxvector 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.
sampleWeightsoptional vector with weights for each sample. It should have CV_32F type.
varTypeoptional 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.
The ml_TrainData | null result.
clone
Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.
clone(): this;The this result.
getLayout
Return ROW_SAMPLE or COL_SAMPLE to indicate how samples are arranged in the data matrix.
getLayout(): number;The number result.
getNTrainSamples
Return the number of samples in the training partition.
getNTrainSamples(): number;The number result.
getNTestSamples
Return the number of samples in the test partition.
getNTestSamples(): number;The number result.
getNSamples
Return the total number of selected samples.
getNSamples(): number;The number result.
getNVars
Return the number of selected input variables per sample.
getNVars(): number;The number result.
getNAllVars
Return the number of input variables before variable selection.
getNAllVars(): number;The number result.
getSample
Return the sample configured on this ml_TrainData object.
getSample(indices: Mat, index: number): FloatVector;indicesindices argument (Mat).
indexindex argument (number).
The FloatVector result. Release returned native handles with using or delete(), including handles nested in results.
getSamples
Return an owned matrix header for the input sample data in its original layout.
getSamples(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getMissing
Return the matrix marking missing values in the input samples.
getMissing(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getTrainSamples
Returns matrix of train samples
getTrainSamples(layout: number, compressSamples: boolean, compressVars: boolean): Mat;4 available overloads
getTrainSamples(): Mat;getTrainSamples(layout: number): Mat;getTrainSamples(layout: number, compressSamples: boolean): Mat;getTrainSamples(layout: number, compressSamples: boolean, compressVars: boolean): Mat;layoutThe requested layout. If it's different from the initial one, the matrix is transposed. See ml::SampleTypes.
compressSamplesif true, the function returns only the training samples (specified by sampleIdx)
compressVarsif 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).
The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getTrainResponses
Returns the vector of responses
The function returns ordered or the original categorical responses. Usually it's used in
regression algorithms.
getTrainResponses(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getTrainNormCatResponses
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.
getTrainNormCatResponses(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getTestResponses
Return the test responses configured on this ml_TrainData object.
getTestResponses(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getTestNormCatResponses
Return the test norm cat responses configured on this ml_TrainData object.
getTestNormCatResponses(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getResponses
Return the responses configured on this ml_TrainData object.
getResponses(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getNormCatResponses
Return the norm cat responses configured on this ml_TrainData object.
getNormCatResponses(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getSampleWeights
Return the sample weights configured on this ml_TrainData object.
getSampleWeights(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getTrainSampleWeights
Return the train sample weights configured on this ml_TrainData object.
getTrainSampleWeights(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getTestSampleWeights
Return the test sample weights configured on this ml_TrainData object.
getTestSampleWeights(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getVarIdx
Return the var idx configured on this ml_TrainData object.
getVarIdx(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getVarType
Return the var type configured on this ml_TrainData object.
getVarType(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getVarSymbolFlags
Return the var symbol flags configured on this ml_TrainData object.
getVarSymbolFlags(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getResponseType
Return the response type configured on this ml_TrainData object.
getResponseType(): number;The number result.
getTrainSampleIdx
Return the train sample idx configured on this ml_TrainData object.
getTrainSampleIdx(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getTestSampleIdx
Return the test sample idx configured on this ml_TrainData object.
getTestSampleIdx(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getValues
Return the values configured on this ml_TrainData object.
getValues(index: number, indices: Mat): FloatVector;indexindex argument (number).
indicesindices argument (Mat).
The FloatVector result. Release returned native handles with using or delete(), including handles nested in results.
getDefaultSubstValues
Return the default subst values configured on this ml_TrainData object.
getDefaultSubstValues(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getCatCount
Return the cat count configured on this ml_TrainData object.
getCatCount(vi: number): number;vivi argument (number).
The number result.
getClassLabels
Returns the vector of class labels
The function returns vector of unique labels occurred in the responses.
getClassLabels(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getCatOfs
Return the cat ofs configured on this ml_TrainData object.
getCatOfs(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getCatMap
Return the cat map configured on this ml_TrainData object.
getCatMap(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
setTrainTestSplit
Splits the training data into the training and test parts See: TrainData::setTrainTestSplitRatio
setTrainTestSplit(count: number, shuffle: boolean): void;2 available overloads
setTrainTestSplit(count: number): void;setTrainTestSplit(count: number, shuffle: boolean): void;countcount argument (number).
shuffleshuffle argument (boolean).
setTrainTestSplitRatio
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
setTrainTestSplitRatio(ratio: number, shuffle: boolean): void;2 available overloads
setTrainTestSplitRatio(ratio: number): void;setTrainTestSplitRatio(ratio: number, shuffle: boolean): void;ratioratio argument (number).
shuffleshuffle argument (boolean).
shuffleTrainTest
Randomly repartition the current training and test sample indices while preserving the split sizes.
shuffleTrainTest(): void;getTestSamples
Returns matrix of test samples
getTestSamples(): Mat;The Mat result. Release returned native handles with using or delete(), including handles nested in results.
getNames
Returns vector of symbolic names captured in loadFromCSV()
getNames(names: StringVector): void;namesnames argument (StringVector).
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.