Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Accord.Net多类SVM DynamicTimeWarping异常_C#_.net_Machine Learning_Svm_Accord.net - Fatal编程技术网

C# Accord.Net多类SVM DynamicTimeWarping异常

C# Accord.Net多类SVM DynamicTimeWarping异常,c#,.net,machine-learning,svm,accord.net,C#,.net,Machine Learning,Svm,Accord.net,我想结合动态时间扭曲和支持向量机作为分类器使用。我使用Accord.net,但我的代码有问题,以下是我的代码: double[][] inputs = new double[100][]; for(int i = 0; i < linesX.Length; i++) { inputs[i] = Array.ConvertAll(linesX[i].Split(','), Double.Parse); }

我想结合动态时间扭曲和支持向量机作为分类器使用。我使用Accord.net,但我的代码有问题,以下是我的代码:

        double[][] inputs = new double[100][];
        for(int i = 0; i < linesX.Length; i++)
        {
            inputs[i] = Array.ConvertAll(linesX[i].Split(','), Double.Parse);
        }
        int[] outputs = Array.ConvertAll(linesY, s => int.Parse(s));     

        // Create the Sequential Minimal Optimization learning algorithm
        var smo = new MulticlassSupportVectorLearning<DynamicTimeWarping>()
        {
            // Set the parameters of the kernel
            Kernel = new DynamicTimeWarping(alpha: 1, degree: 1)
        };

        // And use it to learn a machine!
        var svm = smo.Learn(inputs, outputs);

        // Now we can compute predicted values
        int[] predicted = svm.Decide(inputs);

        // And check how far we are from the expected values
        double error = new ZeroOneLoss(outputs).Loss(predicted); 
double[][]输入=新的double[100][];
对于(int i=0;iint.Parse);
//创建序列最小优化学习算法
var smo=新的MulticlassSupportVectorLearning()
{
//设置内核的参数
内核=新的DynamicTimeWarping(alpha:1,度:1)
};
//用它来学习机器!
var svm=smo.学习(输入、输出);
//现在我们可以计算预测值了
int[]预测=支持向量机决定(输入);
//并检查我们离预期值有多远
双误差=新的零损耗(输出)。损耗(预测);

我的输入是(100800),输出是(100,1),此行将出现异常:
var svm=smo.Learn(输入,输出)异常是“System.AggregateException”发生在Accord.MachineLearning.dll中
我的代码有什么问题

请参考正确的设置。您没有分配
Learner
属性

以下是您的修改代码和一些随机输入数据:

    static void Main(string[] args)
    {
        Random r = new Random();

        double[][] inputs = new double[10][];
        int[] outputs = new int[10];

        for (int i = 0; i < 10; i++)
        {
            inputs[i] = new double[8];
            for (int j = 0; j < 8; j++)
            {
                inputs[i][j] = r.Next(1, 100);
            }
            outputs[i] = r.Next(1, 6);
        }

        var smo = new MulticlassSupportVectorLearning<DynamicTimeWarping>()
        {
            Learner = (param) => new SequentialMinimalOptimization<DynamicTimeWarping>()
            {
                Kernel = new DynamicTimeWarping(alpha: 1, degree: 1),
            }
        };

        var svm = smo.Learn(inputs, outputs);

        int[] predicted = svm.Decide(inputs);

        double error = new ZeroOneLoss(outputs).Loss(predicted);

        Console.WriteLine();
        Console.WriteLine("output = \n{0}", Matrix.ToString(outputs));
        Console.WriteLine();
        Console.WriteLine("predicted = \n{0}", Matrix.ToString(predicted));
        Console.WriteLine();
        Console.WriteLine("error = {0}", error);
        Console.ReadLine();
    }
output =
2 3 1 2 1 2 2 3 5 1

predicted =
2 1 1 2 1 2 2 2 2 1

error = 0.3