Matlab的libsvm 中训练参数怎么输出
答案:2 悬赏:20 手机版
解决时间 2021-02-06 03:38
- 提问者网友:ミ烙印ゝ
- 2021-02-05 13:52
Matlab的libsvm 中训练参数怎么输出
最佳答案
- 五星知识达人网友:山君与见山
- 2021-02-05 13:59
c语言版本的也记录在 model 里面.其中model 是一个结构体,其定义如下.
struct svm_model
{
struct svm_parameter param; // parameter
int nr_class; // number of classes, = 2 in regression/one class svm
int l; // total #SV
struct svm_node **SV; // SVs (SV[l])
double **sv_coef; // coefficients for SVs in decision functions (sv_coef[k-1][l])
double *rho; // constants in decision functions (rho[k*(k-1)/2])
double *probA; // pariwise probability information
double *probB;
// for classification only
int *label; // label of each class (label[k])
int *nSV; // number of SVs for each class (nSV[k])
// nSV[0] + nSV[1] + ... + nSV[k-1] = l
// XXX
int free_sv; // 1 if svm_model is created by svm_load_model
// 0 if svm_model is created by svm_train
};
里面的sv_coef就是指向 拉格朗日参数(可能乘了1或者-1)的指针的指针
=============
其实用Matlab版本的更方便
struct svm_model
{
struct svm_parameter param; // parameter
int nr_class; // number of classes, = 2 in regression/one class svm
int l; // total #SV
struct svm_node **SV; // SVs (SV[l])
double **sv_coef; // coefficients for SVs in decision functions (sv_coef[k-1][l])
double *rho; // constants in decision functions (rho[k*(k-1)/2])
double *probA; // pariwise probability information
double *probB;
// for classification only
int *label; // label of each class (label[k])
int *nSV; // number of SVs for each class (nSV[k])
// nSV[0] + nSV[1] + ... + nSV[k-1] = l
// XXX
int free_sv; // 1 if svm_model is created by svm_load_model
// 0 if svm_model is created by svm_train
};
里面的sv_coef就是指向 拉格朗日参数(可能乘了1或者-1)的指针的指针
=============
其实用Matlab版本的更方便
全部回答
- 1楼网友:拾荒鲤
- 2021-02-05 14:32
您好,很高兴为您解答。
a(1)=0;
for i=2:220
a(i)=0.6*a(i-1)+randn;
end
train_t = 1:200;
train = a(train_t);
train_t = train_t';
train = train';
test_t = 1:203;
test=a(test_t);
test_t = test_t';
test = test';
[bestmse,bestc,bestg] = svmcgforregress(train,train_t,-3,11,-7,1,3,0.5,0.5,0.1);
cmd = ['-c ',num2str(bestc),' -g ',num2str(bestg),' -p 0.01 -s 3'];
model = svmtrain(train,train_t,cmd);
[trainpre,trainmse] = svmpredict(train,train_t,model);
figure;
hold on;
plot(train);
plot(trainpre,'r');
title('原来的训练数据的拟合1-200');
legend('原来的训练数据','训练数据预测拟合数据');
hold off
[testpre,testmse] = svmpredict(test,test_t,model);
figure;
hold on;
plot(test);
plot(testpre,'r');
title('测试数据的预测1-203');
legend('测试数据','测试数据预测拟合数据');
hold off
如若满意,请点击右侧【采纳答案】,如若还有问题,请点击【追问】
希望我的回答对您有所帮助,望采纳!
~ o(∩_∩)o~
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯