I have implemented an XGB Regressor Model in Python but it runs fine in Jupyter Notebook but is raising an error in streamlit application. I am confused as I am not able to debug the following error -
ValueError: DataFrame for label cannot have multiple columns
Code for Streamlit app-
import pandas as pd
import numpy as np
import xgboost as xgb
from xgboost import plot_importance, plot_tree
from sklearn.metrics import mean_squared_error, mean_absolute_error
from catboost import Pool, CatBoostRegressor
import lightgbm as lgb
import streamlit as st
def main():
st.title("TINO IQ Stock Price Prediction App")
st.sidebar.title("TINO IQ Stock Price Prediction App")
st.markdown("Predicting the Stock Price!")
st.sidebar.markdown("Predicting the Stock Price!")
@st.cache(persist=True)
def show_data():
data = pd.read_csv('data_orginal.csv')
data = data.drop(['Unnamed: 0'],axis=1)
return data
def load_data():
df = pd.read_csv('data.csv')
# label_encoder object knows how to understand word labels.
#Filling the missing values
df = df.fillna(0)
#Feature Engineering
df['txn_year'] = df['txn_year']-2000
return df
def split(df):
#Splitting the Data according to the Date
split_date = '2019-08-01'
df_train = df.loc[df['date_txn'] <= split_date]
df_test = df.loc[df['date_txn'] > split_date]
#Assigning X and Y values
X_train = df_train.drop(['predicted_price','date_txn'],axis=1)
y_train = df_train[['predicted_price']]
X_test = df_test.drop(['predicted_price','date_txn'],axis=1)
y_test = df_test[['predicted_price']]
return X_train,y_train,X_test,y_test
df = load_data()
X_train,X_test,y_train,y_test = split(df)
st.sidebar.subheader("Choose Classifier")
classifier = st.sidebar.selectbox("Available Classifiers",("XGBOOSTRegressor(XGB)","CatBoostRegressor(CGB)","LGBMRegressor(LGBM)"))
show = show_data()
if st.sidebar.checkbox("Show Raw Data", False):
st.subheader("Data_Set")
st.write(show[:10])
if classifier == 'XGBOOSTRegressor(XGB)':
st.sidebar.subheader('Model Hyperparameters')
n_estimators = st.sidebar.number_input("n_estimators (Number of Estimators)",10000,15000, step=1,key='n_estimators')
early_stopping_rounds = st.sidebar.number_input("early_stopping_rounds(Number of Stopping Rounds)",50,100,step=10,key='early_stopping_rounds')
if st.sidebar.button("Classify", key='classify'):
st.subheader("XGBOOSTRegressor Results")
model = xgb.XGBRegressor(n_estimators = n_estimators)
model.fit(X_train, y_train,
eval_set=[(X_train, y_train), (X_test, y_test)],
early_stopping_rounds=early_stopping_rounds,
verbose=False)
model.fit(X_train,y_train)
preds = reg.predict(X_test)
st.write("Mean Squared Error:",mean_squared_error(y_test, preds, squared=False))
if __name__ == '__main__':
main()
Actual Problem-
Dataset-