3
當在matlab中測試樸素分類器時,即使我對相同的樣本數據進行了訓練和測試,我也得到了不同的結果,但我想知道我的代碼是否正確,並且有人可以幫助解釋爲什麼?天真的分類器matlab
%% dimensionality reduction
columns = 6
[U,S,V]=svds(fulldata,columns);
%% randomly select dataset
rows = 1000;
columns = 6;
%# pick random rows
indX = randperm(size(fulldata,1));
indX = indX(1:rows)';
%# pick random columns
%indY = randperm(size(fulldata,2));
indY = indY(1:columns);
%# filter data
data = U(indX,indY);
%% apply normalization method to every cell
data = zscore(data);
%create a training set the same as datasample
training_data = data;
%match the class labels to the corresponding rows
target_class = classlabels(indX,:)
%classify the same data sample to check if naive bayes works
class = classify(data, training_data, target_class, 'diaglinear')
confusionmat(test_class, class)
下面是一個例子:
注意到它有IPSweep進行,淚珠和背部混合了正常交通。我還沒有進入分類看不見的數據的階段,但我只想測試它是否會分類相同的數據。
混淆矩陣輸出:
ans =
537 0 0 0 0 0 0 1 0
0 224 0 0 0 1 0 1 0
0 0 91 79 0 17 24 4 0
0 0 0 8 0 0 2 0 0
0 0 0 0 3 0 0 0 0
0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 2 0 0
0 0 0 0 0 0 0 3 0
0 0 0 0 0 1 0 0 1
雖然我不知道這是什麼其實是我可能得到這個錯誤在我的代碼,但我想我只是測試,看看它輸出。
zscore標準化呢?這應該保存嗎? – 2012-07-19 15:50:07
@JungleBoogie zscore標準化當然不是一個壞主意,因爲它使您的分類方法在數值上穩定。請記住,看不見的數據必須經歷相同的轉換。準確地說:您需要從應用於訓練數據的zscore函數中提取轉換矩陣。將zscore應用於測試數據將導致使用不同的轉換。 – denahiro 2012-07-20 06:50:17