英文:
Unable to capture or show the compare_model() metrics in streamlit
问题
以下是翻译好的部分:
我已经创建了一个Streamlit应用程序,以允许我在使用PyCaret Time series的数据集上运行多个实验。我的问题是,我无法捕获和显示Streamlit应用程序中的compare_model()结果表(显示所有测试算法的性能指标表)。
以下是我的代码:
import streamlit as st
from pycaret.time_series import TSForecastingExperiment
from pycaret.time_series import *
# 设置时间序列预测
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("运行时间序列模型:"):
best = exp_auto.compare_models(sort="mape", turbo=False, verbose=True)
st.write(best)
我无法获取性能指标表打印出来,我一直得到设置表的结果,而不是compare_model()的结果,尽管我在setup()中尝试了verbose=False。
英文:
I have created streamlit app to allow me to run multiple experiments on a dataset using PyCaret Time series. My problem is that I am unable to capture and show the compare_model() results table in my streamlit app, (the metrics table that shows the performance in all tested algorithms).
Here is my code:
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)
I can not get the metrics table to print out, i keep getting the setup table results instead of the compare_model() results, although I tried verbose=False in the setup()
答案1
得分: 0
默认情况下,compare_models()
不会返回数据框,而是返回已训练的模型。如果您想要指标表,请尝试使用pull()
来获取最后打印的得分表,然后可以在streamlit上显示它。
from pycaret.datasets import get_data
from pycaret.time_series import TSForecastingExperiment
import streamlit as st
# 获取数据
y = get_data('airline', verbose=False)
# 实验
exp = TSForecastingExperiment()
exp.setup(data=y, fh=12, verbose=False)
if st.button("运行时间序列模型:"):
best = exp.compare_models(include=['arima','exp_smooth','ets'], verbose=False)
# 提取指标
metrics = exp.pull()
st.write(metrics)
# 绘制图形
exp.plot_model(estimator=best, display_format='streamlit')
英文:
By default compare_models()
didn't return results as DataFrame instead it returned the trained model. If you want the metrics table try to use pull()
to get the last printed score grid and then you can display it on streamlit.
<!-- language: lang-py -->
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')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论