load MLFlow model and plot feature importance with feature names

If I save a xgboost model in mlflow with mlflow.xgboost.log_model(model, "model") and load it with model = mlflow.xgboost.load_model("models:/model_uri") and want to plot the feature importance with xgboost.plot_importance(model) the problem is that the features are not shown with names (see plot). If I plot the feature without saving in mlflow the origin feature names are shown. Do I have to store the model in another way?enter image description here

3

1 Answer

Usually, if you use a pipeline It can happen for example on FeatureUnion from sklearn.

You can try to get the feature index from the model or the last step of the pipeline and use it to retrieve the feature names from the dataset.

If you are using a pipeline you can try to get the feature the step before this problem appears or edit the step, also be aware if you are using feature selection different situations can happen.

You can use autologging to autosave the plot, but the same problem happen if it is pipeline.

You could save the model like an artifact, if you think to do it, my suggestion is to use the Dill package.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like