Penelope v0.3.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.
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
compiles a pre-trained model
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.
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:
key | description | default |
---|---|---|
solver | see solver types below | :l2r_l2loss_svc |
c | error term penalty | 1.0 |
weights | class weights map, :auto for balanced | :auto |
epsilon | tolerance for stopping | 0.001 |
bias | intercept bias (-1 for no intercept) | 1.0 |
solver types
type | description |
---|---|
:l2r_lr | primal L2 regularized logistic regression |
:l2r_l2loss_svc_dual | dual L2 regularized L2 loss SVC |
:l2r_l2loss_svc | primal L2 regularized L2 loss SVC |
:l2r_l1loss_svc_dual | dual L2 regularized L1 loss SVC |
:mcsvm_cs | crammer/singer SVC |
:l1r_l2loss_svc | L1 regularized L2 loss SVC |
:l1r_lr | L1 regularized logistic regression |
:l2r_lr_dual | dual L2 regularized logistic regression |
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
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}
.