Spaces:
Sleeping
Sleeping
Update cancer.py
Browse files
cancer.py
CHANGED
|
@@ -10,13 +10,10 @@ from sklearn.linear_model import LogisticRegression
|
|
| 10 |
from sklearn.neighbors import KNeighborsClassifier
|
| 11 |
from sklearn.ensemble import RandomForestClassifier
|
| 12 |
from xgboost import XGBClassifier
|
| 13 |
-
from sklearn.metrics import classification_report
|
| 14 |
|
| 15 |
# Load dataset
|
| 16 |
def load_data():
|
| 17 |
-
|
| 18 |
-
st.write("Class distribution:", df['Cancer_Present'].value_counts())
|
| 19 |
-
return df
|
| 20 |
|
| 21 |
# Data Preprocessing
|
| 22 |
def preprocess_data(df):
|
|
@@ -46,11 +43,11 @@ def preprocess_data(df):
|
|
| 46 |
# Train Model
|
| 47 |
def train_model(x_train, y_train, preprocess, model_name):
|
| 48 |
models = {
|
| 49 |
-
'Decision Tree': DecisionTreeClassifier(
|
| 50 |
-
'Logistic Regression': LogisticRegression(
|
| 51 |
'KNN': KNeighborsClassifier(),
|
| 52 |
-
'Random Forest': RandomForestClassifier(
|
| 53 |
-
'XGBoost': XGBClassifier(
|
| 54 |
}
|
| 55 |
pipeline = Pipeline([
|
| 56 |
('preprocessor', preprocess),
|
|
@@ -69,15 +66,10 @@ with st.sidebar:
|
|
| 69 |
df = load_data()
|
| 70 |
(x_train, x_test, y_train, y_test), preprocess = preprocess_data(df)
|
| 71 |
model = train_model(x_train, y_train, preprocess, model_name)
|
| 72 |
-
|
| 73 |
-
# Evaluate the model
|
| 74 |
-
y_pred = model.predict(x_test)
|
| 75 |
-
report = classification_report(y_test, y_pred, output_dict=True)
|
| 76 |
-
accuracy = report['accuracy']
|
| 77 |
st.session_state['trained_model'] = model
|
| 78 |
st.session_state['x_train'] = x_train
|
| 79 |
st.success(f"Model Trained Successfully! Accuracy: {accuracy:.2f}")
|
| 80 |
-
st.write("Classification Report:", report)
|
| 81 |
|
| 82 |
st.title("🎗️ Cancer Prediction")
|
| 83 |
|
|
|
|
| 10 |
from sklearn.neighbors import KNeighborsClassifier
|
| 11 |
from sklearn.ensemble import RandomForestClassifier
|
| 12 |
from xgboost import XGBClassifier
|
|
|
|
| 13 |
|
| 14 |
# Load dataset
|
| 15 |
def load_data():
|
| 16 |
+
return pd.read_csv('cancer_prediction_data (2).csv')
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Data Preprocessing
|
| 19 |
def preprocess_data(df):
|
|
|
|
| 43 |
# Train Model
|
| 44 |
def train_model(x_train, y_train, preprocess, model_name):
|
| 45 |
models = {
|
| 46 |
+
'Decision Tree': DecisionTreeClassifier(),
|
| 47 |
+
'Logistic Regression': LogisticRegression(),
|
| 48 |
'KNN': KNeighborsClassifier(),
|
| 49 |
+
'Random Forest': RandomForestClassifier(),
|
| 50 |
+
'XGBoost': XGBClassifier()
|
| 51 |
}
|
| 52 |
pipeline = Pipeline([
|
| 53 |
('preprocessor', preprocess),
|
|
|
|
| 66 |
df = load_data()
|
| 67 |
(x_train, x_test, y_train, y_test), preprocess = preprocess_data(df)
|
| 68 |
model = train_model(x_train, y_train, preprocess, model_name)
|
| 69 |
+
accuracy = model.score(x_test, y_test)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
st.session_state['trained_model'] = model
|
| 71 |
st.session_state['x_train'] = x_train
|
| 72 |
st.success(f"Model Trained Successfully! Accuracy: {accuracy:.2f}")
|
|
|
|
| 73 |
|
| 74 |
st.title("🎗️ Cancer Prediction")
|
| 75 |
|