使用FanChenLinSupportVectorRegression进行预测

时间:2018-03-03 18:29:09

标签: machine-learning regression svm accord.net

我想在accord.net中使用FanChenLinSupportVectorRegression。预测对于学习输入是正确的,但该模型不适用于其他输入。我不明白我的错误?

在下面的示例中,第一个预测是好的,但是如果我们想要预测未学习的配置,无论输入如何,预测总是相同的:

// Declare a very simple regression problem
// with only 2 input variables (x and y):
double[][] inputs =
{
    new[] { 3.0, 1.0 },
    new[] { 7.0, 1.0 },
    new[] { 3.0, 1.0 },
    new[] { 3.0, 2.0 },
    new[] { 6.0, 1.0 },
};

// The task is to output a weighted sum of those numbers 
// plus an independent constant term: 7.4x + 1.1y + 42
double[] outputs =
{
    7.4*3.0 + 1.1*1.0 + 42.0,
    7.4*7.0 + 1.1*1.0 + 42.0,
    7.4*3.0 + 1.1*1.0 + 42.0,
    7.4*3.0 + 1.1*2.0 + 42.0,
    7.4*6.0 + 1.1*1.0 + 42.0,
};


// Create a LibSVM-based support vector regression algorithm
var teacher = new FanChenLinSupportVectorRegression<Gaussian>()
{
                Tolerance = 1e-5,
                // UseKernelEstimation = true, 
                // UseComplexityHeuristic = true
                Complexity = 10000,
                Kernel = new Gaussian(0.1)
};

// Use the algorithm to learn the machine
var svm = teacher.Learn(inputs, outputs);

// Get machine's predictions for inputs
double[] prediction = svm.Score(inputs);

// It's OK the predictions are correct
double[][] inputs1 =
{
    new[] { 2.0, 2.0 },
    new[] { 5.0, 1.0 },

};
prediction = svm.Score(inputs1);

// predictions are wrong! what is my mistake?

0 个答案:

没有答案