python-3.x 无法在Streamlit中捕获或显示compare_model()指标

ojsjcaue  于 2023-04-08  发布在  Python
关注(0)|答案(1)|浏览(168)

我创建了streamlit应用程序,允许我使用PyCaret时间序列在数据集上运行多个实验。我的问题是我无法在我的streamlit应用程序中捕获和显示compare_model()结果表,(显示所有测试算法性能的指标表)。
下面是我的代码:

import streamlit as st
    from pycaret.time_series import TSForecastingExperiment
    from pycaret.time_series import *

    # set up for time series forecasting
    exp_auto = TSForecastingExperiment()
    exp_auto.setup(
        data=df_exog, target='qty', fh=fh, enforce_exogenous=False,
        numeric_imputation_target="ffill", numeric_imputation_exogenous="ffill",
        scale_target="minmax",
        scale_exogenous="minmax",
        fold_strategy="expanding",
        session_id=42,verbose=False)
    
    
    
    if st.button("Run Time series models:"):
    
        best = exp_auto.compare_models(sort="mape", turbo=False,verbose=True)
        st.write(best)

我无法打印出指标表,我一直得到设置表结果而不是compare_model()结果,尽管我在setup()中尝试了verbose=False

wrrgggsh

wrrgggsh1#

默认情况下,compare_models()不会以DataFrame的形式返回结果,而是返回训练模型。如果您想要指标表,请尝试使用pull()获取最后打印的分数网格,然后您可以在streamlit上显示它。

from pycaret.datasets import get_data
from pycaret.time_series import TSForecastingExperiment
import streamlit as st

# Get data
y = get_data('airline', verbose=False)

# Experiment
exp = TSForecastingExperiment()
exp.setup(data=y, fh=12, verbose=False)

if st.button("Run Time series models:"):
    best = exp.compare_models(include=['arima','exp_smooth','ets'], verbose=False)
    # Pull metrics
    metrics = exp.pull()
    st.write(metrics)
    
    # Plot graph
    exp.plot_model(estimator=best, display_format='streamlit')

相关问题