Hi,
I’m trying deploying my first streamlit app.
I want to use the pycaret library to load pre-trained models into the app to forecast new data.
However, it fails to load the model (pkl) file and gives me the following error and I don’t know why
All Code below
import streamlit as st
import numpy as np
import pandas as pd
def convert_df(df):
return df.to_csv(index=False).encode('shift-jis')
def predict(loaded_model, df):
pred_holdout = predict_model(loaded_model, data=df)
plot_model(loaded_model, plot='residuals', display_format='streamlit')
plot_model(loaded_model, plot='feature', display_format='streamlit')
plot_model(loaded_model, plot='error', display_format='streamlit')
st.markdown("#### output the result as prediction_label")
st.dataframe(pred_holdout, height=200)
csv = convert_df(pred_holdout)
st.download_button(
"Download result",
csv,
"predict.csv",
"text/csv",
key='download-csv'
)
return pred_holdout
st.markdown("# AutoML Tool")
#st.sidebar.markdown("import the data")
uploaded_file = st.sidebar.file_uploader("import the data", type='csv', key='train')
if uploaded_file is not None:
df = pd.read_csv(uploaded_file, encoding="shift-jis")
st.markdown("#### 1. check the data")
st.dataframe(df.head(10))
st.markdown("### 2. select the method")
ml_usecase = st.selectbox(label='regression or classification',
options=('', 'regression', 'classification'),
key='ml_usecase')
if ml_usecase == 'regression':
from pycaret.regression import *
elif ml_usecase == 'classification':
from pycaret.classification import *
pkl_file = st.file_uploader("import model", type=".pkl", accept_multiple_files=False)
if pkl_file is not None:
loaded_model = load_model(pkl_file)
target = st.selectbox(label='input objective variable', options=df.keys())
ml = setup(data=df,
target=target,
)
predict(loaded_model, df)