Spaces:
Sleeping
Sleeping
Update cancer.py
Browse files
cancer.py
CHANGED
|
@@ -36,13 +36,20 @@ def preprocess_data(df):
|
|
| 36 |
return train_test_split(X, y, test_size=0.2, random_state=23), preprocess
|
| 37 |
|
| 38 |
# Train Models
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
pipeline = Pipeline([
|
| 41 |
('preprocessor', preprocess),
|
| 42 |
-
('classifier',
|
| 43 |
])
|
| 44 |
-
pipeline.fit(
|
| 45 |
-
return pipeline
|
| 46 |
|
| 47 |
# Streamlit UI
|
| 48 |
st.set_page_config(page_title='Cancer Prediction App', layout='wide')
|
|
|
|
| 36 |
return train_test_split(X, y, test_size=0.2, random_state=23), preprocess
|
| 37 |
|
| 38 |
# Train Models
|
| 39 |
+
# Train Model
|
| 40 |
+
def train_model(x_train, y_train, preprocess, model_name):
|
| 41 |
+
models = {
|
| 42 |
+
'Decision Tree': DecisionTreeClassifier(),
|
| 43 |
+
'Logistic Regression': LogisticRegression(),
|
| 44 |
+
'KNN': KNeighborsClassifier(),
|
| 45 |
+
'Random Forest': RandomForestClassifier(),
|
| 46 |
+
'XGBoost': XGBClassifier()
|
| 47 |
+
}
|
| 48 |
pipeline = Pipeline([
|
| 49 |
('preprocessor', preprocess),
|
| 50 |
+
('classifier', models[model_name])
|
| 51 |
])
|
| 52 |
+
pipeline.fit(x_train, y_train)
|
|
|
|
| 53 |
|
| 54 |
# Streamlit UI
|
| 55 |
st.set_page_config(page_title='Cancer Prediction App', layout='wide')
|