Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
liblinear fsharp usage more info in original java port
// Learn more about F# at
// See the 'F# Tutorial' project for more help.
open de.bwaldvogel.liblinear
open System
let main argv =
let problem = new Problem()
problem.l <- 2 // number of training examples
problem.n <- 2 // number of features
problem.x <- [|
[|new FeatureNode(1,0.); new FeatureNode(2,1.)|]
[|new FeatureNode(1,2.); new FeatureNode(2,0.)|]
|]// feature nodes
problem.y <- [|1.;2.|] // target values
let solver = SolverType.MCSVM_CS; // -s 0
let C = 1.0 // cost of constraints violation
let eps = 0.01 // stopping criteria
let parameter = new Parameter(solver, C, eps)
let model = Linear.train(problem, parameter)
let modelFile = new File("model");
// load model or use it directly
let model = Model.load(modelFile)
let instance:Feature []= [| new FeatureNode(1, 0.); new FeatureNode(2, 1.) |]
let prediction = Linear.predict(model, instance)
printfn "%A" prediction
Console.ReadKey() |> ignore
0 // return an integer exit code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.