封裝訓練資料的類。 詳情...
#include <opencv2/ml.hpp>
|
| virtual | ~TrainData () |
| |
| virtual int | getCatCount (int vi) const =0 |
| |
| virtual Mat | getCatMap () const =0 |
| |
| virtual Mat | getCatOfs () const =0 |
| |
| virtual Mat | getClassLabels () const =0 |
| | 返回類別標籤向量。
|
| |
| virtual Mat | getDefaultSubstValues () const =0 |
| |
| virtual int | getLayout () const =0 |
| |
| virtual Mat | getMissing () const =0 |
| |
| virtual int | getNAllVars () const =0 |
| |
| virtual void | getNames (std::vector< String > &names) const =0 |
| | 返回在 loadFromCSV() 中捕獲的符號名稱向量
|
| |
| virtual Mat | getNormCatResponses () const =0 |
| |
| virtual void | getNormCatValues (int vi, InputArray sidx, int *values) const =0 |
| |
| virtual int | getNSamples () const =0 |
| |
| virtual int | getNTestSamples () const =0 |
| |
| virtual int | getNTrainSamples () const =0 |
| |
| virtual int | getNVars () const =0 |
| |
| virtual Mat | getResponses () const =0 |
| |
| virtual int | getResponseType () const =0 |
| |
| virtual void | getSample (InputArray varIdx, int sidx, float *buf) const =0 |
| |
| virtual Mat | getSamples () const =0 |
| |
| virtual Mat | getSampleWeights () const =0 |
| |
| virtual Mat | getTestNormCatResponses () const =0 |
| |
| virtual Mat | getTestResponses () const =0 |
| |
| virtual Mat | getTestSampleIdx () const =0 |
| |
| virtual Mat | getTestSamples () const =0 |
| | 返回測試樣本矩陣。
|
| |
| virtual Mat | getTestSampleWeights () const =0 |
| |
| virtual Mat | getTrainNormCatResponses () const =0 |
| | 返回歸一化的類別響應向量。
|
| |
| virtual Mat | getTrainResponses () const =0 |
| | 返回響應向量。
|
| |
| virtual Mat | getTrainSampleIdx () const =0 |
| |
| virtual Mat | getTrainSamples (int layout=ROW_SAMPLE, bool compressSamples=true, bool compressVars=true) const =0 |
| | 返回訓練樣本矩陣。
|
| |
| virtual Mat | getTrainSampleWeights () const =0 |
| |
| virtual void | getValues (int vi, InputArray sidx, float *values) const =0 |
| |
| virtual Mat | getVarIdx () const =0 |
| |
| virtual Mat | getVarSymbolFlags () const =0 |
| |
| virtual Mat | getVarType () const =0 |
| |
| virtual void | setTrainTestSplit (int count, bool shuffle=true)=0 |
| | 將訓練資料分為訓練部分和測試部分。
|
| |
| virtual void | setTrainTestSplitRatio (double ratio, bool shuffle=true)=0 |
| | 將訓練資料分為訓練部分和測試部分。
|
| |
| virtual void | shuffleTrainTest ()=0 |
| |
|
| static Ptr< TrainData > | create (InputArray samples, int layout, InputArray responses, InputArray varIdx=noArray(), InputArray sampleIdx=noArray(), InputArray sampleWeights=noArray(), InputArray varType=noArray()) |
| | 從記憶體陣列建立訓練資料。
|
| |
| static Mat | getSubMatrix (const Mat &matrix, const Mat &idx, int layout) |
| | 從矩陣中提取由傳遞的索引指定的行/列。
|
| |
| static Mat | getSubVector (const Mat &vec, const Mat &idx) |
| | 從一維向量中提取由傳遞的索引指定的元素。
|
| |
| static Ptr< TrainData > | loadFromCSV (const String &filename, int headerLineCount, int responseStartIdx=-1, int responseEndIdx=-1, const String &varTypeSpec=String(), char delimiter=',', char missch='?') |
| | 從 .csv 檔案中讀取資料集並返回可立即使用的訓練資料。
|
| |
| static float | missingValue () |
| |
封裝訓練資料的類。
請注意,該類僅指定訓練資料的介面,但不指定實現。 ml 模組中的所有統計模型類都接受 Ptr<TrainData> 作為引數。換句話說,您可以建立自己的派生自 TrainData 的類,並將此類的例項的智慧指標傳遞給 StatModel::train。
- 另請參閱
- 訓練資料
◆ ~TrainData()
| virtual cv::ml::TrainData::~TrainData |
( |
| ) |
|
|
virtual |
◆ create()
| 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 |
從記憶體陣列建立訓練資料。
- 引數
-
| samples (樣本) | 樣本矩陣。它應該具有 CV_32F 型別。 |
| layout | 請參閱 ml::SampleTypes。 |
| responses | 響應矩陣。如果響應是標量,則它們應儲存為單行或單列。矩陣應具有 CV_32F 或 CV_32S 型別(在前一種情況下,響應預設被視為有序;在後一種情況下,被視為類別) |
| varIdx | 指定用於訓練的變數的向量。它可以是包含 0 基變數索引的整數向量 (CV_32S) 或包含活動變數掩碼的位元組向量 (CV_8U)。 |
| sampleIdx | 指定用於訓練的樣本的向量。它可以是包含 0 基樣本索引的整數向量 (CV_32S) 或包含訓練樣本掩碼的位元組向量 (CV_8U)。 |
| sampleWeights | 每個樣本的權重可選向量。它應該具有 CV_32F 型別。 |
| varType | 型別為 CV_8U 且大小為 <number_of_variables_in_samples> + <number_of_variables_in_responses> 的可選向量,包含每個輸入和輸出變數的型別。請參閱 ml::VariableTypes。 |
◆ getCatCount()
| virtual int cv::ml::TrainData::getCatCount |
( |
int | vi | ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getCatCount( | vi | ) -> | retval |
◆ getCatMap()
| virtual Mat cv::ml::TrainData::getCatMap |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getCatMap( | | ) -> | retval |
◆ getCatOfs()
| virtual Mat cv::ml::TrainData::getCatOfs |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getCatOfs( | | ) -> | retval |
◆ getClassLabels()
| virtual Mat cv::ml::TrainData::getClassLabels |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getClassLabels( | | ) -> | retval |
返回類別標籤向量。
該函式返回響應中出現的唯一標籤向量。
◆ getDefaultSubstValues()
| virtual Mat cv::ml::TrainData::getDefaultSubstValues |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getDefaultSubstValues( | | ) -> | retval |
◆ getLayout()
| virtual int cv::ml::TrainData::getLayout |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getLayout( | | ) -> | retval |
◆ getMissing()
| virtual Mat cv::ml::TrainData::getMissing |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getMissing( | | ) -> | retval |
◆ getNAllVars()
| virtual int cv::ml::TrainData::getNAllVars |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getNAllVars( | | ) -> | retval |
◆ getNames()
| virtual void cv::ml::TrainData::getNames |
( |
std::vector< String > & | names | ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getNames( | names | ) -> | None |
◆ getNormCatResponses()
| virtual Mat cv::ml::TrainData::getNormCatResponses |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getNormCatResponses( | | ) -> | retval |
◆ getNormCatValues()
| virtual void cv::ml::TrainData::getNormCatValues |
( |
int | vi, |
|
|
InputArray | sidx, |
|
|
int * | values ) const |
|
純虛擬函式 |
◆ getNSamples()
| virtual int cv::ml::TrainData::getNSamples |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getNSamples( | | ) -> | retval |
◆ getNTestSamples()
| virtual int cv::ml::TrainData::getNTestSamples |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getNTestSamples( | | ) -> | retval |
◆ getNTrainSamples()
| virtual int cv::ml::TrainData::getNTrainSamples |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getNTrainSamples( | | ) -> | retval |
◆ getNVars()
| virtual int cv::ml::TrainData::getNVars |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getNVars( | | ) -> | retval |
◆ getResponses()
| virtual Mat cv::ml::TrainData::getResponses |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getResponses( | | ) -> | retval |
◆ getResponseType()
| virtual int cv::ml::TrainData::getResponseType |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getResponseType( | | ) -> | retval |
◆ getSample()
| virtual void cv::ml::TrainData::getSample |
( |
InputArray | varIdx, |
|
|
int | sidx, |
|
|
float * | buf ) const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getSample( | varIdx, sidx, buf | ) -> | None |
◆ getSamples()
| virtual Mat cv::ml::TrainData::getSamples |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getSamples( | | ) -> | retval |
◆ getSampleWeights()
| virtual Mat cv::ml::TrainData::getSampleWeights |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getSampleWeights( | | ) -> | retval |
◆ getSubMatrix()
| static Mat cv::ml::TrainData::getSubMatrix |
( |
const Mat & | matrix, |
|
|
const Mat & | idx (索引), |
|
|
int | layout ) |
|
static (靜態) |
| Python |
|---|
| cv.ml.TrainData.getSubMatrix( | matrix, idx, layout | ) -> | retval |
| cv.ml.TrainData_getSubMatrix( | matrix, idx, layout | ) -> | retval |
從矩陣中提取由傳遞的索引指定的行/列。
- 引數
-
| matrix | 輸入矩陣(支援的型別:CV_32S、CV_32F、CV_64F) |
| idx (索引) | 一維索引向量 |
| layout | 指定提取行(cv::ml::ROW_SAMPLES)或提取列(cv::ml::COL_SAMPLES) |
◆ getSubVector()
| static Mat cv::ml::TrainData::getSubVector |
( |
const Mat & | vec, |
|
|
const Mat & | idx (索引) ) |
|
static (靜態) |
| Python |
|---|
| cv.ml.TrainData.getSubVector( | vec, idx | ) -> | retval |
| cv.ml.TrainData_getSubVector( | vec, idx | ) -> | retval |
從一維向量中提取由傳遞的索引指定的元素。
- 引數
-
| vec | 輸入向量(支援的型別:CV_32S、CV_32F、CV_64F) |
| idx (索引) | 一維索引向量 |
◆ getTestNormCatResponses()
| virtual Mat cv::ml::TrainData::getTestNormCatResponses |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getTestNormCatResponses( | | ) -> | retval |
◆ getTestResponses()
| virtual Mat cv::ml::TrainData::getTestResponses |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getTestResponses( | | ) -> | retval |
◆ getTestSampleIdx()
| virtual Mat cv::ml::TrainData::getTestSampleIdx |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getTestSampleIdx( | | ) -> | retval |
◆ getTestSamples()
| virtual Mat cv::ml::TrainData::getTestSamples |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getTestSamples( | | ) -> | retval |
◆ getTestSampleWeights()
| virtual Mat cv::ml::TrainData::getTestSampleWeights |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getTestSampleWeights( | | ) -> | retval |
◆ getTrainNormCatResponses()
| virtual Mat cv::ml::TrainData::getTrainNormCatResponses |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getTrainNormCatResponses( | | ) -> | retval |
◆ getTrainResponses()
| virtual Mat cv::ml::TrainData::getTrainResponses |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getTrainResponses( | | ) -> | retval |
返回響應向量。
該函式返回有序或原始類別響應。通常用於迴歸演算法。
◆ getTrainSampleIdx()
| virtual Mat cv::ml::TrainData::getTrainSampleIdx |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getTrainSampleIdx( | | ) -> | retval |
◆ getTrainSamples()
| virtual Mat cv::ml::TrainData::getTrainSamples |
( |
int | layout = ROW_SAMPLE, |
|
|
bool | compressSamples = true, |
|
|
bool | compressVars = true ) const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getTrainSamples( | [, layout[, compressSamples[, compressVars]]] | ) -> | retval |
返回訓練樣本矩陣。
- 引數
-
| layout | 請求的佈局。如果它與初始佈局不同,則矩陣將被轉置。請參閱 ml::SampleTypes。 |
| compressSamples | 如果為 true,則函式僅返回訓練樣本(由 sampleIdx 指定) |
| compressVars | 如果為 true,則函式返回較短的訓練樣本,僅包含活動變數。 |
在當前實現中,該函式嘗試避免物理資料複製並返回儲存在 TrainData 內部的矩陣(除非需要轉置或壓縮)。
◆ getTrainSampleWeights()
| virtual Mat cv::ml::TrainData::getTrainSampleWeights |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getTrainSampleWeights( | | ) -> | retval |
◆ getValues()
| virtual void cv::ml::TrainData::getValues |
( |
int | vi, |
|
|
InputArray | sidx, |
|
|
float * | values ) const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getValues( | vi, sidx, values | ) -> | None |
◆ getVarIdx()
| virtual Mat cv::ml::TrainData::getVarIdx |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getVarIdx( | | ) -> | retval |
◆ getVarSymbolFlags()
| virtual Mat cv::ml::TrainData::getVarSymbolFlags |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getVarSymbolFlags( | | ) -> | retval |
◆ getVarType()
| virtual Mat cv::ml::TrainData::getVarType |
( |
| ) |
const |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.getVarType( | | ) -> | retval |
◆ 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 = '?' ) |
|
static (靜態) |
從 .csv 檔案中讀取資料集並返回可立即使用的訓練資料。
- 引數
-
| filename | 輸入檔名 |
| headerLineCount | 要跳過的開頭行數;除了標題行,函式還會跳過空行和以 # 開頭的行 |
| responseStartIdx | 第一個輸出變數的索引。如果為 -1,則函式將最後一個變數視為響應 |
| responseEndIdx | 最後一個輸出變數的索引 + 1。如果為 -1,則在 responseStartIdx 處只有一個響應變數。 |
| varTypeSpec | 可選的文字字串,用於指定變數型別。其格式為 ord[n1-n2,n3,n4-n5,...]cat[n6,n7-n8,...]。也就是說,從 n1 到 n2(包括範圍)、n3、n4 到 n5 ... 的變數被認為是序數變數,而 n6、n7 到 n8 ... 被認為是類別變數。範圍 [n1..n2] + [n3] + [n4..n5] + ... + [n6] + [n7..n8] 應涵蓋所有變數。如果未指定 varTypeSpec,則演算法使用以下規則:
- 所有輸入變數預設被視為序數變數。如果某些列包含非數值,例如“apple”、“pear”、“apple”、“apple”、“mango”,則相應變數被視為類別變數。
- 如果有多個輸出變數,則它們都被視為序數變數。如果使用非數值,則會報告 Error。
- 如果只有一個輸出變數,則如果其值是非數值或全是整數,則它被視為類別變數。否則,它被視為序數變數。
|
| delimiter | 用於分隔每行中值的字元。 |
| missch | 用於指定缺失測量的字元。它不應該是一個數字。儘管它是一個非數值,但它肯定不會影響變數是序數還是類別的決定。 |
- 注意
- 如果資料集僅包含輸入變數而沒有響應,請使用 responseStartIdx = -2 和 responseEndIdx = 0。輸出變數向量將僅包含零。
◆ missingValue()
| static float cv::ml::TrainData::missingValue |
( |
| ) |
|
|
inlinestatic |
◆ setTrainTestSplit()
| virtual void cv::ml::TrainData::setTrainTestSplit |
( |
int | count, |
|
|
bool | shuffle = true ) |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.setTrainTestSplit( | count[, shuffle] | ) -> | None |
◆ setTrainTestSplitRatio()
| virtual void cv::ml::TrainData::setTrainTestSplitRatio |
( |
double | ratio, |
|
|
bool | shuffle = true ) |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.setTrainTestSplitRatio( | ratio[, shuffle] | ) -> | None |
將訓練資料分為訓練部分和測試部分。
該函式選擇指定相對大小的子集,然後將其作為訓練集返回。如果未呼叫該函式,則所有資料都用於訓練。請注意,對於每個 TrainData::getTrain* 都有相應的 TrainData::getTest*,因此也可以檢索和處理測試子集。
- 另請參閱
- TrainData::setTrainTestSplit
◆ shuffleTrainTest()
| virtual void cv::ml::TrainData::shuffleTrainTest |
( |
| ) |
|
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.shuffleTrainTest( | | ) -> | None |
該類的文件由以下檔案生成: