How to use for loops for hyperparameter tuning using fitcnb

2 ビュー (過去 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 Center および File ExchangeNaive Bayes についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by