用于svm的accord.net计算功能不起作用

时间:2014-11-07 07:23:54

标签: svm accord.net

我从accord.net在线文档中复制了这段代码。它由于某种原因不起作用。 http://accord-ramework.net/docs/html/T_Accord_MachineLearning_VectorMachines_SupportVectorMachine.htm

using System;
using System.Windows;
using Accord.Controls;
using Accord.MachineLearning.VectorMachines;
using Accord.MachineLearning.VectorMachines.Learning;
using Accord.Math;
using Accord.Statistics.Kernels;
namespace accord
{
class Program
{
    [MTAThread]
    static void Main(string[] args)
    {
        // Example AND problem
        double[][] inputs =
        {
            new double[] { 0, 0 }, // 0 and 0: 0 (label -1)
            new double[] { 0, 1 }, // 0 and 1: 0 (label -1)
            new double[] { 1, 0 }, // 1 and 0: 0 (label -1)
            new double[] { 1, 1 }  // 1 and 1: 1 (label +1)
        };

        // Dichotomy SVM outputs should be given as [-1;+1]
        int[] labels =
    {
        // 0,  0,  0, 1
          -1, -1, -1, 1
    };

        // Create a Support Vector Machine for the given inputs
        SupportVectorMachine machine = new SupportVectorMachine(inputs[0].Length);

        // Instantiate a new learning algorithm for SVMs
        SequentialMinimalOptimization smo = new SequentialMinimalOptimization(machine, inputs, labels);

        // Set up the learning algorithm
        smo.Complexity = 1.0;

        // Run the learning algorithm
        double error = smo.Run();

        // Compute the decision output for one of the input vectors

*****此行显示错误。它说'SVM'不存在。

        int decision = System.Math.Sign(svm.Compute(inputs[0]));

        Console.Write(decision);
    }
}

}

1 个答案:

答案 0 :(得分:0)

这是文档中的拼写错误。应该已阅读

int decision = System.Math.Sign(machine.Compute(inputs[0]));

感谢您发现问题!