c# – Encog中的多类SVM分类

有人可以告诉我如何在Encog 3.1中使用多类SVM分类

我已经使用他们的神经网络取得了一些成功,但无法弄清楚如何设置多类SVM.

文档有这样的说法:

“这是一个一个或多个支持向量机(SVM)支持的网络.它的设计功能与Encog神经网络非常相似,并且在很大程度上可与Encog神经网络互换.分类用于你希望SVM将输入数据分组到一个或多个类中.支持向量机通常只有一个输出.神经网络可以有多个输出神经元.为了解决这个问题,如果有多个SVM,这个类将创建多个SVM输出指定“

但是我看不出如何指定多个输出,实际上输出属性只返回1:

/// <value>For a SVM,the output count is always one.</value>
    public int OutputCount
    {
        get { return 1; }
    }

Java或c#中的答案非常感谢

编辑仍然无法解决这个问题.真的很享受使用Encog,但支持论坛只有Jeff Heaton(项目的作者)在他有机会时自己回答,所以即时联系项目代码添加赏金,希望有人能看到我明显缺少的东西.

该项目:
http://heatonresearch.com/

Google代码上的SupportVectorMachine类:
https://code.google.com/p/encog-cs/source/browse/trunk/encog-core/encog-core-cs/ML/SVM/SupportVectorMachine.cs

解决方法

对不起,响应缓慢.我决定把它作为Encog的常见问题解答.你可以看到FAQ&这里的例子. http://www.heatonresearch.com/faq/5/2

基本上Encog DOES支持多类SVM.您不需要像神经网络那样需要多个输出.您只需使用单个输出训练它,并且输出是类号,即0.0,1.0,2.0等等,具体取决于您拥有的类数.

这适用于Encog的Java和C#版本.我在C#中做了这个例子.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Encog.ML.SVM;
using Encog.ML.Data;
using Encog.ML.Data.Basic;
using Encog.ML.Train;
using Encog.ML.SVM.Training;

namespace MultiClassSVM
{
    class Program
    {
        /// 
        /// Input for function,normalized to 0 to 1.
        /// 
        public static double[][] ClassificationInput = {
            new[] {0.0,0.0},new[] {0.1,new[] {0.2,new[] {0.3,new[] {0.4,0.5},new[] {0.5,new[] {0.6,new[] {0.7,new[] {0.8,new[] {0.9,0.5}
            };

        /// 
        /// Ideal output,these are class numbers,a total of four classes here (0,1,2,3).
        /// DO NOT USE FRACTIONAL CLASSES (i.e. there is no class 1.5)
        /// 
        public static double[][] ClassificationIdeal = {
            new[] {0.0},new[] {0.0},new[] {1.0},new[] {2.0},new[] {3.0},new[] {3.0}
        };

        static void Main(string[] args)
        {
            // create a neural network,without using a factory
            var svm = new SupportVectorMachine(2,false); // 2 input,& false for classification

            // create training data
            IMLDataSet trainingSet = new BasicMLDataSet(ClassificationInput,ClassificationIdeal);

            // train the SVM
            IMLTrain train = new SVMSearchTrain(svm,trainingSet);

            int epoch = 1;

            do
            {
                train.Iteration();
                Console.WriteLine(@"Epoch #" + epoch + @" Error:" + train.Error);
                epoch++;
            } while (train.Error > 0.01);

            // test the SVM
            Console.WriteLine(@"SVM Results:");
            foreach (IMLDataPair pair in trainingSet)
            {
                IMLData output = svm.Compute(pair.Input);
                Console.WriteLine(pair.Input[0]
                                  + @",actual=" + output[0] + @",ideal=" + pair.Ideal[0]);
            }

            Console.WriteLine("Done");
        }
    }
}

相关文章

原文地址:http://msdn.microsoft.com/en-us/magazine/cc163...
前言 随着近些年微服务的流行,有越来越多的开发者和团队所采...
最近因为比较忙,好久没有写博客了,这篇主要给大家分享一下...
在多核CPU在今天和不久的将来,计算机将拥有更多的内核,Mic...
c语言输入成绩怎么判断等级
字符型数据在内存中的存储形式是什么