Pycaret plot_model not displaying

Summary

I’m trying to display the feature importance chart from the pycaret library, but the chart is not displayed

Steps to reproduce

Code snippet:

import streamlit as st
from pycaret.regression import *
import pandas as pd
import os

if os.path.exists('./dataset.csv'):
    df = pd.read_csv('dataset.csv', index_col=None)
    chosen_target = st.selectbox('Choose the Target Column', df.columns)
    if st.button('Run Modelling'):
        s = setup(df, target=chosen_target, session_id = 123)
        best_model = compare_models()
        plot_model(best_model, plot='feature', display_format='streamlit')

Apart from the graph, the code works and the model is created correctly. Sample data: Vehicle dataset | Kaggle

Expected behavior:

Need to see feature importance plot like in PyCaret inside Streamlit - #16 by ferdy

Actual behavior:

The plot is not displayed.

Debug info

  • Streamlit version: 1.27.2
  • Python version: 3.9.13
  • Pycaret 3.10

Hey @Keszzz! :wave:

It’s not something I’ve tried, but instead of directly plotting with PyCaret’s plot_model function, you might consider using Streamlit’s st.pyplot function to display it.

Also, have you checked that you’re using the latest versions of both Streamlit and PyCaret?

Best,
Charly

Here’s one way to get it to work (not sure why display_format=“streamlit” isn’t working)

        img = plot_model(
            best_model, plot="feature", display_format="streamlit", save=True
        )
        st.image(img)

Great walkaround. Works perfectly.