问题描述
我想在C#中做一个多类分类应用程序.我决定使用encog这样做.现在我只停留在一点.我发现了一个XOR示例,据我所知.但是,当我要使用自己的数据集时,应用仅使用一个示例中的一项功能进行计算.这是我的代码:
I would like to do a multiclass classification application in C#. I decided to use encog to do so. Now I am stuck at one point. I found a XOR example, which I understand. But when I am going to use my own dataset, app is computing only with one feature from one example. Here is my code:
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 looks like this (this is just a sample):
166 163 180228
166 163 180 228
165 162 160 226
165 162 160 226
166 163 180228
166 163 180 228
166164180228
166 164 180 228
期望的输出看起来像这样(这只是一个示例):
DESIRED OUTPUTS looks like this (this is just a sample):
1
2
1
1
测试示例如下:
152 151 98219
152 151 98 219
当我运行我的应用程序时,它正在计算错误,但是它仅显示来自我输入的第一列中的值(因此,我不确定它是否使用整个示例进行计算-4个值).我也不确定如何将我的TEST示例传递给SVM,而不是该对.
When I run my app, it is computing the Error, but it shows only values from first column of my INPUTS (so I am not sure if it is computing with whole examples - 4 values).I am also not sure how to pass my TEST example to the SVM instead of that pair.Input.
还是有比encog更有效的方法?谢谢.
Or is there a more efficient way to do this, than with encog?Thank you.
推荐答案
如果您正在执行xor运算符,则只需要一对数字...但是在示例输入中,您有四个,我不理解
If you are doing and xor operator, you only need a pair of numerals... but in your sample input, you have four, which I do not understand.
我不知道如何使用SupportVectorMachine,所以我使用它:
I do not know how to use SupportVectorMachine so I use this:
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();
我希望这会有所帮助.
这篇关于我自己的数据集的C#ENCOG SVM分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!