matlab中貝葉斯簡單使用
阿新 • • 發佈:2019-02-12
Matlab部分程式碼:
Data_prediction = load('lichen\Pima-prediction-set.txt');
Data_train = load('lichen\Pima-training-set.txt');
training_data = Data_train(:,1:8);
training_label = Data_train(:,9);
prediction_data = Data_prediction(:,1:8);
prediction_label = Data_prediction(:,9);
nb=NaiveBayes.fit(training_data,training_label);
predict_label1=predict(nb,training_data);
training_accuracy=length(find(predict_label1==training_label))/length(training_label)
首先通過對一個數據集Pima-training-set.txt 進行訓練學習,然後再去預測Pima-prediction-set.txt資料集中的結果,再與原有的正確答案進行比較,算出精確度。
資料集在網盤的blog目錄下