Nearest Neighbors models (C API)

typedef struct _EmlNeighborsModel EmlNeighborsModel

Nearest Neighbors Model.

Handle used to do inference. Normally the initialization code is generated by emlearn.

EmlError eml_neighbors_predict(EmlNeighborsModel *self, const int16_t *features, int features_length, EmlNeighborsDistanceItem *distances, int distances_length, int16_t *out)

Run inference and return most probable class.

Parameters:
  • self – EmlNeighborsModel instance

  • features – Input data values

  • features_length – Length of input data

  • distances – Array to use for storing distances

  • distances_length – Length of distance array. Must be larger than model->n_items

  • out – Location to return predicted class label

Returns:

EmlOk on success, or -EmlError on failure

EmlError eml_neighbors_add_item(EmlNeighborsModel *self, const int16_t *values, int16_t values_length, int16_t label)

Add a datapoint to the model / training set.

Parameters:
  • self – EmlNeighborsModel instance

  • values – Feature values for this datapoint

  • values_length – Length of feature data. Must equal model->n_features

  • label – The label to associate with this datapoint

Returns:

EmlOk on success, or -EmlError on failure

typedef struct _EmlNeighborsDistanceItem EmlNeighborsDistanceItem

Distance between input datapoint and a training datapoint.

Used during inference.