Class KNNModel<T extends Output<T>>
java.lang.Object
org.tribuo.Model<T>
org.tribuo.common.nearest.KNNModel<T>
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.provenance.Provenancable<ModelProvenance>,Serializable,ProtoSerializable<org.tribuo.protos.core.ModelProto>
A k-nearest neighbours model.
Note multi-threaded prediction uses a ForkJoinPool which requires that the Tribuo codebase
is given the "modifyThread" and "modifyThreadGroup" privileges when running under a
SecurityManager.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe parallel backend for batch predictions. -
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 TypeMethodDescriptioncopy(String newName, ModelProvenance newProvenance) static KNNModel<?> deserializeFromProto(int version, String className, com.google.protobuf.Any message) Deserialization factory.getTopFeatures(int n) protected List<Prediction<T>> innerPredict(Iterable<Example<T>> examples) Uses the model to predict the output for multiple examples.org.tribuo.protos.core.ModelProtoMethods inherited from class org.tribuo.Model
castModel, copy, createDataCarrier, deserialize, deserializeFromFile, deserializeFromStream, generatesProbabilities, getExcuses, getFeatureIDMap, getName, getOutputIDInfo, getProvenance, predict, predict, serializeToFile, serializeToStream, setName, toString, validate
-
Field Details
-
CURRENT_VERSION
-
-
Method Details
-
deserializeFromProto
public static KNNModel<?> 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.
-
predict
-
innerPredict
Uses the model to predict the output for multiple examples.- Overrides:
innerPredictin classModel<T extends Output<T>>- Parameters:
examples- the examples to predict.- Returns:
- the results of the prediction, in the same order as the examples.
-
getTopFeatures
-
getExcuse
-
serialize
-
copy
-