假设我们启动10次交叉验证来训练支持向量机,根据理论,每个折叠将使用不同的模型,并且基于最小交叉验证错误,我们将选择该模型,现在根据Accord.NET框架这是我们用来实现交叉验证的:
var crossvalidation = new CrossValidation(size: data.Length, folds: 3);
crossvalidation.Fitting = delegate(int k, int[] indicesTrain, int[] indicesValidation)
{
// Lets now grab the training data:
var trainingInputs = data.Submatrix(indicesTrain);
var trainingOutputs = xor.Submatrix(indicesTrain);
// And now the validation data:
var validationInputs = data.Submatrix(indicesValidation);
var validationOutputs = xor.Submatrix(indicesValidation);
// Create a Kernel Support Vector Machine to operate on the set
var svm = new KernelSupportVectorMachine(new Polynomial(2), 2);
// Create a training algorithm and learn the training data
var smo = new SequentialMinimalOptimization(svm, trainingInputs, trainingOutputs);
double trainingError = smo.Run();
// Now we can compute the validation error on the validation data:
double validationError = smo.ComputeError(validationInputs, validationOutputs);
// Return a new information structure containing the model and the errors achieved.
return new CrossValidationValues(svm, trainingError, validationError);
};
然后我们计算:
// Compute the cross-validation
var result = crossvalidation.Compute();
现在如何从这些折叠中提取最佳模型,或者如果不是前面提到的那样,框架的工作原理是什么?
答案 0 :(得分:0)
我开始以其他方式考虑这个问题,可能这是一个很好的答案,因为缺乏适当的文档,不像encog等。可能我们应该自己选择我们的模型然后使用每个选定的模型对其运行CrossValidation,然后可以使用Mean来选择合适的模型。
答案 1 :(得分:0)
哟可以做以下结果:
[WebMethod]
public MyClass getData()
{
HostingEnvironment.QueueBackgroundWorkItem(() => Logwriter.writeToLog("Someone requested the WebMethod 'GetData'"));
//Do some work
return _myClassObject;
}
首先找出最小错误,然后选择产生此错误的模型。