简体   繁体   English

在LIBSVM matlab中执行其他验证

[英]Performing additional validation in LIBSVM matlab

I am working on MATLAB LIBSVM for a while to do prediction. 我正在研究MATLAB LIBSVM一段时间做预测。 I have a dataset out of which I use 75% for training, 15% for finding best parameters and remaining for testing. 我有一个数据集,其中75%用于培训,15%用于查找最佳参数并保留用于测试。 The code is given below. 代码如下。

trainX and trainY are the input and output training instances
testValX and testValY are the validation dataset I use
for j = 1:100
    for jj = 1:10
        model(j,jj) = svmtrain(trainY,trainX,...
        ['-s 3 -t 2 -c ' num2str(j) ' -p 0.001 -g ' num2str(jj) '-v 5']);
        [predicted_label, ~, ~]=svmpredict(testValY,...
        testValX,model(j,jj));
        MSE(j,jj) = sum(((predicted_label-testValY).^2)/2);
    end
end
[min_val,min_indi] = min(MSE(:));
best_predicted_model_rbf(i) = model(min_indi);

My question here is whether this is correct. 我的问题是这是否正确。 I am creating model matrix with different values of c and g. 我正在创建具有不同c和g值的模型矩阵。 I use -v option which is a key here. 我使用-v选项,这是一个关键。 From the predicted models I use validation dataset for prediction and there by compute mean square error. 从预测的模型中,我使用验证数据集进行预测,并使用计算均方误差。 Using this MSE I pick the best c and g. 使用这个MSE我选择最好的c和g。 Since I am using -v which returns the cross validated output, is the procedure I follow correct? 由于我使用-v返回交叉验证输出,我遵循的程序是否正确?

First, I think there is a slight problem with the code shown, which is that num2str(jj) '-v 5']); 首先,我认为显示的代码存在轻微问题,即num2str(jj) '-v 5']); doesn't have a space before the -v. 在-v之前没有空格。 That may cause that flag to not be read. 这可能导致该标志无法读取。 In the other question, you stated that this 'sometimes returns a model', which is what would happen if that flag was not read. 在另一个问题中,你说过这个“有时会返回一个模型”,如果没有读取该标志会发生这种情况。 If the flag is read, you should only get a number, not a model, when the '-v' flag is used. 如果读取该标志,则在使用'-v'标志时,您应该只获得一个数字,而不是模型。

Second, it looks like you are doing two different things here, either one of which would be reasonable on its own. 其次,看起来你在这里做了两件不同的事情,其中​​任何一件都是合理的。 Calling svmtrain with '-v' runs cross validation on the training set. 使用'-v'调用svmtrain会在训练集上运行交叉验证。 That shouldn't return a model, it should just return an mse estimate. 这不应该返回一个模型,它应该只返回一个mse估计。 You could use these estimates to determine which parameter setting was best, and then train one model with that setting on all of the training data. 您可以使用这些估计值来确定哪个参数设置最佳,然后在所有训练数据上训练一个具有该设置的模型。

Anyway, next you call svmpredict(y,x,model) on a hold-out validation set, testValX, but having called svmtrain with '-v', model should just be a scalar at this point. 无论如何,接下来你在保持验证集testValX上调用svmpredict(y,x,model),但是用'-v'调用了svmtrain,模型在这一点上应该只是一个标量。 In order for this call to run correctly, you have to get the model from svmtrain without '-v', so that it is a struct. 为了使此调用正确运行,您必须从svmtrain获取模型而不使用'-v',以便它是一个结构。 The rest of what you are doing makes sense for this case, in which you are doing hold-out validation using testValX. 你正在做的其他事情对于这种情况是有意义的,你正在使用testValX进行保持验证。

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

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