i am trying to build a streamlit application using XGBoost, the code for it as follows:
import streamlit as st
import pickle
import joblib
import numpy as np
import xgboost as xgb
loaded_xgb_model = xgb.Booster()
loaded_xgb_model.load_model(‘C:/Users/soumya sharma/PycharmProjects/pythonProject1/obligation/xgb_model.xgb’)
#load_model = joblib.load(‘C:/Users/soumya sharma/PycharmProjects/pythonProject1/obligation/rf_model.pkl’)
input_data =[540,0,0,162,2.5,1040,676,28]
input_as_array = np.asarray(input_data)
input_reshaped = input_as_array.reshape(1,-1)
prediction = rf_model.predict(input_reshaped)
print(prediction)
def prediction(input_data):
# input_as_array = np.asarray(input_data)
# input_reshaped = input_as_array.reshape(1,-1)
input_data_as_ascii = [str(value).encode(‘ascii’, ‘ignore’).decode(‘ascii’) for value in input_data]
input_dmatrix = xgb.DMatrix([input_data_as_ascii])
prediction = loaded_xgb_model.predict(input_dmatrix)
return f"The predicted strength of concrete is {prediction}"
def main():
st.title(“Concrete Strength Prediction”)
Cement = st.text_input(“Quantity of Cement”)
Blast_furnace_Slag = st.text_input(“Quantity of Blast_furnace_Slag”)
Fly_Ash = st.text_input(“Quantity of Fly_Ash”)
Water = st.text_input(“Quantity of Water”)
SuperPlasticizer = st.text_input(“Quantity of SuperPlasticizer”)
CoarseAgg = st.text_input(“Quantity of Coarse Aggregates”)
Fine_Agg = st.text_input(“Quantity of Fine Aggregate”)
Age = st.text_input(“Age of the Concrete”)
strength =" "
if st.button("Check Concrete Strength"):
strength = prediction(
[Cement, Blast_furnace_Slag, Fly_Ash, Water, SuperPlasticizer, CoarseAgg, Fine_Agg, Age])
st.success(strength)
if name == ‘main’:
main()
But I am getting an error even after trying a lot, the error is:
XGBoostError: [12:30:28] C:\buildkite-agent\builds\buildkite-windows-cpu-autoscaling-group-i-07f6e447eee219473-1\xgboost\xgboost-ci-windows\src\data\array_interface.h:492: Unicode-4 is not supported.
Traceback:
File "C:\Users\soumya sharma\AppData\Local\Programs\Python\Python311\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 552, in _run_script
exec(code, module.__dict__)File "C:\Users\soumya sharma\PycharmProjects\pythonProject1\obligation\pages\rf_check.py", line 45, in <module>
main()File "C:\Users\soumya sharma\PycharmProjects\pythonProject1\obligation\pages\rf_check.py", line 39, in main
strength = prediction(
^^^^^^^^^^^File "C:\Users\soumya sharma\PycharmProjects\pythonProject1\obligation\pages\rf_check.py", line 22, in prediction
input_dmatrix = xgb.DMatrix([input_data_as_ascii])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\soumya sharma\AppData\Local\Programs\Python\Python311\Lib\site-packages\xgboost\core.py", line 729, in inner_f
return func(**kwargs)
^^^^^^^^^^^^^^File "C:\Users\soumya sharma\AppData\Local\Programs\Python\Python311\Lib\site-packages\xgboost\core.py", line 856, in __init__
handle, feature_names, feature_types = dispatch_data_backend(
^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\soumya sharma\AppData\Local\Programs\Python\Python311\Lib\site-packages\xgboost\data.py", line 1081, in dispatch_data_backend
return _from_list(data, missing, threads, feature_names, feature_types)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\soumya sharma\AppData\Local\Programs\Python\Python311\Lib\site-packages\xgboost\data.py", line 1011, in _from_list
return _from_numpy_array(array, missing, n_threads, feature_names, feature_types)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "C:\Users\soumya sharma\AppData\Local\Programs\Python\Python311\Lib\site-packages\xgboost\data.py", line 207, in _from_numpy_array
_check_call(File "C:\Users\soumya sharma\AppData\Local\Programs\Python\Python311\Lib\site-packages\xgboost\core.py", line 281, in _check_call
raise XGBoostError(py_str(_LIB.XGBGetLastError()))
can anyone please help me with it