基于支持向量机的二次函数在Matlab中的应用
>> format compact;
>> x = (-1:0.1:1)’;
>> y = -x.^2;
>> model = svmtrain(y,x,’-s 3 -t 2 -c 2.2 -g 2.8 -p 0.01′);
. WARNING: using -h 0 may be faster
optimization finished, #iter = 104
nu = 0.224906
obj = -0.675055, rho = 0.698514
nSV = 9, nBSV = 2
>> [py , mse] = svmpredict( y , x , model );
Mean squared error = 9.52768e-005 (regression)
Squared correlation coefficient = 0.999184 (regression)
>> figure;
>> plot(x , y, ‘o’);
>> hold on;
>> plot(x, py, ‘r*’);
>> legend(‘原始数据’,’回归数据’);
>> grid on;
>> testx = [1.1;1.2;1.3];
>> display(‘真实数据’)
真实数据
>> testy = -testx.^2
testy =
-1.2100
-1.4400
-1.6900
>> [ ptesty , tmse ] = svmpredict( testy , testx , model);
Mean squared error = 0.0976693 (regression)
Squared correlation coefficient = 0.914542 (regression)
>> display(‘预测数据’);
预测数据
>> ptesty
ptesty =
-1.1087
-1.1913
-1.2200