varshitha22 commited on
Commit
f7ec01e
·
verified ·
1 Parent(s): 7c2ac15

Update cancer.py

Browse files
Files changed (1) hide show
  1. cancer.py +13 -10
cancer.py CHANGED
@@ -22,22 +22,25 @@ def preprocess_data(df):
22
  nominal = ['Gender', 'Family_History', 'Smoking_History']
23
 
24
  # Separate preprocessing steps for numeric and categorical features
 
 
 
 
 
25
  preprocess = ColumnTransformer([
26
  ('num', Pipeline([
27
- ('imputer', SimpleImputer(strategy='mean')), # Impute numeric columns with the mean
28
- ('scaler', StandardScaler()) # Standardize numeric columns
29
  ]), numeric),
30
-
31
  ('ord', Pipeline([
32
- ('imputer', SimpleImputer(strategy='most_frequent')), # Impute ordinal columns with the most frequent value
33
- ('encoder', OrdinalEncoder()) # Encode ordinal columns
34
  ]), ordinal),
35
-
36
  ('nom', Pipeline([
37
- ('imputer', SimpleImputer(strategy='most_frequent')), # Impute nominal columns with the most frequent value
38
- ('encoder', OneHotEncoder(sparse_output=False, handle_unknown='ignore')) # One hot encode nominal columns
39
  ]), nominal)
40
- ], remainder='passthrough') # Keep other columns unchanged
41
 
42
  X = df.drop('Cancer_Present', axis=1)
43
  y = df['Cancer_Present']
@@ -75,7 +78,7 @@ with st.sidebar:
75
  st.session_state['X_train'] = X_train
76
  st.success(f"Model Trained Successfully! Accuracy: {accuracy:.2f}")
77
 
78
- st.title("🎗️ Cancer Prediction Using Machine Learning 🎗️")
79
 
80
  st.markdown("""<style>.big-font {font-size:20px !important;}</style>
81
  <p class="big-font">Provide patient details below to predict cancer presence:</p>""", unsafe_allow_html=True)
 
22
  nominal = ['Gender', 'Family_History', 'Smoking_History']
23
 
24
  # Separate preprocessing steps for numeric and categorical features
25
+ def preprocess_data(df):
26
+ numeric = ['Age', 'Tumor_Size']
27
+ ordinal = ['Tumor_Grade', 'Symptoms_Severity', 'Alcohol_Consumption', 'Exercise_Frequency']
28
+ nominal = ['Gender', 'Family_History', 'Smoking_History']
29
+ # Data Preprocessing
30
  preprocess = ColumnTransformer([
31
  ('num', Pipeline([
32
+ ('imputer', SimpleImputer(strategy='mean')),
33
+ ('scaler', StandardScaler())
34
  ]), numeric),
 
35
  ('ord', Pipeline([
36
+ ('imputer', SimpleImputer(strategy='most_frequent')),
37
+ ('encoder', OrdinalEncoder(handle_unknown="use_encoded_value", unknown_value=-1))
38
  ]), ordinal),
 
39
  ('nom', Pipeline([
40
+ ('imputer', SimpleImputer(strategy='most_frequent')),
41
+ ('encoder', OneHotEncoder(sparse_output=False, handle_unknown='ignore'))
42
  ]), nominal)
43
+ ], remainder='passthrough')
44
 
45
  X = df.drop('Cancer_Present', axis=1)
46
  y = df['Cancer_Present']
 
78
  st.session_state['X_train'] = X_train
79
  st.success(f"Model Trained Successfully! Accuracy: {accuracy:.2f}")
80
 
81
+ st.title("🎗️ Cancer Prediction")
82
 
83
  st.markdown("""<style>.big-font {font-size:20px !important;}</style>
84
  <p class="big-font">Provide patient details below to predict cancer presence:</p>""", unsafe_allow_html=True)