简体   繁体   中英

Libsvm regression in Matlab predict same values for test set instances

I'm trying to use libsvm (Matlab library) for a regression problem. I have a dataset of 192 instances. Here is my code to divide the data in train and test set:

idx = [zeros(170,1) ;ones(22,1)];
idx = idx(randperm(192));
train = data(idx==0,:);
train_label = label(idx==0,:);
test = data(idx==1,:);
test_label = label(idx==1,:);

model_1 = svmtrain(train_label,train,'-s 3 -t 2 -c 1 -g 0.01');
model_2 = svmtrain(label,data,'-s 3 -t 2 -c 1 -g 0.01');

[y_hat, Acc,Dec] = svmpredict(test_label, test, model);

If I use the whole dataset (model_1) to train the model than for each instance of the test set I have different predicted values, while if I use only the training set I obtain exactly the same value for each test record. I thought it was because the train set could be too small to train a good model so I tried using 190 instances for training and only 2 for test. But even with this division I get the same predicted value for the 2 test instances? Is there something wrong with the code?

您应该使用缩放,尝试在代码中缩放训练向量和数据向量

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM