1
我以前使用隨機森林進行分類任務,使用示例here作爲參考來設置參數。它工作完美。但是現在我想解決一個迴歸問題。使用OpenCV隨機森林進行迴歸
我有一些想法,這是與var_type Mat定義隨機森林列車方法中的數據類型有關,但是不確定這些標誌對應的每一個。
對於Classifcation任務,它看起來像這樣(從上面的鏈接複製的代碼):
// define all the attributes as numerical
// alternatives are CV_VAR_CATEGORICAL or CV_VAR_ORDERED(=CV_VAR_NUMERICAL)
// that can be assigned on a per attribute basis
Mat var_type = Mat(ATTRIBUTES_PER_SAMPLE + 1, 1, CV_8U);
var_type.setTo(Scalar(CV_VAR_NUMERICAL)); // all inputs are numerical
// this is a classification problem (i.e. predict a discrete number of class
// outputs) so reset the last (+1) output var_type element to CV_VAR_CATEGORICAL
var_type.at<uchar>(ATTRIBUTES_PER_SAMPLE, 0) = CV_VAR_CATEGORICAL;
而且PARAMS設置:
float priors[] = {1,1,1,1,1,1,1,1,1,1}; // weights of each classification for classes
// (all equal as equal samples of each digit)
CvRTParams params = CvRTParams(25, // max depth
5, // min sample count
0, // regression accuracy: N/A here
false, // compute surrogate split, no missing data
15, // max number of categories (use sub-optimal algorithm for larger numbers)
priors, // the array of priors
false, // calculate variable importance
4, // number of variables randomly selected at node and used to find the best split(s).
100, // max number of trees in the forest
0.01f, // forrest accuracy
CV_TERMCRIT_ITER | CV_TERMCRIT_EPS // termination cirteria
);
培訓使用var_type而params如下:
CvRTrees* rtree = new CvRTrees;
rtree->train(training_data, CV_ROW_SAMPLE, training_classifications,
Mat(), Mat(), var_type, Mat(), params);
我的問題是,我如何設置OpenCV隨機森林,使其作爲一個regre SSOR。我搜索了很多,但一直未能找到答案。我得到的最接近的解釋是在this答案。但它仍然沒有任何意義。
我正在尋找一個解釋var_type和params迴歸的簡單答案。