Ask Your Question
0

GBTree Returns Same Value for any sample

asked 2015-03-31 19:30:33 -0600

MRDaniel gravatar image

Hello,

I am attempting to use the machine learning tool GBTrees in OpenCV. My data wasn't working, so i have generated a simple linear sequence to train the classifier with, this returns the same value on output each time.

    std::string dataFileName = "NZ-SQL-Corpus.csv";
    TrainingData tData;// = ReadDataSource(dataFileName);

    tData.samples = cv::Mat(100,1,CV_32FC1);
    tData.samplesMask = cv::Mat::zeros(100,1,CV_8UC1);
    tData.responses = cv::Mat::zeros(100,1,CV_32FC1);

    for(int i=0;i<tData.samples.rows;i++)
    {
        tData.samples.at<float>(i,0)=i;
        tData.responses.at<float>(i,0)=i;
    }

    cv::Mat train_data = tData.samples.clone();
    cv::Mat mask = tData.samplesMask.clone();
    cv::Mat train_resp = tData.responses.clone();

    cv::GradientBoostingTreeParams params(CvGBTrees::SQUARED_LOSS, 200, 0.8f, 0.01f, 3, true);

    cv::Mat varIdx, sampleIdx, varType;
    varType = cv::Mat( train_data.cols+1, 1, CV_8U );
    varType.setTo(CV_VAR_CATEGORICAL);
    sampleIdx = cv::Mat();

    bool trained = gbTree.train(train_data,CV_ROW_SAMPLE,train_resp,varIdx,sampleIdx,varType,mask,params);
    TestClassifier(tData);

Results....

The red line is the samples, green line is the responses.

image description

The response value is 18.526666641235352 for any value between 1-100 as a sample.

Any tips?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
-2

answered 2015-04-02 04:08:25 -0600

MRDaniel gravatar image

Making tData.samplesMask = cv::Mat::zeros(100,1,CV_8UC1); into tData.samplesMask = cv::Mat::zeros(100,1,CV_8U);

Resolves issue.

edit flag offensive delete link more

Comments

1

This can't be true! At least not for OpenCV 2.4 : CV_8U and CV_8UC1 are both macros standing for the value 0 !

Guanta gravatar imageGuanta ( 2015-04-02 07:35:33 -0600 )edit

@MRDaniel, i'm also sayin: this can't be true.

berak gravatar imageberak ( 2015-04-02 12:10:59 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-03-31 19:30:33 -0600

Seen: 234 times

Last updated: Apr 02 '15