Vector of floating-point numbers
1 view (last 30 days)
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
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.
Stephen23
on 4 Nov 2018
Edited: Stephen23
on 4 Nov 2018
%%%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
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.
See Also
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!