I am building a machine learning model using sklearn Pipeline which includes a ColumnTransformer as a preprocessor before the actual model. Below is the code how the pipeline is created.
When I tried to load the model from mlflow for scoring though, I got the error "This ColumnTransformer instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator."
I also ran check_is_fitted on the second step of the Pipeline which is the xgboost model itself after loaded from mlflow and it is NOT fitted either.
Is Mlflow not compatible with sklearn Pipeline with multiple steps?
To directly answer your question: yes, MLFlow is compatible with sklearn Pipelines, our own AutoML glassbox generator uses a (nearly identical) Pipeline for xgboost training.
I have attached a sample notebook that I was able to run end-to-end to train your exact Pipeline on. the adult-income dataset, log it to MLFlow, load it back from MLFlow, and use it to predict values. I also included some calls to check_is_fitted to see that
it's not fitted until you run
model.fit
then everything in the Pipeline is fitted
the. logged model is fitted
Hope this helps as a guide, let me know if you have any other questions or issues.
To directly answer your question: yes, MLFlow is compatible with sklearn Pipelines, our own AutoML glassbox generator uses a (nearly identical) Pipeline for xgboost training.
I have attached a sample notebook that I was able to run end-to-end to train your exact Pipeline on. the adult-income dataset, log it to MLFlow, load it back from MLFlow, and use it to predict values. I also included some calls to check_is_fitted to see that
it's not fitted until you run
model.fit
then everything in the Pipeline is fitted
the. logged model is fitted
Hope this helps as a guide, let me know if you have any other questions or issues.
Hi
@Nasreddin
,
MLflow is compatible with sklearn Pipeline with multiple steps. The error you're encountering, "This ColumnTransformer instance is not fitted yet. Call’ fit’ with appropriate arguments before using this estimator." is likely because
ColumnTransformer
of the
Pipeline
is not fitted correctly before being logged to MLflow.
Looking at your code, it seems you are fitting and logging the model accurately. The issue might be with the loading of the model. When you load the model from MLflow, ensure that the model_uri correctly points to the logged model. Also, provide the model was successfully logged and saved in the correct path.
Please verify these points and try again. If the problem persists, it might be a good idea to check the versions of sklearn, xgboost, and MLflow you are using and ensure they are compatible.
Welcome to Databricks Community: Lets learn, network and celebrate together
Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections.