使用OpenCV随机森林进行回归
Using OpenCV Random Forest for Regression
我以前使用Random Forest进行分类任务,使用这里的示例设置参数作为指导。效果很好。但是现在我想解决一个回归问题。
我有一些想法,这与var_type Mat有关,该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
);
Training使用的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和参数的回归。
要使用它进行回归,您只需将var_type设置为CV_VAR_ORDERED即
var_type.at<uchar>(ATTRIBUTES_PER_SAMPLE, 0) = CV_VAR_ORDERED;
,您可能希望将regression_accuracy设置为一个非常小的数字,例如0.0001f。
相关文章:
- Lambda回归:这合法吗?
- RcppShark 随机森林示例引发有关随机数生成器的异常
- C++:为什么这段代码会出错?多元线性回归
- 为什么我的梯度下降算法不收敛?(用于逻辑回归)
- 逻辑回归返回错误的预测
- OPENCV逻辑回归负载失败
- C++ 吉尼回归记录.对djinni_generated的未定义引用
- 回归方法的幕后是什么?
- 为什么非回归方法比递归需要更多的时间
- "pair::operator=(pair&&)"错误,"auto&"推断出移动操作 - libstdc++ 回归?
- 从森林里造一棵n元树
- 如何在 postgreSQL 中调试回归测试二进制pg_regress
- OPENCV随机决策森林:如何获得后验概率
- 如何将DLIB用于神经网络回归
- 特征3.3.0对3.2.10的性能回归
- 如何提取Scikit-learn的回归预测器以实施到C++中
- 在C++中使用alglib实现随机森林
- 使用 OpenCV 的琐碎随机森林不起作用,与 sklearn 不同
- std::启用 C++11 时的矢量性能回归
- 使用OpenCV随机森林进行回归