C# Accord和Mulit-label支持向量机

C# Accord和Mulit-label支持向量机,c#,accord.net,C#,Accord.net,我正在研究文档中关于多类支持向量机的示例- 但是,我没有得到0的错误率,当我尝试计算值时,它们没有给出它们应该给出的输出值。这个例子有什么问题吗 static void Main(string[] args) { // Sample input data double[][] inputs = { new double[] { 0 }, new double[] { 1 },

我正在研究文档中关于多类支持向量机的示例-

但是,我没有得到0的错误率,当我尝试计算值时,它们没有给出它们应该给出的输出值。这个例子有什么问题吗

    static void Main(string[] args)
    {
        // Sample input data
        double[][] inputs =
        {
            new double[] { 0 },
            new double[] { 1 },
            new double[] { 2 },
            new double[] { 3 },
        };

        // Outputs for each of the inputs
        int[][] outputs =
            {
                new[] {1,-1,-1,-1}, 
                new[] {-1,1,-1,-1}, 
                new[] {-1,-1,1,-1}, 
                new[] {-1,-1,-1,1}, 
            };

        // Create a new Linear kernel
        IKernel kernel = new Linear();

        // Create a new Multi-class Support Vector Machine with one input,
        //  using the linear kernel and for four disjoint classes.
        var machine = new MultilabelSupportVectorMachine(1, kernel, 4);

        // Create the Multi-label learning algorithm for the machine
        var teacher = new MultilabelSupportVectorLearning(machine, inputs, outputs);

        // Configure the learning algorithm to use SMO to train the
        //  underlying SVMs in each of the binary class subproblems.
        teacher.Algorithm = (svm, classInputs, classOutputs, i, j) =>
            new SequentialMinimalOptimization(svm, classInputs, classOutputs);

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

        error = teacher.Run(); // 0.1875 error rate
        var answer = machine.Compute(new double[] {2});  // gives -1,-1,-1,-1, instead of -1,-1,1,-1

如果错误率为零,为什么似乎只有
0
的输入才能提供正确的输出?

回答这个问题,很可能是该特定示例有问题。大多数示例都经过了更新,以反映去年推出的新的.Learn()API

现在您可能会看到,由于新的API,多标签支持向量机的文档页面也更改了地址,现在位于

现在,它包括以下示例:

// Let's say we have the following data to be classified
// into three possible classes. Those are the samples:
// 
double[][] inputs =
{
    //               input         output
    new double[] { 0, 1, 1, 0 }, //  0 
    new double[] { 0, 1, 0, 0 }, //  0
    new double[] { 0, 0, 1, 0 }, //  0
    new double[] { 0, 1, 1, 0 }, //  0
    new double[] { 0, 1, 0, 0 }, //  0
    new double[] { 1, 0, 0, 0 }, //  1
    new double[] { 1, 0, 0, 0 }, //  1
    new double[] { 1, 0, 0, 1 }, //  1
    new double[] { 0, 0, 0, 1 }, //  1
    new double[] { 0, 0, 0, 1 }, //  1
    new double[] { 1, 1, 1, 1 }, //  2
    new double[] { 1, 0, 1, 1 }, //  2
    new double[] { 1, 1, 0, 1 }, //  2
    new double[] { 0, 1, 1, 1 }, //  2
    new double[] { 1, 1, 1, 1 }, //  2
};

int[] outputs = // those are the class labels
{
    0, 0, 0, 0, 0,
    1, 1, 1, 1, 1,
    2, 2, 2, 2, 2,
};

// Create the multi-class learning algorithm for the machine
var teacher = new MulticlassSupportVectorLearning<Gaussian>()
{
    // Configure the learning algorithm to use SMO to train the
    //  underlying SVMs in each of the binary class subproblems.
    Learner = (param) => new SequentialMinimalOptimization<Gaussian>()
    {
        // Estimate a suitable guess for the Gaussian kernel's parameters.
        // This estimate can serve as a starting point for a grid search.
        UseKernelEstimation = true
    }
};

// Configure parallel execution options
teacher.ParallelOptions.MaxDegreeOfParallelism = 1;

// Learn a machine
var machine = teacher.Learn(inputs, outputs);

// Obtain class predictions for each sample
int[] predicted = machine.Decide(inputs);

// Get class scores for each sample
double[] scores = machine.Score(inputs);

// Compute classification error
double error = new ZeroOneLoss(outputs).Loss(predicted);
//假设我们有以下数据需要分类
//分为三类。这些是样品:
// 
双[]输入=
{
//输入输出
新的双精度[]{0,1,1,0},//0
新的双精度[]{0,1,0,0},//0
新的双精度[]{0,0,1,0},//0
新的双精度[]{0,1,1,0},//0
新的双精度[]{0,1,0,0},//0
新的双精度[]{1,0,0,0},//1
新的双精度[]{1,0,0,0},//1
新的双精度[]{1,0,0,1},//1
新的双精度[]{0,0,0,1},//1
新的双精度[]{0,0,0,1},//1
新的双[]{1,1,1,1},//2
新的双精度[]{1,0,1,1},//2
新的双精度[]{1,1,0,1},//2
新的双精度[]{0,1,1,1},//2
新的双[]{1,1,1,1},//2
};
int[]输出=//这些是类标签
{
0, 0, 0, 0, 0,
1, 1, 1, 1, 1,
2, 2, 2, 2, 2,
};
//为机器创建多类学习算法
var teacher=新的MulticlassSupportVectorLearning()
{
//配置学习算法以使用SMO来训练
//每个二进制类子问题中的基础支持向量机。
学习者=(参数)=>新的顺序最小优化()
{
//估计高斯核参数的合适猜测。
//此估计值可作为网格搜索的起点。
UseKernelEstimation=true
}
};
//配置并行执行选项
teacher.ParallelOptions.MaxDegreeOfParallelism=1;
//学习机器
var机器=教师学习(输入、输出);
//获取每个样本的类预测
int[]预测=机器决定(输入);
//获取每个样本的课堂分数
double[]分数=机器分数(输入);
//计算分类误差
双误差=新的零损耗(输出)。损耗(预测);

那么,为什么投票结果接近?是我的跟踪者有理由证明吗?那些不知道答案的人总是会投票支持close。你也会学到:)