Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use LinearSvm? #1673

Closed
maxt3r opened this issue Nov 19, 2018 · 3 comments
Closed

How to use LinearSvm? #1673

maxt3r opened this issue Nov 19, 2018 · 3 comments
Labels
API Issues pertaining the friendly API bug Something isn't working

Comments

@maxt3r
Copy link

maxt3r commented Nov 19, 2018

Sorry if this is not the place for questions.

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

@rogancarr
Copy link
Contributor

Hi @maxt3r,

This is a great place for a question -- thanks for reaching out!

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.

One note about our LinearSVM implementation: This is an implementation PEGASOS, which is an online implementation of SVM. See this paper for more information.


Instance of Issue #1318

@rogancarr rogancarr added bug Something isn't working API Issues pertaining the friendly API labels Nov 19, 2018
@maxt3r
Copy link
Author

maxt3r commented Nov 19, 2018

Thanks a lot for quick response. Feel free to close the issue.

@rogancarr
Copy link
Contributor

Hi @maxt3r,

I'll close the issue, but one more comment: If you want a good linear baseline to judge other solutions from, I'd suggest using SDCA rather than LinearSVM. You can reference it like mlContext.BinaryClassification.Trainers.StochasticDualCoordinateAscent. In general**, it's the fastest and best "out-of-the-box" linear solver we have.

** Of course, the specific performances will depend on the dataset, but this is the "best bet" solution.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API Issues pertaining the friendly API bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants