How to use for loops for hyperparameter tuning using fitcnb

조회 수: 1 (최근 30일)
Catherine Branter
Catherine Branter 2018년 11월 12일
편집: madhan ravi 2018년 11월 21일
I have different types of distribution I want to test for my fitcnb Naive Bayes model to see which is the bestand I'm running into an error
My code is:
%Set different types of distribution dist_1= {'kernel','mvmn','mvmn','kernel','mvmn','mvmn','mvmn','mvmn','mvmn'}; dist_2= {'normal','mvmn','mvmn','normal','mvmn','mvmn','mvmn','mvmn','mvmn'}; dist_3= {'kernel','mvmn','mvmn','normal','mvmn','mvmn','mvmn','mvmn','mvmn'}; dist_4={'normal','mvmn','mvmn','kernel','mvmn','mvmn','mvmn','mvmn','mvmn'}; distributionoptions = [dist_1 dist_2 dist_3 dist_4];
for d = distributionoptions MdlA = fitcnb(Xtrain,Ytrain,'ClassNames', class_names,'Crossval',{'Off'},'DistributionNames',d); end
The error I get is Error using classreg.learning.modelparams.NaiveBayesParams/checkDistributionNames (line 91) 'DistributionNames' value must be a character vector or string scalar, or a string array or cell array whose length equals the number of predictors.

답변 (1개)

Don Mathis
Don Mathis 2018년 11월 15일
I think you accidentally concatenated your cell arrays together. Instead use curly braces:
distributionoptions = {dist_1 dist_2 dist_3 dist_4};
After that, inside the loop, d will be a 1x1 cell array, so you need to do d{1} in there:
for d = distributionoptions
MdlA = fitcnb(Xtrain,Ytrain,'ClassNames', class_names,'Crossval',{'Off'},'DistributionNames',d{1});
end

카테고리

Help CenterFile Exchange에서 Naive Bayes에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by