Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
Created September 24, 2013 10:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hodzanassredin/6682771 to your computer and use it in GitHub Desktop.
Save hodzanassredin/6682771 to your computer and use it in GitHub Desktop.
liblinear fsharp usage more info in original java port https://github.com/bwaldvogel/liblinear-java
// Learn more about F# at http://fsharp.net
// See the 'F# Tutorial' project for more help.
open de.bwaldvogel.liblinear
open java.io
open System
[<EntryPoint>]
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")
model.save(modelFile);
// 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