Spaces:
Sleeping
Sleeping
Update cancer.py
Browse files
cancer.py
CHANGED
|
@@ -52,7 +52,7 @@ def train_model(x_train, y_train, preprocess, model_name):
|
|
| 52 |
('preprocessor', preprocess),
|
| 53 |
('classifier', models[model_name])
|
| 54 |
])
|
| 55 |
-
pipeline.fit(
|
| 56 |
return pipeline
|
| 57 |
|
| 58 |
# Streamlit UI
|
|
@@ -65,14 +65,14 @@ with st.sidebar:
|
|
| 65 |
if st.button("Train Model"):
|
| 66 |
# Load and preprocess data
|
| 67 |
df = load_data()
|
| 68 |
-
(
|
| 69 |
|
| 70 |
# Train model
|
| 71 |
try:
|
| 72 |
-
model = train_model(
|
| 73 |
-
accuracy = model.score(
|
| 74 |
st.session_state['trained_model'] = model
|
| 75 |
-
st.session_state['
|
| 76 |
st.success(f"Model Trained Successfully! Accuracy: {accuracy:.2f}")
|
| 77 |
except ValueError as e:
|
| 78 |
st.error(f"Error: {e}")
|
|
@@ -104,10 +104,10 @@ input_data = [[age, tumor_size, tumor_grade, symptoms_severity, smoking_history,
|
|
| 104 |
if st.button("Predict Cancer Presence"):
|
| 105 |
if 'trained_model' in st.session_state:
|
| 106 |
model = st.session_state['trained_model']
|
| 107 |
-
|
| 108 |
|
| 109 |
# Prepare input data for prediction
|
| 110 |
-
input_df = pd.DataFrame(input_data, columns=
|
| 111 |
input_transformed = model.named_steps['preprocessor'].transform(input_df)
|
| 112 |
|
| 113 |
# Make prediction
|
|
|
|
| 52 |
('preprocessor', preprocess),
|
| 53 |
('classifier', models[model_name])
|
| 54 |
])
|
| 55 |
+
pipeline.fit(x_train, y_train)
|
| 56 |
return pipeline
|
| 57 |
|
| 58 |
# Streamlit UI
|
|
|
|
| 65 |
if st.button("Train Model"):
|
| 66 |
# Load and preprocess data
|
| 67 |
df = load_data()
|
| 68 |
+
(x_train, x_test, y_train, y_test), preprocess = preprocess_data(df)
|
| 69 |
|
| 70 |
# Train model
|
| 71 |
try:
|
| 72 |
+
model = train_model(x_train, y_train, preprocess, model_name)
|
| 73 |
+
accuracy = model.score(x_test, y_test)
|
| 74 |
st.session_state['trained_model'] = model
|
| 75 |
+
st.session_state['x_train'] = x_train
|
| 76 |
st.success(f"Model Trained Successfully! Accuracy: {accuracy:.2f}")
|
| 77 |
except ValueError as e:
|
| 78 |
st.error(f"Error: {e}")
|
|
|
|
| 104 |
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 |
|
| 109 |
# Prepare input data for prediction
|
| 110 |
+
input_df = pd.DataFrame(input_data, columns=x_train.columns)
|
| 111 |
input_transformed = model.named_steps['preprocessor'].transform(input_df)
|
| 112 |
|
| 113 |
# Make prediction
|