5

如何在 MATLAB 中对一行单独的单元格进行分类?

目前我可以像这样对单个列进行分类:

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等是什么。任何人都可以帮忙吗?

4

1 回答 1

3

这是改编自文档的示例:

%# 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

现在您可以自定义分类器的各种选项(您提到的参数/值),只需参考文档以获取每个..

例如,它允许您从高斯或非参数内核分布中进行选择来对特征进行建模。您还可以指定类的先验概率,如果它是从训练实例估计的,还是假设概率相等。

于 2012-07-01T09:41:08.403 回答