CGC_Codes

predict

Jun 7th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using libsvm;
  4.  
  5. namespace QuantSys.MachineLearning.SupportVectorMachine
  6. {
  7.     public class Predict
  8.     {
  9.         public static string TRAINING_FILE = "C:/Sangar/quantopian/svm/heart_scale";
  10.         public static string TEST_FILE = "C:/Sangar/quantopian/svm/heart_scale";
  11.         public static double gamma = 1.0;
  12.         public static double C = 1.0;
  13.         public static int nr_fold = 5;
  14.  
  15.         private static readonly svm_problem prob = ProblemHelper.ReadAndScaleProblem(TRAINING_FILE);
  16.         private static readonly svm_problem test = ProblemHelper.ReadAndScaleProblem(TEST_FILE);
  17.  
  18.         public static void SVMPredict()
  19.         {
  20.             var svm = new C_SVC(prob, KernelHelper.RadialBasisFunctionKernel(gamma), C);
  21.             double accuracy = svm.GetCrossValidationAccuracy(nr_fold);
  22.  
  23.             for (int i = 0; i < test.l; i++)
  24.             {
  25.                 svm_node[] x = test.x[i];
  26.                 double y = test.y[i];
  27.                 double predict = svm.Predict(x);
  28.                 Dictionary<int, double> probabilities = svm.PredictProbabilities(x);
  29.                
  30.                 Console.WriteLine(predict + " :" + probabilities[1]);
  31.             }
  32.             Console.ReadKey();
  33.         }
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment