Ask Your Question

RandomForest->predict always results 0

asked 2013-11-18 21:53:14 -0500

siso gravatar image

updated 2013-11-20 04:06:40 -0500

I am trying to predict an output from a feature vector. However the following code is always giving a result of 0. I have build a tree and trained it with many input of values 1 and 2 and I have saved this tree in the xml. When I try to predict the answer is always 0. Does anyone have an idea why this could happen ?

CvRTrees *aforest = new CvRTrees;


Mat predictionTraits(1, 250, CV_32FC1);

for(uint i = 0; i < featureVector.size(); i++){<float>(0, i) = featureVector[i];

float result = aforest->predict(predictionTraits);
cout << "The result for this gesture has label" << result <<"\n" ;
edit retag flag offensive close merge delete


Hi, I'm siso's teammate. I just wanted to add that we are trying to use CvRTrees with feature vectors of variable length, and we believe than the problem might originate from this. For instance, a feature vector could be [1,2,3,1,2] or [1,1,2,3,3,1,2] and represent the same output. I suppose we could pad the vectors with a certain value (such as 0), but how can we ensure that this value will be ignored by the classifier? We have tried using Mat masks to solve the issue, but it doesn't seem to help. Either there is a bug in our implementation, or CvRTrees cannot be used with variable length inputs.

LadyZayin gravatar imageLadyZayin ( 2013-11-18 22:51:35 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-11-20 04:09:52 -0500

Current tree classification doesn't allow you to use feature vectors that are not constant in length. Nor does the complete ML module. I suggest creating a fixed set of vectors, which can be filled with correct values. Ignoring 0 values for example will never work, since you create a feature dimension that cannot be filled during classification. If you do want the functionality, the only way to do this is to crack open the source code, make adaptations to the algorithm and make a new implementation. If you do so, feel free to submit it as a pull request so that the feature might get added to the library.

edit flag offensive delete link more


the quesion is also if a shorter feature vector makes sense at all? How should the classifier split the planes then?

Guanta gravatar imageGuanta ( 2013-11-20 05:48:12 -0500 )edit

Well actually, you cannot make your vector larger that the smallest description you have lying around. If that doesn't work, collect more features that can be extracted and enlarge the feature vector :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-11-20 08:30:54 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2013-11-18 21:53:14 -0500

Seen: 224 times

Last updated: Nov 20 '13