Statistics 朴素贝叶斯行分类

Statistics 朴素贝叶斯行分类,statistics,machine-learning,classification,matlab,Statistics,Machine Learning,Classification,Matlab,如何在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

如何在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
,等等。有人能帮忙吗?

以下是根据文档改编的示例:

%# 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
现在,您可以自定义分类器的各种选项(您提到的参数/值),只需参考以了解每种选项的描述


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

Hi amro在这个实例中什么是test_类?@JungleBoogie:这是测试集的真实类标签。我们用它来获得一个无偏的性能度量(我们在一个集合上训练一个模型,然后在一个完全不同的集合上测试它)啊,我现在明白了。我在尝试使用您的方法时遇到了一些错误,但我设法使用了我自己的方法(不确定是否有差异)。您可以看到实现。@JungleBoogie:就上述内容而言,解决方案是好的,没有错误(并回答了所问的问题)。你的另一个问题是使用对角协方差矩阵的判别分析。虽然这两种算法被认为等同于朴素贝叶斯,但它们完全不同。。。