How to use for loops for hyperparameter tuning using fitcnb
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Don Mathis
am 15 Nov. 2018
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Naive Bayes finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!