首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Accord.net框架中使用Lib线性的多重分类

Accord.net框架中使用Lib线性的多重分类
EN

Stack Overflow用户
提问于 2015-04-14 04:36:18
回答 1查看 1.7K关注 0票数 3

我需要用Lib线性来实现多分类分类器。Accord.net机器学习框架除了Crammer和Singer的多类分类公式外,还提供了所有的Lib线性性质。这就是这个过程

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-14 21:48:37

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

因此,下面是一个如何对多个类进行线性培训的例子:

代码语言:javascript
复制
// 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;

您还可以尝试使用one-vs-rest策略来解决多类决策问题。在这种情况下,您可以使用MultilabelSupportVectorLearning教学算法代替上面所示的多类教学算法。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29619258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档