Spaces:
Sleeping
Sleeping
Update cancer.py
Browse files
cancer.py
CHANGED
|
@@ -50,7 +50,7 @@ def train_model(x_train, y_train, preprocess, model_name):
|
|
| 50 |
('preprocessor', preprocess),
|
| 51 |
('classifier', models[model_name])
|
| 52 |
])
|
| 53 |
-
pipeline.fit(
|
| 54 |
return pipeline
|
| 55 |
|
| 56 |
# Streamlit UI
|
|
@@ -62,11 +62,11 @@ with st.sidebar:
|
|
| 62 |
model_name = st.radio("Choose a Model", ['Decision Tree', 'Logistic Regression', 'KNN', 'Random Forest', 'XGBoost'])
|
| 63 |
if st.button("Train Model"):
|
| 64 |
df = load_data()
|
| 65 |
-
(
|
| 66 |
-
model = train_model(
|
| 67 |
-
accuracy = model.score(
|
| 68 |
st.session_state['trained_model'] = model
|
| 69 |
-
st.session_state['
|
| 70 |
st.success(f"Model Trained Successfully! Accuracy: {accuracy:.2f}")
|
| 71 |
|
| 72 |
st.title("🎗️ Cancer Prediction")
|
|
@@ -94,8 +94,8 @@ input_data = [[age, tumor_size, tumor_grade, symptoms_severity, smoking_history,
|
|
| 94 |
if st.button("Predict Cancer Presence"):
|
| 95 |
if 'trained_model' in st.session_state:
|
| 96 |
model = st.session_state['trained_model']
|
| 97 |
-
|
| 98 |
-
input_df = pd.DataFrame(input_data, columns=
|
| 99 |
input_transformed = model.named_steps['preprocessor'].transform(input_df)
|
| 100 |
prediction = model.named_steps['classifier'].predict(input_transformed)
|
| 101 |
|
|
|
|
| 50 |
('preprocessor', preprocess),
|
| 51 |
('classifier', models[model_name])
|
| 52 |
])
|
| 53 |
+
pipeline.fit(x_train, y_train)
|
| 54 |
return pipeline
|
| 55 |
|
| 56 |
# Streamlit UI
|
|
|
|
| 62 |
model_name = st.radio("Choose a Model", ['Decision Tree', 'Logistic Regression', 'KNN', 'Random Forest', 'XGBoost'])
|
| 63 |
if st.button("Train Model"):
|
| 64 |
df = load_data()
|
| 65 |
+
(x_train, x_test, y_train, y_test), preprocess = preprocess_data(df)
|
| 66 |
+
model = train_model(x_train, y_train, preprocess, model_name)
|
| 67 |
+
accuracy = model.score(x_test, y_test)
|
| 68 |
st.session_state['trained_model'] = model
|
| 69 |
+
st.session_state['x_train'] = x_train
|
| 70 |
st.success(f"Model Trained Successfully! Accuracy: {accuracy:.2f}")
|
| 71 |
|
| 72 |
st.title("🎗️ Cancer Prediction")
|
|
|
|
| 94 |
if st.button("Predict Cancer Presence"):
|
| 95 |
if 'trained_model' in st.session_state:
|
| 96 |
model = st.session_state['trained_model']
|
| 97 |
+
x_train = st.session_state['x_train']
|
| 98 |
+
input_df = pd.DataFrame(input_data, columns=x_train.columns)
|
| 99 |
input_transformed = model.named_steps['preprocessor'].transform(input_df)
|
| 100 |
prediction = model.named_steps['classifier'].predict(input_transformed)
|
| 101 |
|