简体   繁体   English

Matlab中的Libsvm回归预测测试集实例的值相同

[英]Libsvm regression in Matlab predict same values for test set instances

I'm trying to use libsvm (Matlab library) for a regression problem. 我正在尝试将libsvm(Matlab库)用于回归问题。 I have a dataset of 192 instances. 我有192个实例的数据集。 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. 如果我使用整个数据集(model_1)来训练模型,则与测试集的每个实例相比,我将具有不同的预测值,而如果仅使用训练集,则每个测试记录将获得完全相同的值。 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. 我以为是因为训练集太小而无法训练出好的模型,所以我尝试使用190个实例进行训练,仅使用2个实例进行测试。 But even with this division I get the same predicted value for the 2 test instances? 但是,即使进行了除法运算,我对于这两个测试实例仍具有相同的预测值? Is there something wrong with the code? 代码有问题吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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