封裝訓練資料的類。 更多...
#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 | ) -> | 無 |
◆ 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 | ) -> | 無 |
◆ 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 & | 矩陣, |
|
|
const Mat & | idx, |
|
|
int | layout ) |
|
static |
| Python |
|---|
| cv.ml.TrainData.getSubMatrix( | matrix, idx, layout | ) -> | retval |
| cv.ml.TrainData_getSubMatrix( | matrix, idx, layout | ) -> | retval |
從矩陣中提取由傳入索引指定的行/列。
- 引數
-
| 矩陣 | 輸入矩陣(支援型別: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 | ) -> | 無 |
◆ 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”,則相應的變數被視為分型別。
- 如果存在多個輸出變數,它們都被視為序數型。錯誤會在使用非數值時報告。
- 如果存在單個輸出變數,則如果其值為非數值或全部為整數,則被視為分型別。否則,被視為序數型。
|
| delimiter | 用於分隔每行值的字元。 |
| missch | 用於指定缺失測量值的字元。它不應是數字。儘管它是一個非數值,但它肯定不會影響變數是有序型還是分型別的決定。 |
- 注意
- 如果資料集只包含輸入變數而沒有響應,請使用 responseStartIdx = -2 和 responseEndIdx = 0。輸出變數向量將只包含零。
◆ missingValue()
| static float cv::ml::TrainData::missingValue |
( |
| ) |
|
|
內聯靜態 |
◆ setTrainTestSplit()
| virtual void cv::ml::TrainData::setTrainTestSplit |
( |
int | count, |
|
|
bool | shuffle = true ) |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.setTrainTestSplit( | count[, shuffle] | ) -> | 無 |
◆ setTrainTestSplitRatio()
| virtual void cv::ml::TrainData::setTrainTestSplitRatio |
( |
double | ratio, |
|
|
bool | shuffle = true ) |
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.setTrainTestSplitRatio( | ratio[, shuffle] | ) -> | 無 |
將訓練資料分為訓練部分和測試部分。
該函式選擇指定相對大小的子集,然後將其作為訓練集返回。如果未呼叫該函式,則所有資料都將用於訓練。請注意,對於每個 TrainData::getTrain*,都有相應的 TrainData::getTest*,因此也可以檢索和處理測試子集。
- 另請參見
- TrainData::setTrainTestSplit
◆ shuffleTrainTest()
| virtual void cv::ml::TrainData::shuffleTrainTest |
( |
| ) |
|
|
純虛擬函式 |
| Python |
|---|
| cv.ml.TrainData.shuffleTrainTest( | | ) -> | 無 |
此類的文件是從以下檔案生成的