cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

ColumnTransformer not fitted after sklearn Pipeline loaded from Mlflow

Nasreddin
New Contributor

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.

transformers = []
num_pipe = Pipeline(steps=[
    ('imputer', SimpleImputer(strategy='median')),
    ('scaler', StandardScaler())
])
transformers.append(('numerical', num_pipe, num_cols))
cat_pipe = Pipeline(steps=[
    ('imputer', SimpleImputer(strategy='most_frequent')),
    ('ohe', OneHotEncoder(handle_unknown='ignore'))
])
transformers.append(('categorical', cat_pipe, cat_cols))
preprocessor = ColumnTransformer(transformers, remainder='passthrough')
model = Pipeline([
  ('prep', preprocessor),
  ('clf', XGBClassifier())
])

I am using Mlflow to log the model artifact as sklearn model after it is fitted on training data.

model.fit(X, y)
mlflow.sklearn.log_model(model, model_uri)

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."

run_model = mlflow.sklearn.load_model(model_uri)
run_model.predict(X_pred)

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?

0 REPLIES 0

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group