如何在 MATLAB 中对一行单独的单元格进行分类?
目前我可以像这样对单个colums进行分类:
training = [1;0;-1;-2;4;0;1]; % this is the sample data.
target_class = ['posi';'zero';'negi';'negi';'posi';'zero';'posi'];
% target_class are the different target classes for the training data; here 'positive' and 'negetive' are the two classes for the given training data
% Training and Testing the classifier (between positive and negative)
test = 10*randn(25, 1); % this is for testing. I am generating random numbers.
class = classify(test,training, target_class, 'diaglinear') % This command classifies the test data depening on the given training data using a Naive Bayes classifier
与上面不同的是,我要分类:
A B C
Row A | 1 | 1 | 1 = a house
Row B | 1 | 2 | 1 = a garden
这是来自 MATLAB 站点的代码示例:
nb = NaiveBayes.fit(training, class)
nb = NaiveBayes.fit(..., 'param1', val1, 'param2', val2, ...)
param1
、val1
等是什么我不明白。谁能帮忙?
最佳答案
这里是一个改编自文档的例子:
%# load data, and shuffle instances order
load fisheriris
ord = randperm(size(meas,1));
meas = meas(ord,:);
species = species(ord);
%# lets split into training/testing
training = meas(1:100,:); %# 100 rows, each 4 features
testing = meas(101:150,:); %# 50 rows
train_class = species(1:100); %# three possible classes
test_class = species(101:150);
%# train model
nb = NaiveBayes.fit(training, train_class);
%# prediction
y = nb.predict(testing);
%# confusion matrix
confusionmat(test_class,y)
本例中的输出是 2 个错误分类的实例:
ans =
15 0 1
0 20 0
1 0 13
现在您可以自定义分类器的各种选项(您提到的参数/值),只需引用 documentation每一个的描述..
例如,它允许您选择高斯分布或非参数核分布来对特征进行建模。您还可以指定类的先验概率,它应该从训练实例中估计出来,还是假设概率相等。
关于statistics - 朴素贝叶斯行分类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11279067/