Class LibLinearModel<T extends Output<T>>
java.lang.Object
org.tribuo.Model<T>
org.tribuo.common.liblinear.LibLinearModel<T>
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.provenance.Provenancable<ModelProvenance>,Serializable,ProtoSerializable<org.tribuo.protos.core.ModelProto>
A
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
FieldsModifier and TypeFieldDescriptionstatic final intProtobuf 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, provenanceOutputFields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLibLinearModel(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.ModelcopyModel(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) 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.ModelProtoMethods 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
-
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
-
copyModel
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
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
-