Vector of floating-point numbers

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

upload your code and datas
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?
The Y vector represents the response of the TreeBagger algorithm as I trained the algorithm to predict some variables. I used that previously on just one output and it was working well. Currently, I am using 45 outputs. Anyway, in case that I got this error in general talk, how can I solve this error? As I mentioned that the class of the vector that I have is double.
"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.
Ibrahim's "Answer" moved here:
%%%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.

Sign in to comment.

Answers (1)

Yfit = predict(B,X)

7 Comments

Thank you but the error appears by training B. If you try to run the overmentioned code, you will find the error.
Bruno Luong
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.
Ibrahim
Ibrahim on 4 Nov 2018
Edited: Ibrahim on 4 Nov 2018
Thank you to inform me that, the question is updated based on your comment. I know that if the Y is a vector of (5x1), the TreeBagger will learn, But my question is how to train the TreeBagger algorithm to predict 2 outputs or more which means Y is a matrix (5x2) in this case.
Bruno Luong
Bruno Luong on 4 Nov 2018
Edited: Bruno Luong on 4 Nov 2018
What about training twice? One for each set of outcomes (column).
This will solve the error but If I have 45 outputs that will be an issue. Moreover, I am going to study the variable importance of each input to the output and traing several times will not give my a cumulative result of the measure. The variable importance measure as following:
bar(B.OOBPermutedVarDeltaError);
title('Variable Importance');
xlabel('Variable Number');
ylabel('Out-of-Bag Variable Importance');
Bruno Luong
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.
Thank you Ok, I will try this solution and back to you.

Sign in to comment.

Asked:

on 3 Nov 2018

Edited:

on 4 Nov 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!