1:先用一下 Accord.MachineLearning(在NuGet下载即可) 2:引用 using Accord.MachineLearning.VectorMachines.Learning; 3:实例SVM多分类 Code:
double[][] inputs =
{ new double[] { 0 }, new double[] { 3 }, new double[] { 1 }, new double[] { 2 }, };
double[][] inputsTest =
{ new double[] { 4 }, }; // Outputs for each of the inputs int[] outputs = { 0, 3, 1, 2, };
// Create the Multi-label learning algorithm for the machine
var teacher = new MulticlassSupportVectorLearning<Linear>() { Learner = (p) => new SequentialMinimalOptimization<Linear>() { Complexity = 10000.0 // Create a hard SVM } };
// Learn a multi-label SVM using the teacher
var svm = teacher.Learn(inputs, outputs);
// Compute the machine answers for the inputs
int[] answers = svm.Decide(inputsTest);
Console.WriteLine(answers[0]);
Console.ReadKey(); github网址: https://github.com/accord-net/framework/wiki/Classification |
|