Error using classreg.learning.internal.classCount (line 31) You passed an unknown class '0.7641' of type double.
5 次查看(过去 30 天)
显示 更早的评论
I am trying to run the HAR simulink to android example using the "bag" method instead of "adaboostM2", the lines of codes are as:
load humanactivity
rng('default') %for reproducibility
Partition = cvpartition(actid, 'Holdout', 0.10);
trainingInds = training(Partition); % Indices for training set
XTrain = feat(trainingInds,:);
YTrain = actid(trainingInds);
testInds = test(Partition); % Indices for test set
XTest = feat(testInds,:);
YTest = feat(testInds);
tTrain = array2table([XTrain YTrain]);
tTrain.Properties.VariableNames = [featlabels' 'Activities'];
template = templateTree('MaxNumSplits', 20, 'Reproducible', true);
classificationEnsemble = fitcensemble(XTrain, YTrain,...
'Method', 'bag',...
'NumLearningCycles', 30,...
'Learners', template, ...
'ClassNames',[1;2;3;4;5]);
partitionedModel = crossval(classificationEnsemble, 'KFold', 5);
validationAccuracy = 1-kfoldLoss(partitionedModel)
testAccuracy = 1-loss(classificationEnsemble,XTest,YTest)
I am getting the following errors shile testing:
Error using classreg.learning.internal.classCount (line 31)
You passed an unknown class '0.7641' of type double.
Error in classreg.learning.classif.ClassificationModel/prepareDataForLoss (line 316)
C = classreg.learning.internal.classCount(this.ClassSummary.ClassNames,Y);
Error in classreg.learning.classif.CompactClassificationEnsemble/loss (line 339)
[X,C,W] = prepareDataForLoss(this,X,Y,W,[],true,true);
Error in HAR (line 33)
testAccuracy = 1-loss(classificationEnsemble,XTest,YTest)
Please help me debug the code.
Thank you for your time!
0 个评论
回答(1 个)
Walter Roberson
2022-9-21
load humanactivity
rng('default') %for reproducibility
Partition = cvpartition(actid, 'Holdout', 0.10);
trainingInds = training(Partition); % Indices for training set
XTrain = feat(trainingInds,:);
YTrain = actid(trainingInds);
testInds = test(Partition); % Indices for test set
XTest = feat(testInds,:);
YTest = actid(testInds); %<---- this was your error
tTrain = array2table([XTrain YTrain]);
tTrain.Properties.VariableNames = [featlabels' 'Activities'];
template = templateTree('MaxNumSplits', 20, 'Reproducible', true);
classificationEnsemble = fitcensemble(XTrain, YTrain,...
'Method', 'bag',...
'NumLearningCycles', 30,...
'Learners', template, ...
'ClassNames',[1;2;3;4;5]);
partitionedModel = crossval(classificationEnsemble, 'KFold', 5);
validationAccuracy = 1-kfoldLoss(partitionedModel)
testAccuracy = 1-loss(classificationEnsemble,XTest,YTest)
4 个评论
Walter Roberson
2022-9-21
编辑:Walter Roberson
2022-9-26
fitcensemble() cannot be deployed to Android (or other hardware).
The workflow for deploying classifiers and approximators, is that you have to do the training with a real MATLAB session first, and you save the classification results to a file. Then you create a new project that load()'s the file and arranges input data as appropriate for the hardware, and uses predict() or whichever function is appropriate for the object class. The training portion cannot take place on the deployed hardware, but the results of training can be used on the hardware to classify or approximate.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Modeling 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!