0

Currently I'm using FastTree for binary classification, but I would like to give SVM a try and compare metrics.

All the docs mention LinearSvm, but I can't find code example anywhere.

mlContext.BinaryClassification.Trainers does not have public SVM trainers. There is LinearSvm class and LinearSvm.TrainLinearSvm static method, but they seem to be intended for different things.

What am I missing?

Version: 0.7

Max Al Farakh
  • 4,386
  • 4
  • 29
  • 56

2 Answers2

0

For some reason there is no trainer in the runtime API but there is a linear SVM trainer in the Legacy API (for v0.7) found here. They might be generating a new one for the upcoming API, so my advice is to either use the legacy one, or wait for a newer API.

At this stage, ML.Net is very much in development.

c-chavez
  • 7,237
  • 5
  • 35
  • 49
0

Copy pasting the response I got on Github:

I have two answers for you: What the status of the API is, and how to use the LinearSVM in the meantime.

First, we have LinearSVM in the ML.NET codebase, but we do not yet have samples or the API extensions to place it in mlContext.BinaryClassification.Trainers. This is being worked through in issue #1318. I'll link this to that issue, and mark it as a bug.

In the meantime, you can use direct instantiation to get access to LinearSVM:

var arguments = new LinearSvm.Arguments()
{
    NumIterations = 20
};
var linearSvm = new LinearSvm(mlContext, arguments);
var svmTransformer = linearSvm.Fit(trainSet);
var scoredTest = svmTransformer.Transform(testSet);

This will give you an ITransformer, here called svmTransformer that you can use to operate on IDataView objects.

Max Al Farakh
  • 4,386
  • 4
  • 29
  • 56