Vector of floating-point numbers
Show older comments
How can I solve this error "Y must be a vector of floating-point numbers."? Y is "predictor" data of TreeBagger function. The class of the vector Y is double. I tried using the function single as well as using the format short, format long and format longg but that did not solve the issue.
%%%INPUTS
%%Training data
A1= [1.2342;2.2342;3.234;490.34;5.657];
A2= [6.77;7.888;0.898;0.911;1.990];
%%Testing data
A1_t=[23.56;8.99;0.99];
A2_t=[2.55;7.88;0.88];
%%OUTPUTS
%%Response
Z1=[6.88;7.88;9.77;0.88;90.77];
Z2=[7.98;70.88;0.07;0.98;7.98];
%%%%RFs code
%%Split training data into predictor array
X=[A1, A2];
Y=[Z1, Z2];
%%Split testing data into predictor array
Xdata=[A1_t, A2_t];
B=TreeBagger(500,X,Y,'method','regression','oobvarimp','on','oobpred','on');
This error is appeared when I used 2 outputs (Z1 and Z2) or more. Then, the main solution will be of how to use the TreeBagger algorithm to predict 2 outputs or more.
5 Comments
madhan ravi
on 3 Nov 2018
upload your code and datas
John D'Errico
on 3 Nov 2018
Edited: John D'Errico
on 3 Nov 2018
Why do you think the output of TreeBagger is a double? As a simple test...
load fisheriris
b = TreeBagger(50,meas,species,'OOBPrediction','on')
b =
TreeBagger
Ensemble with 50 bagged decision trees:
Training X: [150x4]
Training Y: [150x1]
Method: classification
NumPredictors: 4
NumPredictorsToSample: 2
MinLeafSize: 1
InBagFraction: 1
SampleWithReplacement: 1
ComputeOOBPrediction: 1
ComputeOOBPredictorImportance: 0
Proximity: []
ClassNames: 'setosa' 'versicolor' 'virginica'
Properties, Methods
whos b
Name Size Bytes Class Attributes
b 1x1 305645 TreeBagger
So TreeBagger returns an object, of class TreeBagger. Single or double would be a waste of time, as you clearly found. The function TreeBagger is a constructor for that class.
What are you trying to do with this output, and why do you think it is a double vector, when it clearly is not?
Ibrahim
on 3 Nov 2018
Image Analyst
on 3 Nov 2018
"how can I solve this error?" Did you read madhan's and John's comments? Evidently not. Hopefully you will read mine, which has as the main suggestion to read this link and fix your post by attaching code and data so that people will be able to help you.
%%%INPUTS
%%Training data
A= [1.2342;2.2342;3.234;490.34;5.657];
B= [6.77;7.888;0.898;0.911;1.990];
%%Testing data
A_t=[23.56;8.99;0.99];
B_t=[2.55;7.88;0.88];
%%OUTPUTS
%%Response
Z1=[6.88;7.88;9.77;0.88;90.77];
Z2=[7.98;70.88;0.07;0.98;7.98];
%%%%RFs code
%%Split training data into predictor array
X=[A, B];
Y=[Z1,Z2];
%%Split testing data into predictor array
Xdata=[A_t, B_t];
B=TreeBagger(500,X,Y,'method','regression','oobvarimp','on','oobpred','on');
This error is appeared when I used 2 outputs (Z1 and Z2) or more. Then, the main solution will be of how to use the TreeBagger algorithm to predict 2 outputs or more.
Answers (1)
Bruno Luong
on 4 Nov 2018
Yfit = predict(B,X)
7 Comments
Ibrahim
on 4 Nov 2018
Bruno Luong
on 4 Nov 2018
Edited: Bruno Luong
on 4 Nov 2018
bold Oh so you have a problem of training (regression) using TreeBagger, since you said Y is the "_output_ vector of TreeBagger" nobody understands.
The correct word for Y is "predictor" data.
In your case, formally Y is wrong it must by "label" 5 x 1 vector corresponds to the classification of each row of X.
You focus on the word "floating-point" but the error tells you it actually expects a vector, not an array.
Now since in your mind Y is something else (a matrix), nobody know the problem you want to solve to tell if it's correct or not.
Bruno Luong
on 4 Nov 2018
Edited: Bruno Luong
on 4 Nov 2018
What about training twice? One for each set of outcomes (column).
Ibrahim
on 4 Nov 2018
Bruno Luong
on 4 Nov 2018
Edited: Bruno Luong
on 4 Nov 2018
If you have 45 predictors (please stop using word OUTPUT that creates confusion), then just using for-loop to train 45 times.
If those 45 input-output pairs suppose to share the same mode l, then you should concatenate them in a long vector and training all together.
Ibrahim
on 4 Nov 2018
Categories
Find more on Classification Ensembles in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!