Package org.tribuo.clustering.kmeans
Class KMeansModel
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.provenance.Provenancable<ModelProvenance>,Serializable,ProtoSerializable<org.tribuo.protos.core.ModelProto>
A K-Means model with a selectable distance function.
The predict method of this model assigns centres to the provided input, but it does not update the model's centroids.
The predict method is single threaded.
See:
J. Friedman, T. Hastie, & R. Tibshirani. "The Elements of Statistical Learning" Springer 2001. PDF
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intProtobuf serialization version.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 -
Method Summary
Modifier and TypeMethodDescriptionprotected KMeansModelcopy(String newName, ModelProvenance newProvenance) static KMeansModeldeserializeFromProto(int version, String className, com.google.protobuf.Any message) Deserialization factory.Returns a list of features, one per centroid.Returns a copy of the centroids.getTopFeatures(int n) org.tribuo.protos.core.ModelProtoMethods inherited from class org.tribuo.Model
castModel, copy, createDataCarrier, deserialize, deserializeFromFile, deserializeFromStream, generatesProbabilities, getExcuses, getFeatureIDMap, getName, getOutputIDInfo, getProvenance, innerPredict, predict, predict, serializeToFile, serializeToStream, setName, toString, validate
-
Field Details
-
CURRENT_VERSION
Protobuf serialization version.- See Also:
-
-
Method Details
-
deserializeFromProto
public static KMeansModel deserializeFromProto(int version, String className, com.google.protobuf.Any message) throws com.google.protobuf.InvalidProtocolBufferException Deserialization factory.- Parameters:
version- The serialized object version.className- The class name.message- The serialized data.- Returns:
- The deserialized object.
- Throws:
com.google.protobuf.InvalidProtocolBufferException- If the protobuf could not be parsed from themessage.
-
getCentroidVectors
Returns a copy of the centroids.In most cases you should prefer
getCentroids()as it performs the mapping from Tribuo's internal feature ids to the externally visible feature names for you. This method provides direct access to the centroid vectors for use in downstream processing if the ids are not relevant (or are known to match).- Returns:
- The centroids.
-
getCentroids
Returns a list of features, one per centroid.This should be used in preference to
getCentroidVectors()as it performs the mapping from Tribuo's internal feature ids to the externally visible feature names.- Returns:
- A list containing all the centroids.
-
predict
-
getTopFeatures
- Specified by:
getTopFeaturesin classModel<ClusterID>
-
getExcuse
-
serialize
- Specified by:
serializein interfaceProtoSerializable<org.tribuo.protos.core.ModelProto>- Overrides:
serializein classModel<ClusterID>
-
copy
-