Penelope v0.4.0 Penelope.ML.Linear.Classifier

The linear classifier uses liblinear for multi-class classification. It provides support for training a model, compiling/extracting model parameters to/from erlang data structures, and predicting classes or probabilities.

Features are represented as lists of dense Vector instances. Classes can be any value, and class labels for training are lists of these.

The basic functionality of liblinear is extended to include predicting calibrated probabilites for SVM models, using Platt scaling. Binary Platt scaling is extended to OVR multiclass using simple normalization. This feature can be enabled by setting the :probability? option.

Model parameters are elixir analogs of those supported by liblinear. See https://github.com/cjlin1/liblinear for details.

Link to this section Summary

Functions

compiles a pre-trained model

extracts model parameters from the compiled model

trains a linear model and returns it as a compiled model

predicts a list of target classes from a list of feature vectors

predicts probabilities for all classes from a list of feature vectors

Link to this section Functions

Link to this function compile(params)
compile(params :: map()) :: map()

compiles a pre-trained model

Link to this function export(map)
export(%{lin: reference(), classes: [any()]}) :: map()

extracts model parameters from the compiled model

These parameters are simple elixir objects and can later be passed to compile to prepare the model for inference.

Link to this function fit(context, x, y, options \\ [])
fit(context :: map(), x :: [Penelope.ML.Vector.t()], y :: [any()], options :: keyword()) :: map()

trains a linear model and returns it as a compiled model

options:

keydescriptiondefault
solversee solver types below:l2r_l2loss_svc
cerror term penalty1.0
weightsclass weights map, :auto for balanced:auto
epsilontolerance for stopping0.001
biasintercept bias (-1 for no intercept)1.0
probability?enable class probabilities for svm?false

solver types

typedescription
:l2r_lrprimal L2 regularized logistic regression
:l2r_l2loss_svc_dualdual L2 regularized L2 loss SVC
:l2r_l2loss_svcprimal L2 regularized L2 loss SVC
:l2r_l1loss_svc_dualdual L2 regularized L1 loss SVC
:mcsvm_cscrammer/singer SVC
:l1r_l2loss_svcL1 regularized L2 loss SVC
:l1r_lrL1 regularized logistic regression
:l2r_lr_dualdual L2 regularized logistic regression
Link to this function predict_class(model, context, x)
predict_class(%{lin: reference(), classes: [any()]}, context :: map(), [x :: Penelope.ML.Vector.t()]) :: [any()]

predicts a list of target classes from a list of feature vectors

Link to this function predict_probability(model, context, x)
predict_probability(%{lin: reference(), classes: [any()]}, context :: map(), [x :: Penelope.ML.Vector.t()]) :: [%{optional(any()) => float()}]

predicts probabilities for all classes from a list of feature vectors

The results are returned in a map of %{label => probability}.