2012-07-01 18 views
5

MATLABで別々の行をどのように分類しますか?Naive Bayesの行の分類

私はそうのような単一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 

を、私は分類する:

 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, ...) 

param1val1などが分かりません。誰も助けることができますか?ここで

答えて

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 

今、あなたが分類器のためのオプションのすべての種類をカスタマイズすることができます(パラメータ/値を指定してください)、それぞれの説明についてはdocumentationを参照してください。

たとえば、ガウス型またはノンパラメトリック機能をモデル化するためのカーネル配布。また、クラスの事前確率を指定することもできます。これは、トレーニングインスタンスから推定するか、等しい確率を仮定しますか?

+0

こんにちは、このインスタンスでは、test_classは何ですか? –

+1

@JungleBoogie:テストセットの真のクラスラベルです。パフォーマンスの公平な測定値を得るために使用します(モデルを1つのセットで訓練し、完全に異なるセットでテストします)。 – Amro

+0

ああ、私は今理解しています。私はあなたのメソッドを使用しようといくつかのエラーが表示されますが、私は自分のメソッドを使用することができました(違いについては分かりません)実装を見ることができます[ここ](http://stackoverflow.com/questions/11566964/clustering-and -bayes-classifiers-matlab)を実行します。 –