Class LibSVMModel<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:
LibSVMAnomalyModel
,LibSVMClassificationModel
,LibSVMRegressionModel
See:
Chang CC, Lin CJ. "LIBSVM: a library for Support Vector Machines" ACM transactions on intelligent systems and technology (TIST), 2011.for the nu-svm algorithm:
Schölkopf B, Smola A, Williamson R, Bartlett P L. "New support vector algorithms" Neural Computation, 2000, 1207-1245.and for the original algorithm:
Cortes C, Vapnik V. "Support-Vector Networks" Machine Learning, 1995.
- See Also:
-
Field Summary
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
LibSVMModel
(String name, ModelProvenance description, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, boolean generatesProbabilities, List<libsvm.svm_model> models) Constructs a LibSVMModel from the supplied arguments. -
Method Summary
Modifier and TypeMethodDescriptionprotected static libsvm.svm_model
copyModel
(libsvm.svm_model model) Copies an svm_model, as it does not provide a copy method.protected static libsvm.svm_model
deserializeModel
(org.tribuo.common.libsvm.protos.SVMModelProto proto) Deserializes a LibSVM svm_model from a protobuf.protected static libsvm.svm_parameter
deserializeParameters
(org.tribuo.common.libsvm.protos.SVMParameterProto proto) Deserializes svm_parameter from a protobuf.Generates an excuse for an example.List<libsvm.svm_model>
Returns an unmodifiable copy of the underlying list of libsvm models.List<libsvm.svm_model>
getModel()
Deprecated.Deprecated to unify the names across LibLinear, LibSVM and XGBoost.getTopFeatures
(int n) Gets the topn
features associated with this model.static boolean
modelEquals
(libsvm.svm_model first, libsvm.svm_model second) Checks for equality between two svm_models.protected static org.tribuo.common.libsvm.protos.SVMModelProto
serializeModel
(libsvm.svm_model model) Serializes a LibSVM svm_model to a protobuf.protected static org.tribuo.common.libsvm.protos.SVMParameterProto
serializeParameters
(libsvm.svm_parameter param) Serializes a svm_parameter to a protobuf.Methods inherited from class org.tribuo.Model
castModel, copy, copy, createDataCarrier, deserialize, deserializeFromFile, deserializeFromStream, generatesProbabilities, getExcuses, getFeatureIDMap, getName, getOutputIDInfo, getProvenance, innerPredict, predict, predict, predict, serialize, serializeToFile, serializeToStream, setName, toString, validate
-
Field Details
-
models
The LibSVM models. Multiple models are used for multi-label or 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
-
LibSVMModel
protected LibSVMModel(String name, ModelProvenance description, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, boolean generatesProbabilities, List<libsvm.svm_model> models) Constructs a LibSVMModel from the supplied arguments.- Parameters:
name
- The model name.description
- The model provenance.featureIDMap
- The features the model knows about.outputIDInfo
- The outputs the model can produce.generatesProbabilities
- Does the model generate probabilities or not?models
- The svm models themselves.
-
-
Method Details
-
getModel
Deprecated.Deprecated to unify the names across LibLinear, LibSVM and XGBoost.Returns an unmodifiable copy of the underlying list of libsvm models.- Returns:
- The underlying model list.
-
getInnerModels
Returns an unmodifiable copy of the underlying list of libsvm models.- Returns:
- The underlying model list.
-
getTopFeatures
Description copied from class:Model
Gets the topn
features associated with this model.If the model does not produce per output feature lists, it returns a map with a single element with key Model.ALL_OUTPUTS.
If the model cannot describe it's top features then it returns
Collections.emptyMap()
.- Specified by:
getTopFeatures
in classModel<T extends Output<T>>
- Parameters:
n
- the number of features to return. If this value is less than 0, all features should be returned for each class, unless the model cannot score it's features.- Returns:
- a map from string outputs to an ordered list of pairs of feature names and weights associated with that feature in the model
-
getExcuse
Description copied from class:Model
Generates an excuse for an example.This attempts to explain a classification result. Generating an excuse may be quite an expensive operation.
This excuse either contains per class information or an entry with key Model.ALL_OUTPUTS.
The optional is empty if the model does not provide excuses.
-
copyModel
protected static libsvm.svm_model copyModel(libsvm.svm_model model) Copies an svm_model, as it does not provide a copy method.- Parameters:
model
- The svm_model to copy.- Returns:
- A deep copy of the model.
-
modelEquals
public static boolean modelEquals(libsvm.svm_model first, libsvm.svm_model second) Checks for equality between two svm_models.Equality is defined as bit-wise exact for SV, rho, sv_coeff, probA and probB.
- Parameters:
first
- The first model.second
- The second model.- Returns:
- True if the models are identical.
-
serializeParameters
protected static org.tribuo.common.libsvm.protos.SVMParameterProto serializeParameters(libsvm.svm_parameter param) Serializes a svm_parameter to a protobuf.- Parameters:
param
- The parameters to serialize.- Returns:
- The protobuf.
-
serializeModel
protected static org.tribuo.common.libsvm.protos.SVMModelProto serializeModel(libsvm.svm_model model) Serializes a LibSVM svm_model to a protobuf.- Parameters:
model
- The model to serialize.- Returns:
- The protobuf representation.
-
deserializeParameters
protected static libsvm.svm_parameter deserializeParameters(org.tribuo.common.libsvm.protos.SVMParameterProto proto) Deserializes svm_parameter from a protobuf.- Parameters:
proto
- The protobuf to deserialize.- Returns:
- The parameters.
-
deserializeModel
protected static libsvm.svm_model deserializeModel(org.tribuo.common.libsvm.protos.SVMModelProto proto) Deserializes a LibSVM svm_model from a protobuf.- Parameters:
proto
- The protobuf to deserialize.- Returns:
- The svm_model.
-