Машины опорных векторов Accord и Multi-label

Я работаю над примером в документации для многоклассовой машины опорных векторов — http://accord-framework.net/docs/html/T_Accord_MachineLearning_VectorMachines_MultilabelSupportVectorMachine.htm

Тем не менее, я не получаю 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 дает правильный результат?


person user3791372    schedule 19.03.2016    source источник
comment
Итак, почему закрытое голосование? Это мой сталкер, которому есть что доказывать?   -  person user3791372    schedule 20.03.2016
comment
люди, которые ничего не знают и не знают ответа, всегда будут голосовать за близких. ты тоже научишься :)   -  person MonsterMMORPG    schedule 05.04.2016


Ответы (1)


Чтобы ответить на вопрос, очень вероятно, что с этим конкретным примером что-то не так. Большинство примеров были обновлены, чтобы отразить новый API .Learn(), введенный в действие в прошлом году.

Теперь вы можете видеть, что страница документации для Multi-label Support Vector Machine также изменила адреса из-за нового 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);
person Cesar    schedule 08.07.2017