- Fit discriminant analysis classifier: https://in.mathworks.com/help/stats/fitcdiscr.html
- Cell Arrays: https://in.mathworks.com/help/matlab/ref/cell.html
- Convert table to homogenous array: https://in.mathworks.com/help/matlab/ref/table2array.html
LDA with 2D vectors as predictors
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi folks,
I have a (4X21) table. The 20 first columns are the predictors which contain 2d vectors eg [-1.014;-0.0194] the last column contains the class.. I use fitdiscr() but I get the error "Table variable trial1 is not a valid predictor". I suspect this happens because the predictors are vectors? Any solutions?? Thank you in advance
train_table=cell2table(tr_all,'VariableNames',{'trial1','trial2','trial3','trial4','trial5','trial6','trial7','trial8','trial9','trial10','trial11', 'trial12', 'trial13', 'trial14', 'trial15', 'trial16', 'trial17','trial18','trial19', 'trial20'});
train_table.trustee=[1;2;3;4];
Mdl_lda=fitcdiscr(train_table,'trustee');
Error using classreg.learning.internal.table2FitMatrix>makeXMatrix
Table variable trial1 is not a valid predictor.
Error in classreg.learning.internal.table2FitMatrix (line 123)
makeXMatrix(X,PredictorNames,CategoricalPredictors,OrdinalIsCategorical,ReferenceLevels);
Error in classreg.learning.classif.FullClassificationModel.prepareData (line 815)
[X,Y,vrange,wastable,varargin] = classreg.learning.internal.table2FitMatrix(X,Y,varargin{:});
Error in classreg.learning.FitTemplate/fit (line 246)
this.PrepareData(X,Y,this.BaseFitObjectArgs{:});
Error in ClassificationDiscriminant.fit (line 107)
this = fit(temp,X,Y);
Error in fitcdiscr (line 168)
this = ClassificationDiscriminant.fit(X,Y,RemainingArgs{:});
Error in Ws_classification_ind (line 143)
Mdl_lda=fitcdiscr(train_table,'trustee');
0 Kommentare
Antworten (1)
Moksh
am 22 Sep. 2023
Hi Efstathios,
I understand that you are using the “fitcdiscr” function on a table in MATLAB and are facing the mentioned error.
You can try separating the predictor and class columns and convert them into arrays before passing them into the function.
I have created a table as per the mentioned specifications and showed how to do this in the following code:
% Recreating the table with the provided specifications
trial = rand(4, 20);
classes = cell(4, 1);
% Assigning class labels (Random)
classes{1} = 'c1';
classes{2} = 'c2';
classes{3} = 'c1';
classes{4} = 'c1';
% Table with the given specifications
table = array2table(trial);
table.class = classes;
% Converting the predictor variables to seperate array
columnsToConvert = 1:20;
predictorColumns = table(:, columnsToConvert);
predictors = table2array(predictorColumns);
% Class array
classesColumn = table2array(table(:, 21));
% Using the fitcdiscr function
fit = fitcdiscr(predictors, classesColumn);
Here, I am assuming that all the required data is already there, so I have just showed how to perform indexing on some randomly generated data.
For more information about the above used functions, please refer to the following documentation:
Hope this information helps!
Best Regards,
Moksh Aggarwal
0 Kommentare
Siehe auch
Kategorien
Mehr zu Discriminant Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!