24小时热门版块排行榜    

查看: 3503  |  回复: 3

zgyzhp

新虫 (初入文坛)

[求助] matlab libsvm中svm参数优化时准确率超低,只有7%!求解决办法!!!

求大神救命!!!我快绝望了!我根据网上教程,在svm做参数c,g优化时,准确率超级低,只有7%!这是什么原因,求解答!另外,我不知道数据怎么像heart_scale.m里面有2个数据heart_scale_int和heart_scale_labels,所以我把我的数据保存成2个.m文件,一个是因变量,只有一个因变量(data_labels.m),一个是自变量数据,共9个自变量(data.m)。不知道有没有什么影响。ps,我的数据是用matlab打开excel文件,再将它保存为.m格式,需要将数据变成libsvm格式吗?下面是我的运行程序。
CODE:
load data
>> load data_labels
>> train_data=[data(1:57,:)];
>> train_data_labels=[data_labels(1:57)];
>> test_data=[data(58:71,:)];
>> test_data_labels=[data_labels(58:71)];
>> [train_data,pstrain]=mapminmax(train_data');
>> pstrain.ymin=0;
>> patrain.ymax=1;
>> [train_data,pstrain]=mapminmax(train_data,pstrain);
>> test_data=[data(58:71,:)];
>> [test_data,pstest]=mapminmax(test_data');
>> pstest.ymin=0;
>> pstest.ymax=1;
>> [test_data,pstest]=mapminmax(test_data,pstest);
>> train_data=train_data';
>> test_data=test_data';
>> [bestacc,bestc,bestg] = SVMcgForClass(train_data_labels,train_data,-10,10,-10,10);
部分结果显示为:
optimization finished, #iter = 1
nu = 0.000977obj = -1.000000, rho = 0.000000nSV = 2, nBSV = 0
*optimization finished, #iter = 1
nu = 0.000977obj = -1.000000, rho = 0.000000nSV = 2, nBSV = 0
*optimization finished, #iter = 1
nu = 0.000977obj = -1.000000, rho = 0.000000nSV = 2, nBSV = 0
*optimization finished, #iter = 1
nu = 0.000977obj = -1.000000, rho = 0.000000nSV = 2, nBSV = 0Total nSV = 22
Cross Validation Accuracy = 7.01754%
求大神解答!!!!救命!!!一定要看到我!!!!!
下面是SVMcgForClass程序文件
function [ bestacc,bestc,bestg ] = SVMcgForClass(train_data_labels,train_data,cmin,cmax,gmin,gmax,v,cstep,gstep,accstep)
%UNTITLED3 Summary of this function goes here
%   Detailed explanation goes here
% SVMcgForClass
% 输入:
% train_data_labels:训练集标签.要求与libsvm工具箱中要求一致.
% train:训练集.要求与libsvm工具箱中要求一致.
% cmin:惩罚参数c的变化范围的最小值(取以2为底的对数后),即 c_min = 2^(cmin).默认为 -5
% cmax:惩罚参数c的变化范围的最大值(取以2为底的对数后),即 c_max = 2^(cmax).默认为 5
% gmin:参数g的变化范围的最小值(取以2为底的对数后),即 g_min = 2^(gmin).默认为 -5
% gmax:参数g的变化范围的最小值(取以2为底的对数后),即 g_min = 2^(gmax).默认为 5
% v:cross validation的参数,即给测试集分为几部分进行cross validation.默认为 3
% cstep:参数c步进的大小.默认为 1
% gstep:参数g步进的大小.默认为 1
% accstep:最后显示准确率图时的步进大小.默认为 1.5
% 输出:
% bestacc:Cross Validation 过程中的最高分类准确率
% bestc:最佳的参数c
% bestg:最佳的参数g
% about the parameters of SVMcgForClass
if nargin < 10
    accstep = 1.5;
end
if nargin < 8
    accstep = 1.5;
    cstep = 1;
    gstep = 1;
end
if nargin < 7
    accstep = 1.5;
    v = 3;
    cstep = 1;
    gstep = 1;
end
if nargin < 6
    accstep = 1.5;
    v = 3;
    cstep = 1;
    gstep = 1;
    gmax = 5;
end
if nargin < 5
    accstep = 1.5;
    v = 3;
    cstep = 1;
    gstep = 1;
    gmax = 5;
    gmin = -5;
end
if nargin < 4
    accstep = 1.5;
    v = 3;
    cstep = 1;
    gstep = 1;
    gmax = 5;
    gmin = -5;
    cmax = 5;
end
if nargin < 3
    accstep = 1.5;
    v = 3;
    cstep = 1;
    gstep = 1;
    gmax = 5;
    gmin = -5;
    cmax = 5;
    cmin = -5;
end
% X:c Y:g cg:accuracy
[X,Y] = meshgrid(cmin:cstep:cmax,gmin:gstep:gmax);
[m,n] = size(X);
cg = zeros(m,n);
% record accuracy with different c & g,and find the best accuracy with the smallest c
bestc = 0;
bestg = 0;
bestacc = 0;
basenum = 2;
for i=1:m
    for j = 1:n
        cmd = ['-v ',num2str(v),' -c ',num2str( basenum^X(i,j) ),' -g ',num2str(basenum^Y(i,j) )];
        cg(i,j) = svmtrain(train_data_labels, train_data, cmd);
        if cg(i,j) > bestacc
            bestacc = cg(i,j);
            bestc = basenum^X(i,j);
            bestg = basenum^Y(i,j);
        end
        if ( cg(i,j) == bestacc && bestc > basenum^X(i,j) )
            bestacc = cg(i,j);
            bestc = basenum^X(i,j);
            bestg = basenum^Y(i,j);
        end
    end
end
% draw the accuracy with different c & g
figure;
[C,h] = contour(X,Y,cg,60:accstep:100);
clabel(C,h,'FontSize',20,'Color','r');
xlabel('log2c','FontSize',20);
ylabel('log2g','FontSize',20);
title('参数选择结果图(grid search)','FontSize',10);
grid on;

end

另外,我的参数选择结果图也没有内容,不知道是什么原因?是因为准确率太低吗?下面是我的2个数据,拜托了!!!

[ Last edited by jjdg on 2017-7-8 at 17:25 ]
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zgyzhp

新虫 (初入文坛)

上面的笑脸是:,不知道怎么变成这个了,更正一下,上面3行带笑脸的分别是
train_data=[data(1:57,:];  
test_data=[data(58:71,:];  
test_data=[data(58:71,:];
不要沉
2楼2017-07-07 21:26:34
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

zgyzhp

新虫 (初入文坛)

求大神帮忙!!!!!!
3楼2017-07-08 14:00:05
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

somomo91

专家顾问 (职业作家)

引用回帖:
2楼: Originally posted by zgyzhp at 2017-07-07 21:26:34
上面的笑脸是:,不知道怎么变成这个了,更正一下,上面3行带笑脸的分别是
train_data=;  
test_data=;  
test_data=;
不要沉

你把数据编辑掉了,没法下载数据
4楼2017-07-09 20:33:10
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 zgyzhp 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 26考研一志愿中国石油大学(华东)305分求调剂 +5 嘉年新程 2026-03-15 5/250 2026-03-21 15:20 by 巴黎材料
[考研] 280求调剂 +8 咕噜晓晓 2026-03-18 9/450 2026-03-21 15:01 by lature00
[考研] 初试 317 +3 半拉月丙 2026-03-20 3/150 2026-03-21 13:25 by zhukairuo
[考研] 332求调剂 +3 凤凰院丁真 2026-03-20 3/150 2026-03-21 10:27 by luoyongfeng
[考研] 0856材料专硕353求调剂 +3 NIFFFfff 2026-03-20 3/150 2026-03-21 10:23 by luoyongfeng
[考研] 材料学学硕080502 337求调剂-一志愿华中科技大学 +4 顺顺顺mr 2026-03-18 5/250 2026-03-21 10:22 by luoyongfeng
[考研] 求调剂 +6 Mqqqqqq 2026-03-19 6/300 2026-03-21 08:04 by JourneyLucky
[考研] 346求调剂[0856] +4 WayneLim327 2026-03-16 7/350 2026-03-21 04:02 by JourneyLucky
[考研] 08工科 320总分 求调剂 +6 梨花珞晚风 2026-03-17 6/300 2026-03-21 03:40 by JourneyLucky
[考研] 265求调剂 +3 Jack?k?y 2026-03-17 3/150 2026-03-21 03:17 by JourneyLucky
[考研] 一志愿西安交通大学 学硕 354求调剂211或者双一流 +3 我想要读研究生 2026-03-20 3/150 2026-03-20 20:13 by JourneyLucky
[考研] 353求调剂 +3 拉钩不许变 2026-03-20 3/150 2026-03-20 19:56 by JourneyLucky
[考研] 一志愿吉林大学材料学硕321求调剂 +11 Ymlll 2026-03-18 15/750 2026-03-20 19:40 by 丁丁*
[考研] 085410人工智能专硕317求调剂(0854都可以) +4 xbxudjdn 2026-03-18 4/200 2026-03-20 09:07 by 不168
[考研] 320求调剂0856 +3 不想起名字112 2026-03-19 3/150 2026-03-19 22:53 by 学员8dgXkO
[考研] 288求调剂,一志愿华南理工大学071005 +5 ioodiiij 2026-03-17 5/250 2026-03-19 18:22 by zcl123
[考研] 085601材料工程专硕求调剂 +10 慕寒mio 2026-03-16 10/500 2026-03-19 15:26 by 丁丁*
[考研] 0703化学调剂 +5 pupcoco 2026-03-17 8/400 2026-03-19 13:58 by houyaoxu
[考研] 0703化学 305求调剂 +4 FY_yy 2026-03-14 4/200 2026-03-19 05:54 by anny19840123
[考研] 070303 总分349求调剂 +3 LJY9966 2026-03-15 5/250 2026-03-16 14:24 by xwxstudy
信息提示
请填处理意见