varshitha22 commited on
Commit
fca6233
·
verified ·
1 Parent(s): 30ec374

Update cancer.py

Browse files
Files changed (1) hide show
  1. cancer.py +11 -1
cancer.py CHANGED
@@ -105,10 +105,20 @@ if st.button("Predict Cancer Presence"):
105
  if 'trained_model' in st.session_state:
106
  model = st.session_state['trained_model']
107
  x_train = st.session_state['x_train']
 
 
108
  input_df = pd.DataFrame(input_data, columns=x_train.columns)
 
 
 
 
 
 
109
  input_transformed = model.named_steps['preprocessor'].transform(input_df)
 
 
110
  prediction = model.named_steps['classifier'].predict(input_transformed)
111
-
112
  if prediction[0] == 1:
113
  st.markdown("<h3 style='color: red;'>Cancer Prediction: Positive 🟥</h3>", unsafe_allow_html=True)
114
  st.write("Unfortunately, the model predicts the presence of cancer. Please consult a doctor for further advice.")
 
105
  if 'trained_model' in st.session_state:
106
  model = st.session_state['trained_model']
107
  x_train = st.session_state['x_train']
108
+
109
+ # Create DataFrame for input
110
  input_df = pd.DataFrame(input_data, columns=x_train.columns)
111
+
112
+ # Convert numeric inputs explicitly to float
113
+ for col in ['Age', 'Tumor_Size']:
114
+ input_df[col] = pd.to_numeric(input_df[col], errors='coerce')
115
+
116
+ # Apply preprocessing
117
  input_transformed = model.named_steps['preprocessor'].transform(input_df)
118
+
119
+ # Make prediction
120
  prediction = model.named_steps['classifier'].predict(input_transformed)
121
+
122
  if prediction[0] == 1:
123
  st.markdown("<h3 style='color: red;'>Cancer Prediction: Positive 🟥</h3>", unsafe_allow_html=True)
124
  st.write("Unfortunately, the model predicts the presence of cancer. Please consult a doctor for further advice.")