Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regression same values predicted #139

Open
karasjoh000 opened this issue Mar 18, 2019 · 10 comments
Open

regression same values predicted #139

karasjoh000 opened this issue Mar 18, 2019 · 10 comments

Comments

@karasjoh000
Copy link

karasjoh000 commented Mar 18, 2019

When I train my regression problem, I only get 1 and -1 for the weights of support vectors and it produces an exact same prediction for every test vectors.

@cjlin1
Copy link
Owner

cjlin1 commented Mar 18, 2019 via email

@Nuist-Lee
Copy link

What I got is the same !
I always get the same prediction value, even if I've already changed the inputdata.
Specifically, I used 9 precipitation factors and real precipitation data from 1951 to 2010 to train the SVM regression model. Then I input the factors from 2011 to 2016 to the model in order to get the predicted precipitation data. But all I got was an array with the same 6 numberslike[248 248 248 248 248 248]. When I change the inputdata, the result may change but still an array with the same six numbers. Sometimes the result array can be 'almost' the same, like [222.121971040339 217.475177855453 221.321911068434 215.667836808570 222.829461145174].
It's also been found that only if I input the data that is very very closed to the trainnig data(1951-2010 factors), the result can be quite well.
Ironically, when I use some classic dataset (from my reference books), the result will be pretty pretty good.
Add on, RBF kernel was used, too.

@cjlin1
Copy link
Owner

cjlin1 commented Apr 27, 2022 via email

@Nuist-Lee
Copy link

This is the code for trainning.

clear all
load ("predictionfactors.mat");

[tsx,TSXps]=mapminmax(InputdataS1');
[ts,TSps]=mapminmax(JHy');
TSX=tsx';
TS=ts';


%% 选择回归预测分析最佳的SVM参数c&g

[bestmse,bestc,bestg] = gaSVMcgForRegress(TS,TSX);


% 打印选择结果
disp('打印选择结果');
str = sprintf( 'Best Cross Validation MSE = %g Best c = %g Best g = %g',bestmse,bestc,bestg);
disp(str);

%% 利用回归预测分析最佳的参数进行SVM网络训练
cmd = ['-c ', num2str(bestc), ' -g ', num2str(bestg) , ' -s 3 -p 0.01 -t 2 '];
model = svmtrain(TS,TSX,cmd);

When I load ("predictionfactors.mat"), the workspace is as follows:
image
InputdataS1 is precipitation factors in the former 60 years, which is the trainning data.InputdataS2 is that in the latter 6 years, and is used for prediction.
JHy is precipitation data in the former 60 years, and JHt is the former one.
gaSVMcgForRegressis a function written by Faruto, which can find the best c and g in SVM by using Genetic Algorithm.
Then is the code for SVM regression prediction:

    ttx=mapminmax('apply',InputdataS2',TSXps);
    tty=mapminmax('apply',JHt',TSps);
    TTX=ttx';
    TTY=tty';
    
    [predict_,mse] = svmpredict(TTY,TTX,model);
    predict_ = mapminmax('reverse',predict_',TSps);
    predict_ = predict_';

And then the value 'predict_' always be an array with same numbers, which means however I change my inputdata to the model, the prediction result is the same one.

@Nuist-Lee
Copy link

In addition , @kevin031060 said he met the same issue when using Java interface ,and Python/Matlab is fine.While mine is using Matlab toolbox.

@cjlin1
Copy link
Owner

cjlin1 commented Apr 28, 2022 via email

@Nuist-Lee
Copy link

image
image
TSX is prediction factors which are already transposed and normalizd and transposed again to be a 601 matrix.
TS is real precipitation data, operated as above. It's a 60
9 matrix.

@Nuist-Lee
Copy link

I mean 60x1 and 60x9

@Nuist-Lee
Copy link

问题解决了!谢谢林老师的耐心指导!
Issue solved!!! Thanks for your patient help!!!
The key is Y, which is the real precipitation data in my code named TS.
In fact , I have 3 precipitation data for 3 different regions. And when I choose JH region, the issue occurs.
I was always focused on the X, which is prediction factor in my code. While the Y is another part of trainning an SVR model, which was ignored for a long time.
So the result is : One region cannot match well with those precipitation factors, while another region can.

@cjlin1
Copy link
Owner

cjlin1 commented Apr 29, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants