TrainData

Objective-C

@interface TrainData : NSObject

Swift

class TrainData : NSObject

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

REF: ml_intro_data

Member of Ml

Methods

  • Declaration

    Objective-C

    - (Mat*)getCatMap NS_SWIFT_NAME(getCatMap());

    Swift

    func getCatMap() -> Mat
  • Declaration

    Objective-C

    - (Mat*)getCatOfs NS_SWIFT_NAME(getCatOfs());

    Swift

    func getCatOfs() -> Mat
  • Returns the vector of class labels

     The function returns vector of unique labels occurred in the responses.
    

    Declaration

    Objective-C

    - (nonnull Mat *)getClassLabels;

    Swift

    func getClassLabels() -> Mat
  • Declaration

    Objective-C

    - (Mat*)getDefaultSubstValues NS_SWIFT_NAME(getDefaultSubstValues());

    Swift

    func getDefaultSubstValues() -> Mat
  • Declaration

    Objective-C

    - (Mat*)getMissing NS_SWIFT_NAME(getMissing());

    Swift

    func getMissing() -> Mat
  • Declaration

    Objective-C

    - (Mat*)getNormCatResponses NS_SWIFT_NAME(getNormCatResponses());

    Swift

    func getNormCatResponses() -> Mat
  • Declaration

    Objective-C

    - (Mat*)getResponses NS_SWIFT_NAME(getResponses());

    Swift

    func getResponses() -> Mat
  • Declaration

    Objective-C

    - (Mat*)getSampleWeights NS_SWIFT_NAME(getSampleWeights());

    Swift

    func getSampleWeights() -> Mat
  • Declaration

    Objective-C

    - (Mat*)getSamples NS_SWIFT_NAME(getSamples());

    Swift

    func getSamples() -> Mat
  • Extract from matrix rows/cols specified by passed indexes.

    Declaration

    Objective-C

    + (nonnull Mat *)getSubMatrix:(nonnull Mat *)matrix
                              idx:(nonnull Mat *)idx
                           layout:(int)layout;

    Swift

    class func getSubMatrix(matrix: Mat, idx: Mat, layout: Int32) -> Mat

    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)

  • Extract from 1D vector elements specified by passed indexes.

    Declaration

    Objective-C

    + (nonnull Mat *)getSubVector:(nonnull Mat *)vec idx:(nonnull Mat *)idx;

    Swift

    class func getSubVector(vec: Mat, idx: Mat) -> Mat

    Parameters

    vec

    input vector (supported types: CV_32S, CV_32F, CV_64F)

    idx

    1D index vector

  • Declaration

    Objective-C

    - (Mat*)getTestNormCatResponses NS_SWIFT_NAME(getTestNormCatResponses());

    Swift

    func getTestNormCatResponses() -> Mat
  • Declaration

    Objective-C

    - (Mat*)getTestResponses NS_SWIFT_NAME(getTestResponses());

    Swift

    func getTestResponses() -> Mat
  • Declaration

    Objective-C

    - (Mat*)getTestSampleIdx NS_SWIFT_NAME(getTestSampleIdx());

    Swift

    func getTestSampleIdx() -> Mat
  • Declaration

    Objective-C

    - (Mat*)getTestSampleWeights NS_SWIFT_NAME(getTestSampleWeights());

    Swift

    func getTestSampleWeights() -> Mat
  • Returns matrix of test samples

    Declaration

    Objective-C

    - (nonnull Mat *)getTestSamples;

    Swift

    func getTestSamples() -> Mat
  • 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.
    

    Declaration

    Objective-C

    - (nonnull Mat *)getTrainNormCatResponses;

    Swift

    func getTrainNormCatResponses() -> Mat
  • Returns the vector of responses

     The function returns ordered or the original categorical responses. Usually it's used in
     regression algorithms.
    

    Declaration

    Objective-C

    - (nonnull Mat *)getTrainResponses;

    Swift

    func getTrainResponses() -> Mat
  • Declaration

    Objective-C

    - (Mat*)getTrainSampleIdx NS_SWIFT_NAME(getTrainSampleIdx());

    Swift

    func getTrainSampleIdx() -> Mat
  • Declaration

    Objective-C

    - (Mat*)getTrainSampleWeights NS_SWIFT_NAME(getTrainSampleWeights());

    Swift

    func getTrainSampleWeights() -> Mat
  • Returns matrix of train samples

    Declaration

    Objective-C

    - (nonnull Mat *)getTrainSamples:(int)layout
                     compressSamples:(BOOL)compressSamples
                        compressVars:(BOOL)compressVars;

    Swift

    func getTrainSamples(layout: Int32, compressSamples: Bool, compressVars: Bool) -> Mat

    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 matrix of train samples

    Declaration

    Objective-C

    - (nonnull Mat *)getTrainSamples:(int)layout
                     compressSamples:(BOOL)compressSamples;

    Swift

    func getTrainSamples(layout: Int32, compressSamples: Bool) -> Mat

    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 matrix of train samples

    Declaration

    Objective-C

    - (nonnull Mat *)getTrainSamples:(int)layout;

    Swift

    func getTrainSamples(layout: Int32) -> Mat

    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 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).
    

    Declaration

    Objective-C

    - (nonnull Mat *)getTrainSamples;

    Swift

    func getTrainSamples() -> Mat
  • Declaration

    Objective-C

    - (Mat*)getVarIdx NS_SWIFT_NAME(getVarIdx());

    Swift

    func getVarIdx() -> Mat
  • Declaration

    Objective-C

    - (Mat*)getVarSymbolFlags NS_SWIFT_NAME(getVarSymbolFlags());

    Swift

    func getVarSymbolFlags() -> Mat
  • Declaration

    Objective-C

    - (Mat*)getVarType NS_SWIFT_NAME(getVarType());

    Swift

    func getVarType() -> Mat
  • Creates training data from in-memory arrays.

    Declaration

    Objective-C

    + (nonnull TrainData *)create:(nonnull Mat *)samples
                           layout:(int)layout
                        responses:(nonnull Mat *)responses
                           varIdx:(nonnull Mat *)varIdx
                        sampleIdx:(nonnull Mat *)sampleIdx
                    sampleWeights:(nonnull Mat *)sampleWeights
                          varType:(nonnull Mat *)varType;

    Swift

    class func create(samples: Mat, layout: Int32, responses: Mat, varIdx: Mat, sampleIdx: Mat, sampleWeights: Mat, varType: Mat) -> TrainData

    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.

  • Creates training data from in-memory arrays.

    Declaration

    Objective-C

    + (nonnull TrainData *)create:(nonnull Mat *)samples
                           layout:(int)layout
                        responses:(nonnull Mat *)responses
                           varIdx:(nonnull Mat *)varIdx
                        sampleIdx:(nonnull Mat *)sampleIdx
                    sampleWeights:(nonnull Mat *)sampleWeights;

    Swift

    class func create(samples: Mat, layout: Int32, responses: Mat, varIdx: Mat, sampleIdx: Mat, sampleWeights: Mat) -> TrainData

    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. `, containing types of each input and output variable. See ml::VariableTypes.

  • Creates training data from in-memory arrays.

    Declaration

    Objective-C

    + (nonnull TrainData *)create:(nonnull Mat *)samples
                           layout:(int)layout
                        responses:(nonnull Mat *)responses
                           varIdx:(nonnull Mat *)varIdx
                        sampleIdx:(nonnull Mat *)sampleIdx;

    Swift

    class func create(samples: Mat, layout: Int32, responses: Mat, varIdx: Mat, sampleIdx: Mat) -> TrainData

    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. `, containing types of each input and output variable. See ml::VariableTypes.

  • Creates training data from in-memory arrays.

    Declaration

    Objective-C

    + (nonnull TrainData *)create:(nonnull Mat *)samples
                           layout:(int)layout
                        responses:(nonnull Mat *)responses
                           varIdx:(nonnull Mat *)varIdx;

    Swift

    class func create(samples: Mat, layout: Int32, responses: Mat, varIdx: Mat) -> TrainData

    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. `, containing types of each input and output variable. See ml::VariableTypes.

  • Creates training data from in-memory arrays.

    Declaration

    Objective-C

    + (nonnull TrainData *)create:(nonnull Mat *)samples
                           layout:(int)layout
                        responses:(nonnull Mat *)responses;

    Swift

    class func create(samples: Mat, layout: Int32, responses: Mat) -> TrainData

    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. `, containing types of each input and output variable. See ml::VariableTypes.

  • Declaration

    Objective-C

    - (int)getCatCount:(int)vi NS_SWIFT_NAME(getCatCount(vi:));

    Swift

    func getCatCount(vi: Int32) -> Int32
  • Declaration

    Objective-C

    - (int)getLayout NS_SWIFT_NAME(getLayout());

    Swift

    func getLayout() -> Int32
  • Declaration

    Objective-C

    - (int)getNAllVars NS_SWIFT_NAME(getNAllVars());

    Swift

    func getNAllVars() -> Int32
  • Declaration

    Objective-C

    - (int)getNSamples NS_SWIFT_NAME(getNSamples());

    Swift

    func getNSamples() -> Int32
  • Declaration

    Objective-C

    - (int)getNTestSamples NS_SWIFT_NAME(getNTestSamples());

    Swift

    func getNTestSamples() -> Int32
  • Declaration

    Objective-C

    - (int)getNTrainSamples NS_SWIFT_NAME(getNTrainSamples());

    Swift

    func getNTrainSamples() -> Int32
  • Declaration

    Objective-C

    - (int)getNVars NS_SWIFT_NAME(getNVars());

    Swift

    func getNVars() -> Int32
  • Declaration

    Objective-C

    - (int)getResponseType NS_SWIFT_NAME(getResponseType());

    Swift

    func getResponseType() -> Int32
  • Returns vector of symbolic names captured in loadFromCSV()

    Declaration

    Objective-C

    - (void)getNames:(nonnull NSArray<NSString *> *)names;

    Swift

    func getNames(names: [String])
  • Declaration

    Objective-C

    - (void)getSample:(Mat*)varIdx sidx:(int)sidx buf:(float)buf NS_SWIFT_NAME(getSample(varIdx:sidx:buf:));

    Swift

    func getSample(varIdx: Mat, sidx: Int32, buf: Float)
  • Declaration

    Objective-C

    - (void)getValues:(int)vi sidx:(Mat*)sidx values:(float)values NS_SWIFT_NAME(getValues(vi:sidx:values:));

    Swift

    func getValues(vi: Int32, sidx: Mat, values: Float)
  • Splits the training data into the training and test parts - see: -setTrainTestSplitRatio:shuffle:

    Declaration

    Objective-C

    - (void)setTrainTestSplit:(int)count shuffle:(BOOL)shuffle;

    Swift

    func setTrainTestSplit(count: Int32, shuffle: Bool)
  • Splits the training data into the training and test parts - see: -setTrainTestSplitRatio:shuffle:

    Declaration

    Objective-C

    - (void)setTrainTestSplit:(int)count;

    Swift

    func setTrainTestSplit(count: Int32)
  • 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: `-setTrainTestSplit:shuffle:`
    

    Declaration

    Objective-C

    - (void)setTrainTestSplitRatio:(double)ratio shuffle:(BOOL)shuffle;

    Swift

    func setTrainTestSplitRatio(ratio: Double, shuffle: Bool)
  • 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: `-setTrainTestSplit:shuffle:`
    

    Declaration

    Objective-C

    - (void)setTrainTestSplitRatio:(double)ratio;

    Swift

    func setTrainTestSplitRatio(ratio: Double)
  • Declaration

    Objective-C

    - (void)shuffleTrainTest NS_SWIFT_NAME(shuffleTrainTest());

    Swift

    func shuffleTrainTest()