2017-05-11 3 views
1

Ich möchte dynamische Zeitverzerren und Svm kombinieren, um als Klassifikator zu verwenden. Ich benutze Accord .net, aber es ist etwas falsch mit meinem Code, hier ist mein Code:Accord.Net Multiclass SVM DynamicTimeWarping Ausnahme

 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); 

Meine Eingänge (100.800), Ausgänge (100,1), wird es in dieser Zeile eine Ausnahme sein : var svm = smo.Learn(inputs, outputs); Die Ausnahme ist “System.AggregateException” happens in Accord.MachineLearning.dll Was ist falsch mit meinem Code

Antwort

1

Bitte beachten Sie die richtige Einrichtung HERE. Sie weisen die Eigenschaft Learner nicht zu.

Hier ist Ihr modifizierten Code mit einigen zufälligen Eingangsdaten:

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(); 
    } 

die so etwas wie diese produzieren:

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