diff --git a/doc/source/servers/mlflow.md b/doc/source/servers/mlflow.md index 8b3fbb8760..672b6ab241 100644 --- a/doc/source/servers/mlflow.md +++ b/doc/source/servers/mlflow.md @@ -52,6 +52,32 @@ spec: replicas: 1 ``` +## MLFlow xtype + +By default the server will call your loaded model's predict function with a `numpy.ndarray`. If you wish for it to call it with `pandas.DataFrame` instead, you can pass a parameter `X_type` and set it to `DataFrame`. For example: + +```yaml +apiVersion: machinelearning.seldon.io/v1alpha2 +kind: SeldonDeployment +metadata: + name: mlflow +spec: + name: wines + predictors: + - graph: + children: [] + implementation: MLFLOW_SERVER + modelUri: gs://seldon-models/mlflow/elasticnet_wine + name: classifier + parameters: + - name: xtype + type: STRING + value: DataFrame + name: default + replicas: 1 +``` + +``` You can also try out a [worked notebook](../examples/server_examples.html#Serve-MLflow-Elasticnet-Wines-Model) or check our [talk at the Spark + AI Summit diff --git a/servers/mlflowserver/mlflowserver/MLFlowServer.py b/servers/mlflowserver/mlflowserver/MLFlowServer.py index 85f2fcd666..44f8337c0d 100644 --- a/servers/mlflowserver/mlflowserver/MLFlowServer.py +++ b/servers/mlflowserver/mlflowserver/MLFlowServer.py @@ -15,10 +15,12 @@ class MLFlowServer(SeldonComponent): - def __init__(self, model_uri: str): + def __init__(self, model_uri: str, xtype: str = 'ndarray'): super().__init__() logger.info(f"Creating MLFLow server with URI {model_uri}") + logger.info(f"xtype: {xtype}") self.model_uri = model_uri + self.xtype = xtype self.ready = False def load(self): @@ -34,11 +36,15 @@ def predict( if not self.ready: raise requests.HTTPError("Model not loaded yet") - if feature_names is not None and len(feature_names) > 0: - df = pd.DataFrame(data=X, columns=feature_names) + + if self.xtype == "ndarray": + result = self._model.predict(X) else: - df = pd.DataFrame(data=X) - result = self._model.predict(df) + if feature_names is not None and len(feature_names) > 0: + df = pd.DataFrame(data=X, columns=feature_names) + else: + df = pd.DataFrame(data=X) + result = self._model.predict(df) logger.info(f"Prediction result: {result}") return result