Using first time streamlit it is easy to understand but i get only one output value from this code . please guide me

import numpy as np

import pickle

import streamlit as st

# loading the saved model

loaded_model = pickle.load(open('trained_model.sav', 'rb'))

# creating a function for Prediction

def diabetes_prediction(input_data):

   

    # changing the input_data to numpy array

    input_data_as_numpy_array = np.asarray(input_data)

    # reshape the array as we are predicting for one instance

    input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)

    prediction = loaded_model.predict(input_data_reshaped)

    # print(prediction)

    if (prediction[0] == 1):

      return 'The person is  diabetic'

    else:

      return 'The person is not diabetic'

       

def main():

       

    # giving a title

    st.title('Diabetes Prediction Web App')

       

    # getting the input data from the user

       

    Pregnancies = st.text_input('Number of Pregnancies')

    Glucose = st.text_input('Glucose Level')

    BloodPressure = st.text_input('Blood Pressure value')

    SkinThickness = st.text_input('Skin Thickness value')

    Insulin = st.text_input('Insulin Level')

    BMI = st.text_input('BMI value')

    DiabetesPedigreeFunction = st.text_input('Diabetes Pedigree Function value')

    Age = st.text_input('Age of the Person')

       

    # code for Prediction

    diagnosis = ''

   

    # creating a button for Prediction

   

    if st.button('Diabetes Test Result'):

        diagnosis = diabetes_prediction([Pregnancies, Glucose, BloodPressure, SkinThickness, Insulin, BMI, DiabetesPedigreeFunction, Age])

               

    st.success(diagnosis)

                   

if __name__ == '__main__':

    main()

Hi @Selvin_Macwan, welcome to the Streamlit community!

Though I’m not entirely sure what you are asking, I think the problem may be here:

  if (prediction[0] == 1):

      return 'The person is  diabetic'

    else:

      return 'The person is not diabetic'

For any classification model, the values can generally take the value of 0 to 1, but it’s unlikely that you’ll get exactly a value of 1. Usually you want to test if the model value exceeds some threshold, like 0.5 or whatever the expected rate of ‘success’ is in your sample.

If this is not your issue, please provide more details about the error you are experiencing.

Best,
Randy

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.