Skip to main content

Additional Fields

In many cases it is useful to output additional information from the model besides the actual prediction list. This can be achieved very simply by adding keys to the output dictionary of the model’s predict method.

Example:

import mlflow


class AdditionalFields(mlflow.pyfunc.PythonModel):
def predict(self, context, model_input):
return {
'prediction': [1.] * model_input.shape[0],
'extra': {
'this': 'can be any JSON serializable structure',
}
}

The API will place any data not included in the prediction field into the additionalFields object, so a response of the above model to a prediction request would look like:

{
"predictions": [
{
"prediction": "1.0"
}
],
"additionalFields": {
"extra": {
"this": "can be any JSON serializable structure"
}
}
}

Multiple Target Columns

While it is possible to specify multiple target columns in the model’s Request Schema, currently the navio API will only consider the first target column in the provided list of columns when generating the prediction endpoint. A temporary workaround is to use the functionality for including additional fields in the model’s output.