Skip to content

Instantly share code, notes, and snippets.

@kvorion
Created May 9, 2011 18:19
Show Gist options
  • Save kvorion/963041 to your computer and use it in GitHub Desktop.
Save kvorion/963041 to your computer and use it in GitHub Desktop.
Console application that uses the NetSVMLight library
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NetSVMLight;
namespace NetSVMLightConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//ENTER FULL PATH OF EXECUTABLES.
//configure learner by setting parameters
SVMLearn learner = new SVMLearn();
learner.mode = Mode.Classification;
learner.kernelType = Kernel.Polynomial;
learner.ParamC = 2;
learner.ParamD = 2;
learner.LeaveOneOutCrossValidation = true;
learner.TrainingErrorAndMarginTradeoff = 10;
//construct training and test sets from dataset
Utilities.ConstructTrainingAndTestSets(@"all.data", "training.data", "test.data", 0.7, false);
//build model
learner.ExecuteLearner("svm_learn.exe", "training.data", "trained.model", "traininglog.txt", false);
//classify test set
SVMClassify classifier = new SVMClassify();
classifier.ExecuteClassifier("svm_classify.exe", "test.data", "trained.model", "output.txt", "testlog.txt",
false);
//find instances that were incorrect classified
classifier.FindIncorrectlyClassifiedInstances("test.data", "output.txt",
"incorrectlyClassified.txt");
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment