基于matlab的libsvm使用遇到的问题
1、遇到这个问题Error using svmclassify (line 53)
load ‘heart_scale.mat’这个例子利用加载libsvm程序在加载时出了问题,解决如下:
Error using load
Unable to read file ‘heart_scale.mat’: No such file or directory.
加载数据改为[label_vector, instance_matrix] = libsvmread('heart_scale')即可。
[attrib1, attrib2, attrib3, attrib4, class] = textread('iris.txt', '%f%f%f%f%s', 'delimiter', ',');
attrib = [attrib1'; attrib2'; attrib3'; attrib4']';
a = zeros(150, 1);
a(strcmp(class, 'Iris-setosa')) = 1;
a(strcmp(class, 'Iris-versicolor')) = 2;
a(strcmp(class, 'Iris-virginica')) = 3;
iris_new=[attrib a];
iris_train_label=iris_new([1:40 51:90 101:140],end);%每类取40个数据作为训练,共120个训练数据
iris_train_data=iris_new([1:40 51:90 101:140],1:end-1);
iris_test_label=iris_new([41:50 91:100 141:150],end);%每类取10个数据作为测试,共30个测试数据
iris_test_data=iris_new([41:50 91:100 141:150],1:end-1);
save irisdata;
model=svmtrain(iris_train_label,iris_train_data);
[iris_predict_label]=svmpredict(iris_test_label,iris_test_data,model);%,iris_accuracy