G G*_* Gr 5 statistics matlab classification machine-learning
如何在MATLAB中对一行单独的单元格进行分类?
目前我可以像这样分类单个coloums:
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
Run Code Online (Sandbox Code Playgroud)
与上述不同,我想分类:
A B C
Row A | 1 | 1 | 1 = a house
Row B | 1 | 2 | 1 = a garden
Run Code Online (Sandbox Code Playgroud)
这是MATLAB站点的代码示例:
nb = NaiveBayes.fit(training, class)
nb = NaiveBayes.fit(..., 'param1', val1, 'param2', val2, ...)
Run Code Online (Sandbox Code Playgroud)
我不明白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)
Run Code Online (Sandbox Code Playgroud)
本例中的输出是 2 个错误分类的实例:
ans =
15 0 1
0 20 0
1 0 13
Run Code Online (Sandbox Code Playgroud)
现在您可以为分类器自定义各种选项(您提到的参数/值),只需参考以获取每个选项的描述。
例如,它允许您选择高斯或非参数核分布来对特征进行建模。您还可以指定类别的先验概率,应该根据训练实例进行估计,还是假设概率相等。