Handwritten Digits Recognition with C# SVMs in Accord.NET


I’ve posted a new article on CodeProject, entitled “Handwriting Recognition Revisited: Kernel Support Vector Machines”. It is a continuation of a previous article on handwritten digits recognition but this time using SVMs instead of KDA.


The code uses the SVM library in Accord.NET Framework. The framework, which runs on .NET and is written mostly in C#, supports standard or multiclass support vector machines for either classification or regression, having more than 20 kernel functions available to choose from.

In the article, the same set and the same amount of training and testing samples have been used as in the previous Kernel Discriminant Analysis article for comparison purposes. The experimental results shows that  SVMs can outperform KDA both in terms of efficiency and accuracy, requiring much less processing time and memory available while still producing robust results.


  1. how to make classification multiclass with svm where input more than one parameter. For the example my case like this :

    x1=0,1,2,3 …. -> for label 1
    x2=1,1,1,1 … -> for label 2
    x3=2,1,2,2 …. -> for label 3
    x4=3,2,1,1 …. -> for label 1
    and etc

  2. Hi Singgih,

    Here is an example on how to create such multi-class SVMs. If you would like to use multiple inputs, simply add more numbers to your input vectors. For example, in the page I linked it shows the following code:

    // Sample input data
    double[][] inputs =
    new double[] { 0 },
    new double[] { 3 },
    new double[] { 1 },
    new double[] { 2 },

    Instead, you can change it to be

    // Sample input data
    double[][] inputs =
    new double[] { 0, 2 },
    new double[] { 3, 3 },
    new double[] { 1, 2 },
    new double[] { 2, 2 },

    As you see, you can grow your input vectors as you would like. When you create your machine, don’t forget to specify the number of inputs you will be using as the first parameter of its constructor.

    Hope it helps!

    Best regards,

  3. Hi, I would like to make some tests with multiclass SVM (8 attributes and 5 classes), using same logic for decision trees as seen in example:


    I have done this:

    //same code to get input and output data
    string nurseryData = Resources.nursery;
    string[] inputColumns =
    “parents”, “has_nurs”, “form”, “children”,
    “housing”, “finance”, “social”, “health”
    string outputColumn = “output”;
    DataTable table = new DataTable(“Nursery”);
    string[] lines = nurseryData.Split(
    new[] { Environment.NewLine }, StringSplitOptions.None);
    foreach (var line in lines)
    Codification codebook = new Codification(table);
    DataTable symbols = codebook.Apply(table);
    double[][] inputs = symbols.ToArray(inputColumns);
    int[] outputs = symbols.ToArray(outputColumn);

    IKernel kernel = new Polynomial(2, 5);
    // Create the Multi-class Support Vector Machine using the selected Kernel
    var ksvm = new MulticlassSupportVectorMachine(inputDimension, kernel, outputClasses);
    // Create the learning algorithm using the machine and the training data
    var ml = new MulticlassSupportVectorLearning(ksvm, inputs, outputs);
    ml.Algorithm = (svm, classInputs, classOutputs, i, j) =>
    new SequentialMinimalOptimization(svm, classInputs, classOutputs);
    double SVMerror = ml.Run();

    However I get an error while training the machine, What am I missing?

Leave a Reply

Your email address will not be published. Required fields are marked *