ColumnTransformer not fitted after sklearn Pipeline loaded from Mlflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2021 01:20 PM
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?
- Labels:
-
MlFlow
-
Model
-
Sklean Pipeline
-
Sklearn
![](/skins/images/8C2A30E5B696B676846234E4B14F2C7B/responsive_peak/images/icon_anonymous_message.png)
![](/skins/images/8C2A30E5B696B676846234E4B14F2C7B/responsive_peak/images/icon_anonymous_message.png)