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!