File size: 3,316 Bytes
a98a45f
14cc1a2
a98a45f
 
 
 
 
 
 
 
 
 
 
 
 
 
14cc1a2
a98a45f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2907dc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Author: Hanife Kaptan
# Versions: python==3.11.2, xgboost==2.1.1, streamlit==1.36.0, scikit-learn==1.4.2, pandas==2.2.3

import pandas as pd
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.pipeline import Pipeline
from xgboost import XGBClassifier 
import streamlit as st

df = pd.read_csv("akcigerKanseri.csv")

X = df.drop("lung_cancer", axis=1)
y = df["lung_cancer"]

preprocess = ColumnTransformer(
    transformers = [("cat", OneHotEncoder(), ["gender"]), ("num", (StandardScaler()), ["age"])], remainder = "passthrough"
)

my_model = XGBClassifier()

pipe = Pipeline(steps=[("preprocessor", preprocess), ("model", my_model)])
pipe.fit(X, y)

def lung_cancer(gender, age, smoking, yellow_fingers, anxiety, peer_pressure,
                chronic_disease, fatigue, allergy, wheezing, alcohol_consuming,
                coughing, shortness_of_breath, swallowing_difficulty, chest_pain):
    input_data = pd.DataFrame({"gender": [gender],
                               "age": [age],
                               "smoking": [smoking],
                               "yellow_fingers": [yellow_fingers],
                               "anxiety": [anxiety],
                               "peer_pressure": [peer_pressure],
                               "chronic_disease": [chronic_disease],
                               "fatigue": [fatigue],
                               "allergy": [allergy],
                               "wheezing": [wheezing],
                               "alcohol_consuming": [alcohol_consuming],
                               "coughing": [coughing],
                               "shortness_of_breath": [shortness_of_breath],
                               "swallowing_difficulty": [swallowing_difficulty],
                               "chest_pain": [chest_pain]})
    prediction = pipe.predict(input_data)[0]
    return prediction

st.title("Akciğer Kanseri Tespiti :hospital:: @hanifekaptan")
st.write("Kendinizle ilgili doğru seçenekleri seçiniz.")
gender = st.radio("Gender", ["Male", "Female"]) # male ve female 1 ve 0 değerlerine dönüştürülecek
age = st.number_input("Age", 0, 100)
smoking = st.radio("Smoking", [True, False])
yellow_fingers = st.radio("Yellow Fingers", [True, False])
anxiety = st.radio("Anxiety", [True, False])
peer_pressure = st.radio("Peer Pressure", [True, False])
chronic_disease = st.radio("Chronic Disease", [True, False])
fatigue = st.radio("Fatigue", [True, False])
allergy = st.radio("Allergy", [True, False])
wheezing = st.radio("Wheezing", [True, False])
alcohol_consuming = st.radio("Alcohol Consuming", [True, False])
coughing = st.radio("Coughing", [True, False])
shortness_of_breath = st.radio("Shortness of Breath", [True, False])
swallowing_difficulty = st.radio("Swallowing Difficulty", [True, False])
chest_pain = st.radio("Chest Pain", [True, False])

if st.button("Predict"):
    pred = lung_cancer(gender, age, smoking, yellow_fingers, anxiety, peer_pressure,
                       chronic_disease, fatigue, allergy, wheezing, alcohol_consuming,
                       coughing, shortness_of_breath, swallowing_difficulty, chest_pain)
    if pred == 1:
        st.write("Result: Positive")
    elif pred == 0:
        st.write("Result: Negative")