@Namespace(value="cv::ml") @Properties(inherit=opencv_ml.class) public class TrainData extends Pointer
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\
ml_intro_data
Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.NativeDeallocator, Pointer.ReferenceCounter
Constructor and Description |
---|
TrainData(Pointer p)
Pointer cast constructor.
|
Modifier and Type | Method and Description |
---|---|
static TrainData |
create(GpuMat samples,
int layout,
GpuMat responses) |
static TrainData |
create(GpuMat samples,
int layout,
GpuMat responses,
GpuMat varIdx,
GpuMat sampleIdx,
GpuMat sampleWeights,
GpuMat varType) |
static TrainData |
create(Mat samples,
int layout,
Mat responses) |
static TrainData |
create(Mat samples,
int layout,
Mat responses,
Mat varIdx,
Mat sampleIdx,
Mat sampleWeights,
Mat varType)
\brief Creates training data from in-memory arrays.
|
static TrainData |
create(UMat samples,
int layout,
UMat responses) |
static TrainData |
create(UMat samples,
int layout,
UMat responses,
UMat varIdx,
UMat sampleIdx,
UMat sampleWeights,
UMat varType) |
int |
getCatCount(int vi) |
Mat |
getCatMap() |
Mat |
getCatOfs() |
Mat |
getClassLabels()
\brief Returns the vector of class labels
|
Mat |
getDefaultSubstValues() |
int |
getLayout() |
Mat |
getMissing() |
int |
getNAllVars() |
void |
getNames(StringVector names)
\brief Returns vector of symbolic names captured in loadFromCSV()
|
Mat |
getNormCatResponses() |
void |
getNormCatValues(int vi,
GpuMat sidx,
int[] values) |
void |
getNormCatValues(int vi,
GpuMat sidx,
IntBuffer values) |
void |
getNormCatValues(int vi,
GpuMat sidx,
IntPointer values) |
void |
getNormCatValues(int vi,
Mat sidx,
int[] values) |
void |
getNormCatValues(int vi,
Mat sidx,
IntBuffer values) |
void |
getNormCatValues(int vi,
Mat sidx,
IntPointer values) |
void |
getNormCatValues(int vi,
UMat sidx,
int[] values) |
void |
getNormCatValues(int vi,
UMat sidx,
IntBuffer values) |
void |
getNormCatValues(int vi,
UMat sidx,
IntPointer values) |
int |
getNSamples() |
int |
getNTestSamples() |
int |
getNTrainSamples() |
int |
getNVars() |
Mat |
getResponses() |
int |
getResponseType() |
void |
getSample(GpuMat varIdx,
int sidx,
float[] buf) |
void |
getSample(GpuMat varIdx,
int sidx,
FloatBuffer buf) |
void |
getSample(GpuMat varIdx,
int sidx,
FloatPointer buf) |
void |
getSample(Mat varIdx,
int sidx,
float[] buf) |
void |
getSample(Mat varIdx,
int sidx,
FloatBuffer buf) |
void |
getSample(Mat varIdx,
int sidx,
FloatPointer buf) |
void |
getSample(UMat varIdx,
int sidx,
float[] buf) |
void |
getSample(UMat varIdx,
int sidx,
FloatBuffer buf) |
void |
getSample(UMat varIdx,
int sidx,
FloatPointer buf) |
Mat |
getSamples() |
Mat |
getSampleWeights() |
static Mat |
getSubMatrix(Mat matrix,
Mat idx,
int layout)
\brief Extract from matrix rows/cols specified by passed indexes.
|
static Mat |
getSubVector(Mat vec,
Mat idx)
\brief Extract from 1D vector elements specified by passed indexes.
|
Mat |
getTestNormCatResponses() |
Mat |
getTestResponses() |
Mat |
getTestSampleIdx() |
Mat |
getTestSamples()
\brief Returns matrix of test samples
|
Mat |
getTestSampleWeights() |
Mat |
getTrainNormCatResponses()
\brief Returns the vector of normalized categorical responses
|
Mat |
getTrainResponses()
\brief Returns the vector of responses
|
Mat |
getTrainSampleIdx() |
Mat |
getTrainSamples() |
Mat |
getTrainSamples(int layout,
boolean compressSamples,
boolean compressVars)
\brief Returns matrix of train samples
|
Mat |
getTrainSampleWeights() |
void |
getValues(int vi,
GpuMat sidx,
float[] values) |
void |
getValues(int vi,
GpuMat sidx,
FloatBuffer values) |
void |
getValues(int vi,
GpuMat sidx,
FloatPointer values) |
void |
getValues(int vi,
Mat sidx,
float[] values) |
void |
getValues(int vi,
Mat sidx,
FloatBuffer values) |
void |
getValues(int vi,
Mat sidx,
FloatPointer values) |
void |
getValues(int vi,
UMat sidx,
float[] values) |
void |
getValues(int vi,
UMat sidx,
FloatBuffer values) |
void |
getValues(int vi,
UMat sidx,
FloatPointer values) |
Mat |
getVarIdx() |
Mat |
getVarSymbolFlags() |
Mat |
getVarType() |
static TrainData |
loadFromCSV(BytePointer filename,
int headerLineCount) |
static TrainData |
loadFromCSV(BytePointer filename,
int headerLineCount,
int responseStartIdx,
int responseEndIdx,
BytePointer varTypeSpec,
byte delimiter,
byte missch)
\brief Reads the dataset from a .csv file and returns the ready-to-use training data.
|
static TrainData |
loadFromCSV(String filename,
int headerLineCount) |
static TrainData |
loadFromCSV(String filename,
int headerLineCount,
int responseStartIdx,
int responseEndIdx,
String varTypeSpec,
byte delimiter,
byte missch) |
static float |
missingValue() |
void |
setTrainTestSplit(int count) |
void |
setTrainTestSplit(int count,
boolean shuffle)
\brief Splits the training data into the training and test parts
|
void |
setTrainTestSplitRatio(double ratio) |
void |
setTrainTestSplitRatio(double ratio,
boolean shuffle)
\brief Splits the training data into the training and test parts
|
void |
shuffleTrainTest() |
address, asBuffer, asByteBuffer, availablePhysicalBytes, calloc, capacity, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, hashCode, isNull, isNull, limit, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetof, parseBytes, physicalBytes, position, position, put, realloc, referenceCount, releaseReference, retainReference, setNull, sizeof, toString, totalBytes, totalPhysicalBytes, withDeallocator, zero
public TrainData(Pointer p)
Pointer.Pointer(Pointer)
.public static float missingValue()
public int getLayout()
public int getNTrainSamples()
public int getNTestSamples()
public int getNSamples()
public int getNVars()
public int getNAllVars()
public void getSample(@ByVal Mat varIdx, int sidx, FloatPointer buf)
public void getSample(@ByVal Mat varIdx, int sidx, FloatBuffer buf)
public void getSample(@ByVal UMat varIdx, int sidx, FloatPointer buf)
public void getSample(@ByVal UMat varIdx, int sidx, FloatBuffer buf)
public void getSample(@ByVal GpuMat varIdx, int sidx, FloatPointer buf)
public void getSample(@ByVal GpuMat varIdx, int sidx, FloatBuffer buf)
@ByVal public Mat getTrainSamples(int layout, @Cast(value="bool") boolean compressSamples, @Cast(value="bool") boolean compressVars)
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).
@ByVal public Mat getTrainResponses()
The function returns ordered or the original categorical responses. Usually it's used in regression algorithms.
@ByVal public Mat getTrainNormCatResponses()
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.
public int getResponseType()
public void getValues(int vi, @ByVal Mat sidx, FloatPointer values)
public void getValues(int vi, @ByVal Mat sidx, FloatBuffer values)
public void getValues(int vi, @ByVal UMat sidx, FloatPointer values)
public void getValues(int vi, @ByVal UMat sidx, FloatBuffer values)
public void getValues(int vi, @ByVal GpuMat sidx, FloatPointer values)
public void getValues(int vi, @ByVal GpuMat sidx, FloatBuffer values)
public void getNormCatValues(int vi, @ByVal Mat sidx, IntPointer values)
public void getNormCatValues(int vi, @ByVal UMat sidx, IntPointer values)
public void getNormCatValues(int vi, @ByVal GpuMat sidx, IntPointer values)
public int getCatCount(int vi)
@ByVal public Mat getClassLabels()
The function returns vector of unique labels occurred in the responses.
public void setTrainTestSplit(int count, @Cast(value="bool") boolean shuffle)
TrainData::setTrainTestSplitRatio
public void setTrainTestSplit(int count)
public void setTrainTestSplitRatio(double ratio, @Cast(value="bool") boolean shuffle)
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.
TrainData::setTrainTestSplit
public void setTrainTestSplitRatio(double ratio)
public void shuffleTrainTest()
public void getNames(@ByRef StringVector names)
@ByVal public static Mat getSubVector(@Const @ByRef Mat vec, @Const @ByRef Mat idx)
vec
- input vector (supported types: CV_32S, CV_32F, CV_64F)idx
- 1D index vector@ByVal public static Mat getSubMatrix(@Const @ByRef Mat matrix, @Const @ByRef Mat idx, int layout)
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)@opencv_core.Ptr public static TrainData loadFromCSV(@opencv_core.Str BytePointer filename, int headerLineCount, int responseStartIdx, int responseEndIdx, @opencv_core.Str BytePointer varTypeSpec, @Cast(value="char") byte delimiter, @Cast(value="char") byte missch)
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 staring 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
format ord[n1-n2,n3,n4-n5,...]cat[n6,n7-n8,...]
. That is, variables from n1 to n2
(inclusive range), n3
, n4 to n5
... are considered ordered and n6
, 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.
\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.@opencv_core.Ptr public static TrainData loadFromCSV(@opencv_core.Str BytePointer filename, int headerLineCount)
@opencv_core.Ptr public static TrainData loadFromCSV(@opencv_core.Str String filename, int headerLineCount, int responseStartIdx, int responseEndIdx, @opencv_core.Str String varTypeSpec, @Cast(value="char") byte delimiter, @Cast(value="char") byte missch)
@opencv_core.Ptr public static TrainData loadFromCSV(@opencv_core.Str String filename, int headerLineCount)
@opencv_core.Ptr public static TrainData create(@ByVal Mat samples, int layout, @ByVal Mat responses, @ByVal(nullValue="cv::InputArray(cv::noArray())") Mat varIdx, @ByVal(nullValue="cv::InputArray(cv::noArray())") Mat sampleIdx, @ByVal(nullValue="cv::InputArray(cv::noArray())") Mat sampleWeights, @ByVal(nullValue="cv::InputArray(cv::noArray())") Mat varType)
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.@opencv_core.Ptr public static TrainData create(@ByVal Mat samples, int layout, @ByVal Mat responses)
@opencv_core.Ptr public static TrainData create(@ByVal UMat samples, int layout, @ByVal UMat responses, @ByVal(nullValue="cv::InputArray(cv::noArray())") UMat varIdx, @ByVal(nullValue="cv::InputArray(cv::noArray())") UMat sampleIdx, @ByVal(nullValue="cv::InputArray(cv::noArray())") UMat sampleWeights, @ByVal(nullValue="cv::InputArray(cv::noArray())") UMat varType)
@opencv_core.Ptr public static TrainData create(@ByVal UMat samples, int layout, @ByVal UMat responses)
@opencv_core.Ptr public static TrainData create(@ByVal GpuMat samples, int layout, @ByVal GpuMat responses, @ByVal(nullValue="cv::InputArray(cv::noArray())") GpuMat varIdx, @ByVal(nullValue="cv::InputArray(cv::noArray())") GpuMat sampleIdx, @ByVal(nullValue="cv::InputArray(cv::noArray())") GpuMat sampleWeights, @ByVal(nullValue="cv::InputArray(cv::noArray())") GpuMat varType)
Copyright © 2020. All rights reserved.