Take the data out after using Classification Learner App
Ältere Kommentare anzeigen
Hi, I separated my data into training and testing data. I trained using the training data, then I tested using the testing data with the code below. It said "Unrecognized variable name 'Character'." And how can I take the data out after classification? Please help me. Thank guys.
testdata=readtable("ClassificationTestData.xlsx")
predictions = char(trainedModel.predictFcn(testdata))
% accuracy
iscorrect=predictions==cell2mat(string((testdata.Character)));
iscorrect=iscorrect(:,2);
accuracy = sum(iscorrect)*100/20;
Akzeptierte Antwort
Weitere Antworten (3)
Cris LaPierre
am 15 Dez. 2021
1 Stimme
You appear to be trying to use a variable name (Character) that does not exist in your test data file. To me, it appears the available variable names are Power, WingSpeed, WindDirect, WindSpeed, and Cluster.
2 Kommentare
Huy Cao
am 15 Dez. 2021
Cris LaPierre
am 15 Dez. 2021
I did. You need to use one of the actual variable names in your table, which appear to be Power, WingSpeed, WindDirect, WindSpeed, and Cluster.
Image Analyst
am 15 Dez. 2021
1 Stimme
You train using Power, WingSpeed, WindDirect, WindSpeed as the predictors, and Cluster as the response (ground truth).
Now when you go to use the trainedModel, you need to pass in only the predictors (columns 1-4 which are Power, WingSpeed, WindDirect, WindSpeed). Don't pass in Cluster as a predictor since the trained model won't be expecting that.
Your predictions are trainedModel.predictFcn(testdata). That's how you "can take the data out after classification". I'm not sure you need to cast it to char. And there is no column in your testdata table called "Character". Again, it needs to be Cluster since that's the column where the ground truth response for your test data is stored.
Attach trainedModel.mat if you need more help.
3 Kommentare
Huy Cao
am 15 Dez. 2021
Huy Cao
am 15 Dez. 2021
Image Analyst
am 15 Dez. 2021
Save the model to a .mat file
save('trainedModel.mat', 'trainedModel');
then attach trainedModel.mat with the paper clip icon.
Character is not a field of the table so you need to extract the ground truth labels like this
testGroundTruth = testdata.Cluster;
iscorrect= predictions == testGroundTruth;
That may not work. I won't know unless I get the model. Or I'd have to train the model myself, but I don't know which model you chose.
Also make sure you didn't train your model with Cluster being one of the predictors as well as the response. Otherwise it will ignore your other 4 inputs since Cluster is, obviously, a perfect predictor of the response.
Huy Cao
am 15 Dez. 2021
0 Stimmen
8 Kommentare
Image Analyst
am 15 Dez. 2021
Run this code:
%==============================================================================
% TRAINING
trainingData=readtable("ClassificationData.xlsx");
% The first 4 columns are the inputs.
tPredictors = trainingData(:, 1:4);
% The last column is the "answer/ground truth".
tResponse = trainingData{:, end};
% Now run Classification Learner app. Start a new session from workspace, and
% Select tPredictors as the "Data set variable" and
% select tResponse as the response.
% I did "All quick to train" and found the Fine Tree model was the best.
% I highlighted it and clicked the Export button to export trainingModel to the workspace.
% Then save it to a .mat file from the command line like this:
% save('trainedModel.mat', 'trainedModel')
Now start a new session from workspace. You should see this:

Your screenshot doesn't have New Session from Workspace in it so I think you did something different. Once you click the drop down list for Data Set Variable and pick tPredictors, then it should populate the Response. Click From Workspace and you should see tResponse.
Huy Cao
am 16 Dez. 2021
Image Analyst
am 16 Dez. 2021
I have r2021b. But tResponse should be in your response drop down list.
Huy Cao
am 16 Dez. 2021
Image Analyst
am 16 Dez. 2021
Bearbeitet: Image Analyst
am 16 Dez. 2021
Can you call tech support on that?
Anyway, I uploaded the model for you so you should be able to use that.
Huy Cao
am 17 Dez. 2021
Image Analyst
am 12 Jan. 2022
I think for earlier versions it expects the response variable to be one of the columns in your predictors table. I was just working with a guy yesterday who had r2019b and we figured out that's what it was wanting.
Huy Cao
am 12 Jan. 2022
Kategorien
Mehr zu Classification Learner App finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





