MATLAB中的分类器
目前了解到的MATLAB中分类器有:K近邻分类器,随机森林分类器,朴素贝叶斯,集成学习方法,鉴别分析分类器,支持向量机。现将其主要函数使用方法总结如下,更多细节需参考MATLAB 帮助文件。
设
训练样本:train_data % 矩阵,每行一个样本,每列一个特征
训练样本标签:train_label % 列向量
测试样本:test_data
测试样本标签:test_label
K近邻分类器 (KNN)
mdl = ClassificationKNN.fit(train_data,train_label,'NumNeighbors',1);
predict_label = predict(mdl, test_data);
accuracy = length(find(predict_label == test_label))/length(test_label)*100
随机森林分类器(Random Forest)
B = TreeBagger(nTree,train_data,train_label);
predict_label = predict(B,test_data);
朴素贝叶斯 (Na?ve Bayes)
nb = NaiveBayes.fit(train_data, train_label);
predict_label = predict(nb, test_data);
accuracy = length(find(predict_label == test_label))/length(test_label)*100;
集成学习方法(Ensembles for Boosting, Bagging, or Random Subspace)
ens = fitensemble(train_data,train_label,'AdaBoostM1' ,100,'tree','type','classification');
predict_label = predict(ens, test_data);
鉴别分析分类器(discriminant analysis classifier)
obj = ClassificationDiscriminant.fit(train_data, train_label);
predict_label = predict(obj, test_data);
支持向量机(Support Vector Machine, SVM)
SVMStruct = svmtrain(train_data, train_label);
predict_label = svmclassify(SVMStruct, test_data)
设
训练样本:train_data % 矩阵,每行一个样本,每列一个特征
训练样本标签:train_label % 列向量
测试样本:test_data
测试样本标签:test_label
K近邻分类器 (KNN)
mdl = ClassificationKNN.fit(train_data,train_label,'NumNeighbors',1);
predict_label = predict(mdl, test_data);
accuracy = length(find(predict_label == test_label))/length(test_label)*100
随机森林分类器(Random Forest)
B = TreeBagger(nTree,train_data,train_label);
predict_label = predict(B,test_data);
朴素贝叶斯 (Na?ve Bayes)
nb = NaiveBayes.fit(train_data, train_label);
predict_label = predict(nb, test_data);
accuracy = length(find(predict_label == test_label))/length(test_label)*100;
集成学习方法(Ensembles for Boosting, Bagging, or Random Subspace)
ens = fitensemble(train_data,train_label,'AdaBoostM1' ,100,'tree','type','classification');
predict_label = predict(ens, test_data);
鉴别分析分类器(discriminant analysis classifier)
obj = ClassificationDiscriminant.fit(train_data, train_label);
predict_label = predict(obj, test_data);
支持向量机(Support Vector Machine, SVM)
SVMStruct = svmtrain(train_data, train_label);
predict_label = svmclassify(SVMStruct, test_data)