public abstract class LibLinearModel<T extends Output<T>> extends Model<T>
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.
Modifier and Type | Field and Description |
---|---|
protected List<de.bwaldvogel.liblinear.Model> |
models
The list of LibLinear models.
|
ALL_OUTPUTS, BIAS_FEATURE, featureIDMap, generatesProbabilities, name, outputIDInfo, provenance, provenanceOutput
Modifier | Constructor and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
Optional<Excuse<T>> |
getExcuse(Example<T> e)
This call is expensive as it copies out the weight matrix from the
LibLinear model.
|
Optional<List<Excuse<T>>> |
getExcuses(Iterable<Example<T>> examples)
Generates an excuse for each example.
|
protected abstract double[][] |
getFeatureWeights()
Extracts the feature weights from the models.
|
List<de.bwaldvogel.liblinear.Model> |
getInnerModels()
Returns an unmodifiable list containing a copy of each model.
|
protected abstract Excuse<T> |
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.
|
copy, copy, generatesProbabilities, getFeatureIDMap, getName, getOutputIDInfo, getProvenance, getTopFeatures, innerPredict, predict, predict, predict, setName, toString, validate
protected final List<de.bwaldvogel.liblinear.Model> models
protected LibLinearModel(String name, ModelProvenance description, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> labelIDMap, boolean generatesProbabilities, List<de.bwaldvogel.liblinear.Model> models)
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.public List<de.bwaldvogel.liblinear.Model> getInnerModels()
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.
public Optional<Excuse<T>> getExcuse(Example<T> e)
Prefer getExcuses(java.lang.Iterable<org.tribuo.Example<T>>)
to get multiple excuses.
public Optional<List<Excuse<T>>> getExcuses(Iterable<Example<T>> examples)
Model
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.
getExcuses
in class Model<T extends Output<T>>
examples
- An iterable of examplesprotected static de.bwaldvogel.liblinear.Model copyModel(de.bwaldvogel.liblinear.Model model)
Unfortunately liblinear-java doesn't have a copy constructor on it's model.
model
- The model to copy.protected abstract double[][] getFeatureWeights()
protected abstract Excuse<T> innerGetExcuse(Example<T> e, double[][] featureWeights)
If it becomes a problem then we could cache the feature weights in the model.
e
- The example.featureWeights
- The per dimension feature weights.Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.