根据distrebution Accord.net对数字数组进行分类

时间:2016-06-04 14:34:06

标签: c# accord.net

我在c#中使用Accord.net,这个库中有很多分类器算法,我想知道对我的情况最好的是什么, 我试图用监督学习根据他们的分配来学习双重类型的数组,例如:

学习集:

a1 = new int[]{1,2,3,4} label a
a2 = new int[]{1,2,5,6} label a
a3= new int[]{1,1,0,0} label b
a4=new int[]{1,0,0,0} label b
a5 =new int[]{-10,0,-10,0} label c
a6=new int[]{-20,1,-20,1} label c

在学习训练集之后,分类器将需要识别不在学习集中的数组: 例如:

classify(new int[]{1,1,1,0}) ---> returns label b

1 个答案:

答案 0 :(得分:0)

您的阵列是否具有固定大小?例如,它们是否总是包含4个条目,例如您的示例?

如果是这样,请使用Accord.NET中的MulticlassSupportVectorMachine。 documentation page for MulticlassSupportVectorMachine现在有一个简单的示例如何对大小为3的数组进行分类,但您可以根据需要进行更改:

// Sample input data
double[][] inputs =
{
    new double[] { -1, 3, 2 },
    new double[] { -1, 3, 2 },
    new double[] { -1, 3, 2 },
    new double[] { 10, 82, 4 },
    new double[] { 10, 15, 4 },
    new double[] { 0, 0, 1 },
    new double[] { 0, 0, 2 },
};

// Output for each of the inputs
int[] outputs = { 0, 3, 1, 2 };


// Create a new polynomial kernel
IKernel kernel = new Polynomial(2);

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

// Create the Multi-class learning algorithm for the machine
var teacher = new MulticlassSupportVectorLearning(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(); // output should be 0

// Compute the decision output for one of the input vectors
int decision = machine.Compute( new double[] { -1, 3, 2 });