【问题标题】:multiple classification using Liblinear in Accord.net Framework在 Accord.net 框架中使用 Liblinear 进行多重分类
【发布时间】:2015-06-19 14:03:44
【问题描述】:

我需要使用 Liblinear 实现多分类分类器。 Accord.net 机器学习框架提供了除 Crammer 和 Singer 的多类分类公式之外的所有 Liblinear 属性。 This is the process.

【问题讨论】:

    标签: c# machine-learning classification liblinear accord.net


    【解决方案1】:

    学习多类机器的常用方法是使用MulticlassSupportVectorLearning class。该课程可以教授一对一的机器,然后可以使用投票或淘汰策略进行查询。

    因此,这里有一个关于如何对多个类进行线性训练的示例:

    // 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 a one-vs-one multi-class SVM learning algorithm 
    var teacher = new MulticlassSupportVectorLearning<Linear>()
    {
        // using LIBLINEAR's L2-loss SVC dual for each SVM
        Learner = (p) => new LinearDualCoordinateDescent()
        {
            Loss = Loss.L2
        }
    };
    
    // Learn a machine
    var machine = teacher.Learn(inputs, outputs);
    
    // Obtain class predictions for each sample
    int[] predicted = machine.Decide(inputs);
    
    // Compute classification accuracy
    double acc = new GeneralConfusionMatrix(expected: outputs, predicted: predicted).Accuracy;
    

    您还可以尝试使用一对一策略解决多类决策问题。在这种情况下,您可以使用MultilabelSupportVectorLearning 教学算法,而不是上面显示的多类算法。

    【讨论】:

    • 非常感谢。我对其进行了测试,并且效果很好。抱歉,我还有一个对我来说非常重要的问题。如何以并行方式实现它?
    • 嗯...学习阶段已经并行完成。多类问题被分解为一系列二元决策问题,每个二元决策都在一个单独的线程中解决。如果您没有发生这种情况,请告诉我,我会进行调查!
    猜你喜欢
    • 2016-09-29
    • 2017-11-08
    • 1970-01-01
    • 2014-08-29
    • 1970-01-01
    • 2023-03-29
    • 2016-04-15
    • 2013-08-28
    • 2014-09-01
    相关资源
    最近更新 更多