2

私のプログラムは、ユーザーからの一定量のクラスターの K-means クラスタリングを使用します。この k=4 の場合、後でクラスター化された情報を matlabs 単純ベイズ分類器で実行したいと思います。

クラスターを分割して、matlab の異なる単純な分類器に供給する方法はありますか?

単純ベイズ:

class  = classify(test,training, target_class, 'diaglinear');

K-平均:

    %% generate sample data
K = 4;
numObservarations = 5000;
dimensions = 42;
%% cluster
opts = statset('MaxIter', 500, 'Display', 'iter');
[clustIDX, clusters, interClustSum, Dist] = kmeans(data, K, 'options',opts, ...
'distance','sqEuclidean', 'EmptyAction','singleton', 'replicates',3);
%% plot data+clusters
figure, hold on
scatter3(data(:,1),data(:,2),data(:,3), 5, clustIDX, 'filled')
scatter3(clusters(:,1),clusters(:,2),clusters(:,3), 100, (1:K)', 'filled')
hold off, xlabel('x'), ylabel('y'), zlabel('z')
%% plot clusters quality
figure
[silh,h] = silhouette(data, clustIDX);
avrgScore = mean(silh);
%% Assign data to clusters
% calculate distance (squared) of all instances to each cluster centroid
D = zeros(numObservarations, K);     % init distances
for k=1:K
%d = sum((x-y).^2).^0.5
D(:,k) = sum( ((data - repmat(clusters(k,:),numObservarations,1)).^2), 2);
end
% find  for all instances the cluster closet to it
[minDists, clusterIndices] = min(D, [], 2);
% compare it with what you expect it to be
sum(clusterIndices == clustIDX)

k個のクラスターを形式k1、k2、k3に出力し、単純な分類器にそれらをピックアップさせるようなもので、テストの代わりにk1、k2..などになります。

class  = classify(k1,training, target_class, 'diaglinear');

しかし、matlab の k クラスターの出力を何らかの形式に送信する方法がわかりません。(このプログラムには本当に新しい)

編集

training = [1;0;-1;-2;4;0]; % this is the sample data.
target_class = ['posi';'zero';'negi';'negi';'posi';'zero'];% This should have the same number of rows as training data. The elements and the class on the same row should correspond.
% 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(10,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

% diaglinear is for naive bayes classifier; there is also diagquadratic
4

1 に答える 1

1

これを試して:

% create 100 random points (this is the training data)
X = rand(100,3);

% cluster into 5 clusters
K = 5;
[IDX, C] = kmeans(X, K);

% now let us say you have new data and you want 
% to classify it based on the training:
SAMPLE = rand(10,3);
CLASS = classify(SAMPLE,X,IDX);

そして、データからクラスタの 1 つだけを除外したい場合は、次のようにすることができます。

K1 = X(IDX==1)

それが役に立ったことを願っています..

于 2012-02-19T14:49:10.883 に答える