【问题标题】:C# ENCOG SVM classification with my own datasetC# ENCOG SVM 分类与我自己的数据集
【发布时间】:2014-03-17 20:20:52
【问题描述】:

我想在 C# 中做一个多类分类应用程序。我决定使用 encog 来做到这一点。现在我被困在某一点上。我找到了一个我理解的 XOR 示例。但是当我要使用自己的数据集时,应用程序仅使用一个示例中的一个特征进行计算。 这是我的代码:

 namespace ConsoleApplication1
 {

   public static class Load
   {
       public static double[][] FromFile(string path)
       {
        var rows = new List<double[]>();
        foreach (var line in File.ReadAllLines(path))
        {
            rows.Add(line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(double.Parse).ToArray());
        }
        return rows.ToArray();
    }
}

 public class Program
 {

 static void Main( string [ ] args )
 {

 // LOADING MY OWN DATASET
 string cestain = @"E:\vstup.txt";
 double[][] innput = Load.FromFile(cestain);   //Training INPUTS

 string cestaout = @"E:\vystup.txt";
 double[][] ooutput = Load.FromFile(cestaout); //Desired OUTPUTS

 string cestatest = @"E:\te1.txt";
 double[][] teest = Load.FromFile(cestatest);   // Test Example


    // create a neural network 
    var svm = new SupportVectorMachine(10, false); // 2 input, & false for classification


    // create training data
    IMLDataSet trainingSet = new BasicMLDataSet(innput, ooutput);

    // train the neural network
    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 neural network

    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");
    Console.ReadKey();
 }
 }
 } 

INPUTS 看起来像这样(这只是一个示例):

166 163 180 228

165 162 160 226

166 163 180 228

166 164 180 228

DESIRED OUTPUTS 如下所示(这只是一个示例):

1

2

1

1

测试示例如下所示:

152 151 98 219

当我运行我的应用程序时,它正在计算错误,但它只显示我输入的第一列中的值(所以我不确定它是否正在计算整个示例 - 4 个值)。 我也不确定如何将我的 TEST 示例传递给 SVM 而不是该 pair.Input。

或者有比 encog 更有效的方法吗? 谢谢。

【问题讨论】:

    标签: c# classification svm libsvm encog


    【解决方案1】:

    如果你在做和 xor 运算符,你只需要一对数字......但在你的示例输入中,你有四个,我不明白。

    我不知道如何使用 SupportVectorMachine 所以我用这个:

    BasicNetwork network = new BasicNetwork(); 
    network.AddLayer(new BasicLayer(2)); //input layer
    network.AddLayer(new BasicLayer(2)); //hidden layer
    network.AddLayer(new BasicLayer(1)); //ouput layer
    network.Structure.FinalizeStructure(); 
    network.Reset();
    

    我希望这会有所帮助。

    【讨论】:

    • 我用那个异或作为模板来弄清楚它是如何工作的。这四个数字是参数(如高度、宽度……)。所以我不想使用对。可以说,我将使用 BasicNetwork。如果我在输入层使用 4 个神经元,这是否意味着它将处理整个训练示例(这 4 个值)?当您想对新的未知示例进行分类时,您如何使用您的网络?谢谢
    猜你喜欢
    • 2013-05-20
    • 1970-01-01
    • 2014-08-15
    • 2014-06-03
    • 2014-02-10
    • 2015-07-04
    • 2018-05-28
    • 2021-08-10
    • 1970-01-01
    相关资源
    最近更新 更多