void Model::Predict_gbt( const SampleSet& samples, SampleSet& outError ) { int true_resp = 0; CvGBTrees *model = (CvGBTrees*)m_pModel; for (int i = 0; i < samples.N(); i++) { float ret; ret = model->predict(samples.GetSampleAt(i), cv::Mat(), cv::Range::all()); if (ret != samples.GetLabelAt(i)) { outError.Add(samples.GetSampleAt(i), samples.GetLabelAt(i)); } else { true_resp++; } } printf("%d %d",samples.N(), true_resp); }
void find_decision_boundary_GBT() { img.copyTo( imgDst ); Mat trainSamples, trainClasses; prepare_train_data( trainSamples, trainClasses ); // learn classifier CvGBTrees gbtrees; Mat var_types( 1, trainSamples.cols + 1, CV_8UC1, Scalar(CV_VAR_ORDERED) ); var_types.at<uchar>( trainSamples.cols ) = CV_VAR_CATEGORICAL; CvGBTreesParams params( CvGBTrees::DEVIANCE_LOSS, // loss_function_type 100, // weak_count 0.1f, // shrinkage 1.0f, // subsample_portion 2, // max_depth false // use_surrogates ) ); gbtrees.train( trainSamples, CV_ROW_SAMPLE, trainClasses, Mat(), Mat(), var_types, Mat(), params ); Mat testSample(1, 2, CV_32FC1 ); for( int y = 0; y < img.rows; y += testStep ) { for( int x = 0; x < img.cols; x += testStep ) { testSample.at<float>(0) = (float)x; testSample.at<float>(1) = (float)y; int response = (int)gbtrees.predict( testSample ); circle( imgDst, Point(x,y), 2, classColors[response], 1 ); } } }