varshitha22 commited on
Commit
872d1e9
·
verified ·
1 Parent(s): 370eb34

Update cancer.py

Browse files
Files changed (1) hide show
  1. cancer.py +8 -2
cancer.py CHANGED
@@ -97,10 +97,16 @@ if st.button("Predict Cancer Presence"):
97
  if 'trained_model' in st.session_state:
98
  model = st.session_state['trained_model']
99
  x_train = st.session_state['x_train']
 
 
100
  input_df = pd.DataFrame(input_data, columns=x_train.columns)
 
 
101
  input_transformed = model.named_steps['preprocessor'].transform(input_df)
 
 
102
  prediction = model.named_steps['classifier'].predict(input_transformed)
103
-
104
  if prediction[0] == 1:
105
  st.markdown("<h3 style='color: red;'>Cancer Prediction: Positive 🟥</h3>", unsafe_allow_html=True)
106
  st.write("Unfortunately, the model predicts the presence of cancer. Please consult a doctor for further advice.")
@@ -108,4 +114,4 @@ if st.button("Predict Cancer Presence"):
108
  st.markdown("<h3 style='color: green;'>Cancer Prediction: Negative 🟩</h3>", unsafe_allow_html=True)
109
  st.write("Good news! The model predicts that there is no cancer detected. Stay healthy!")
110
  else:
111
- st.error("Please train a model first!")
 
97
  if 'trained_model' in st.session_state:
98
  model = st.session_state['trained_model']
99
  x_train = st.session_state['x_train']
100
+
101
+ # Create DataFrame for input
102
  input_df = pd.DataFrame(input_data, columns=x_train.columns)
103
+
104
+ # Apply preprocessing (fix error)
105
  input_transformed = model.named_steps['preprocessor'].transform(input_df)
106
+
107
+ # Make prediction
108
  prediction = model.named_steps['classifier'].predict(input_transformed)
109
+
110
  if prediction[0] == 1:
111
  st.markdown("<h3 style='color: red;'>Cancer Prediction: Positive 🟥</h3>", unsafe_allow_html=True)
112
  st.write("Unfortunately, the model predicts the presence of cancer. Please consult a doctor for further advice.")
 
114
  st.markdown("<h3 style='color: green;'>Cancer Prediction: Negative 🟩</h3>", unsafe_allow_html=True)
115
  st.write("Good news! The model predicts that there is no cancer detected. Stay healthy!")
116
  else:
117
+ st.error("Please train a model first!")