-
Notifications
You must be signed in to change notification settings - Fork 0
Quickstart Go
Lemkit for Go currently implements only reading previously saved linear classification models (the equivalent of Scala lemkit-model); see Quickstart Scala. There are command-line applications to do prediction, and this can also be done using library functions.
This library assumes you have already trained a model using Scala or Python. For the following, we assume you have a binary model saved in model.binary, but the code is very similar for JSON models. We also assume you have a file data.predict containing data instances to predict, using the format described in Input Format.
Example code is as follows. See also github.com/peoplepattern/lemkit/go/lkpredict/PredictApp, which implements
lkpredict.
package main
import (
"fmt"
"github.com/peoplepattern/lemkit/go/classify"
)
func main() {
classifier, err := classify.ReadBinaryModel("model.binary")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
predictData, err := classify.ReadDataFile("data.predict")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for i := 0; i < len(predictData); i++ {
prediction, _ := classifier.Predict(predictData[i].Features)
correct := predictData[i].Label
fmt.Printf("%d %s %s\n", i+1, correct, prediction)
}
}
Note that the second return value to classifier.Predict is a probability.
If you want the full set of scores for each possible label, use
classifier.Scores or classifier.ScoresMap. (These are methods of the
LinearClassifier struct.)
If you want to read a JSON model instead of a binary model, use
classify.ReadJSONModel.
lkpredict is used to do prediction on linear classifier models trained using Scala or Python. The following command does the equivalent of the library code above:
lkpredict -m vowpal -f binary -p data.predict
Full documentation is available in the User Guide.