svm回归matlab工具箱很慢,svm加强工具箱回归训练与预测问题

%% a_template_flow_usingSVM_regress

%for regression

%%

% by faruto

%Email:patrick.lee@foxmail.com QQ:516667408 http://blog.sina.com.cn/faruto BNU

%last modified 2010.01.17

%Super Moderator @ www.ilovematlab.cn

%% 若转载请注明:

% faruto and liyang , LIBSVM-farutoUltimateVersion

% a toolbox with implements for support vector machines based on libsvm, 2009.

% Software available at https://www.ilovematlab.cn

%

% Chih-Chung Chang and Chih-Jen Lin, LIBSVM : a library for

% support vector machines, 2001. Software available at

% http://www.csie.ntu.edu.tw/~cjlin/libsvm

%%

close all;

clear;

clc;

format compact;

%%

load x123

% load windspeed.mat;

% load traffic;

% load test1;

%%

% train_x = X;

% train_y = Y;

% train_x = traffic(1:4,:)';;

% train_y = traffic(5,:)';

%

train_x = [1:17]';

train_y = x1(train_x);

test_x = [18;19;20];

test_y = x1(test_x);

%% 归一化预处理

[train_x,test_x] = scaleForSVM(train_x,test_x,0,1);

% [train_x,test_x] = scaleForSVM(train_x,train_x,0,1);

[train_y_scale,test_y_scale,ps] = scaleForSVM(train_y,test_y,0,1);

% [train_y_scale,test_x,ps] = scaleForSVM(train_y,train_y,0,1);

% train_y_scale = train_y;

% test_y_scale = test_y;

%% pca

% [train_x,test_x] = pcaForSVM(train_x,test_x,93);

% [train_x,train_x] = pcaForSVM(train_x,train_x,90);

%% 参数寻优

[bestmse,bestc,bestg] = SVMcgForRegress(train_y_scale,train_x)

cmd = ['-c ',num2str(bestc),' -g ',num2str(bestg),' -s 3 -p 0.01'];

%% 训练并对训练集回归预测

model = svmtrain(train_y_scale, train_x,cmd);

[ptrain, train_mse] = svmpredict(train_y_scale, train_x, model);

ptrain = mapminmax('reverse',ptrain',ps);

ptrain = ptrain';

%% 可视化

figure;

subplot(2,1,1);

plot(train_y,'-o');

hold on;

plot(ptrain,'r-s');

grid on;

legend('original','predict');

title('Train Set Regression Predict by SVM');

%% predict on test set

[ptest, test_mse] = svmpredict(test_y_scale,test_x, model);

ptest = mapminmax('reverse',ptest',ps);

ptest = ptest';

test_y

ptest

%% 可视化

subplot(2,1,2);

plot(test_y,'-d');

hold on

plot(ptest,'r-*');

legend('original','predict');

title('Test Set Regression Predict by SVM');

grid on;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值