While deploying my model with streamlit, I am getting the error below;
Error: ufunc ‘isnan’ not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ”safe”
The data has no NaNs and the model is a pipline including preprocessing steps. When I replicate the prediction in my notebook, it works fine. I can’t figure out why the error comes up.
When I print the filtered data as a df, the index doesn’t match in the notebook vs streamlit, would that have anything to do with the error? I’m also training the model on a subset of data since I don’t have the computational resources to use the full dataset but I don’t see what that has to do with anything if preprocessing is included in the model pipeline.
I’m using the same environment in notebook and streamlit so that should be aligned.
prediction code in streamlit:
if st.session_state['predict_clicked']:
input_data = X[(X['StateAbbr'] == state) & (X['LocationName'] == county)]
st.write("Filtered data:", input_data.head())
if not input_data.empty:
prediction_data = input_data.copy()
try:
prediction = model.predict(prediction_data).mean()
st.success(f"Predicted Health Disparity Index: {prediction}")
st.write("### Detailed Prediction Data")
st.dataframe(prediction_data)
I would expect the output to be a mean of the predicted values of the filtered input_data.
ElinaR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.