我以前曾使用“随机森林”进行分类任务,使用此处的示例作为指导来设置参数。完美的作品。但是现在我想解决回归问题。
我有点想法,认为这与在“随机森林”训练方法中定义数据类型的var_type Mat有关,但是不确定每个标志对应什么。
对于分类任务,它看起来像这样(从上面的链接复制的代码):
// 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;
以及参数设置:
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随机森林,使其充当回归器。我进行了很多搜索,但未能找到答案。我得到的最接近的解释就是这个答案。但是,这仍然没有任何意义。
我正在寻找一个简单的答案来解释var_type和params进行回归。
要使用它进行回归,只需将var_type设置为CV_VAR_ORDERED即
var_type.at<uchar>(ATTRIBUTES_PER_SAMPLE, 0) = CV_VAR_ORDERED;
并且您可能希望将gression_accuracy设置为一个很小的数字,例如0.0001f。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句