你能否给出一个在 MATLAB 中使用支持向量机 (SVM) 对 4 个类别进行分类的例子,例如:
atribute_1 atribute_2 atribute_3 atribute_4 class1 2 3 4 01 2 3 5 00 2 6 4 10 3 3 8 17 2 6 4 29 1 7 10 3
回答:
MATLAB 目前不支持多类 SVM。 你可以使用 svmtrain
(2 类)来实现这一点,但使用标准的 SVM 包会容易得多。
我使用过 LIBSVM,并且可以确认它非常容易使用。
%%# 你的数据D = [1 2 3 4 01 2 3 5 00 2 6 4 10 3 3 8 17 2 6 4 29 1 7 10 3];%%# 为了清晰起见Attributes = D(:,1:4);Classes = D(:,5);train = [1 3 5 6];test = [2 4];%%# 训练model = svmtrain(Classes(train),Attributes(train,:),'-s 0 -t 2');%%# 测试[predict_label, accuracy, prob_estimates] = svmpredict(Classes(test), Attributes(test,:), model);