Class LibLinearModel<T extends Output<T>>
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.provenance.Provenancable<ModelProvenance>
,Serializable
,ProtoSerializable<org.tribuo.protos.core.ModelProto>
- Direct Known Subclasses:
LibLinearAnomalyModel
,LibLinearClassificationModel
,LibLinearRegressionModel
Model
which wraps a LibLinear-java model.
It disables the LibLinear debug output as it's very chatty.
See:
Fan RE, Chang KW, Hsieh CJ, Wang XR, Lin CJ. "LIBLINEAR: A library for Large Linear Classification" Journal of Machine Learning Research, 2008.and for the original algorithm:
Cortes C, Vapnik V. "Support-Vector Networks" Machine Learning, 1995.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Protobuf serialization version.protected List<de.bwaldvogel.liblinear.Model>
The list of LibLinear models.Fields inherited from class org.tribuo.Model
ALL_OUTPUTS, BIAS_FEATURE, featureIDMap, generatesProbabilities, name, outputIDInfo, provenance, provenanceOutput
Fields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER
-
Constructor Summary
ModifierConstructorDescriptionprotected
LibLinearModel
(String name, ModelProvenance description, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> labelIDMap, boolean generatesProbabilities, List<de.bwaldvogel.liblinear.Model> models) Constructs a LibLinear model from the supplied arguments. -
Method Summary
Modifier and TypeMethodDescriptionprotected static de.bwaldvogel.liblinear.Model
copyModel
(de.bwaldvogel.liblinear.Model model) Copies the model by writing it out to a String and loading it back in.This call is expensive as it copies out the weight matrix from the LibLinear model.getExcuses
(Iterable<Example<T>> examples) Generates an excuse for each example.protected abstract double[][]
Extracts the feature weights from the models.List<de.bwaldvogel.liblinear.Model>
Returns an unmodifiable list containing a copy of each model.innerGetExcuse
(Example<T> e, double[][] featureWeights) The call to getFeatureWeights in the public methods copies the weights array so this inner method exists to save the copy in getExcuses.org.tribuo.protos.core.ModelProto
Serializes this object to a protobuf.Methods inherited from class org.tribuo.Model
castModel, copy, copy, createDataCarrier, deserialize, deserializeFromFile, deserializeFromStream, generatesProbabilities, getFeatureIDMap, getName, getOutputIDInfo, getProvenance, getTopFeatures, innerPredict, predict, predict, predict, serializeToFile, serializeToStream, setName, toString, validate
-
Field Details
-
CURRENT_VERSION
public static final int CURRENT_VERSIONProtobuf serialization version.- See Also:
-
models
The list of LibLinear models. Multiple models are used by multi-label and multidimensional regression outputs.Not final to support deserialization reordering of multidimensional regression models which have an incorrect id mapping. Will be final again in some future version which doesn't maintain serialization compatibility with 4.X.
-
-
Constructor Details
-
LibLinearModel
protected LibLinearModel(String name, ModelProvenance description, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> labelIDMap, boolean generatesProbabilities, List<de.bwaldvogel.liblinear.Model> models) Constructs a LibLinear model from the supplied arguments.- Parameters:
name
- The model name.description
- The model provenance.featureIDMap
- The features this model knows about.labelIDMap
- The outputs this model produces.generatesProbabilities
- Does this model generate probabilities?models
- The liblinear models themselves.
-
-
Method Details
-
getInnerModels
Returns an unmodifiable list containing a copy of each model.As liblinear-java models don't expose a copy constructor this requires serializing each model to a String and rebuilding it, and is thus quite expensive.
- Returns:
- A copy of all of the models.
-
getExcuse
This call is expensive as it copies out the weight matrix from the LibLinear model.Prefer
getExcuses(java.lang.Iterable<org.tribuo.Example<T>>)
to get multiple excuses. -
getExcuses
Description copied from class:Model
Generates an excuse for each example.This may be an expensive operation, and probably should be overridden in subclasses for performance reasons.
These excuses either contain per class information or an entry with key Model.ALL_OUTPUTS.
The optional is empty if the model does not provide excuses.
- Overrides:
getExcuses
in classModel<T extends Output<T>>
- Parameters:
examples
- An iterable of examples- Returns:
- A optional list of excuses. The Optional is empty if this model does not provide excuses.
-
copyModel
protected static de.bwaldvogel.liblinear.Model copyModel(de.bwaldvogel.liblinear.Model model) Copies the model by writing it out to a String and loading it back in.Unfortunately liblinear-java doesn't have a copy constructor on it's model.
- Parameters:
model
- The model to copy.- Returns:
- A deep copy of the model.
-
getFeatureWeights
protected abstract double[][] getFeatureWeights()Extracts the feature weights from the models. The first dimension corresponds to the model index.- Returns:
- The feature weights.
-
innerGetExcuse
The call to getFeatureWeights in the public methods copies the weights array so this inner method exists to save the copy in getExcuses.If it becomes a problem then we could cache the feature weights in the model.
- Parameters:
e
- The example.featureWeights
- The per dimension feature weights.- Returns:
- An excuse for this example.
-
serialize
public org.tribuo.protos.core.ModelProto serialize()Description copied from interface:ProtoSerializable
Serializes this object to a protobuf.
-