| import streamlit as st |
| import joblib |
| import tensorflow as tf |
| import numpy as np |
| import pandas as pd |
| from sklearn.preprocessing import StandardScaler |
|
|
| |
| svm_model = joblib.load('svm_model.pkl') |
| logreg_model = joblib.load('logistic_regression_model.pkl') |
| neural_network_model = tf.keras.models.load_model('neural_network_model.h5') |
|
|
| |
| scaler = joblib.load('scaler.pkl') |
|
|
| |
| def make_prediction(model, data): |
| if model == 'SVM': |
| return svm_model.predict(data) |
|
|
| elif model == 'Logistic Regression': |
| return logreg_model.predict(data) |
| elif model == 'Neural Network': |
| return (neural_network_model.predict(data) > 0.5).astype(int) |
|
|
| |
| st.set_page_config(page_title='Kidney Disease Classification', layout='wide') |
| st.markdown( |
| """ |
| <style> |
| .main { |
| background-color: #f0f8ff; |
| } |
| .header { |
| font-size: 2em; |
| color: #4f4f4f; |
| } |
| .red { |
| color: red; |
| font-weight: bold; |
| } |
| .green { |
| color: green; |
| font-weight: bold; |
| } |
| </style> |
| """, unsafe_allow_html=True |
| ) |
|
|
| st.title('Kidney Disease Classification') |
|
|
| |
| st.sidebar.header('Model Selection') |
| model_choice = st.sidebar.radio('Choose the model for prediction:', |
| ['SVM', 'Logistic Regression', 'Neural Network']) |
|
|
| |
| st.subheader('Input Features') |
|
|
| |
| cols = st.columns(5) |
|
|
| with cols[0]: |
| age = st.number_input('Age', min_value=0, max_value=120, value=30, step=1) |
| with cols[1]: |
| bp = st.number_input('Blood Pressure (BP)', min_value=50, max_value=200, value=80, step=1) |
| with cols[2]: |
| sg = st.number_input('Specific Gravity (SG)', min_value=1.000, max_value=1.050, value=1.020, step=0.001) |
| with cols[3]: |
| al = st.number_input('Albumin (AL)', min_value=0, max_value=5, value=1, step=1) |
| with cols[4]: |
| su = st.number_input('Sugar (SU)', min_value=0, max_value=5, value=0, step=1) |
|
|
| |
| cols = st.columns(5) |
|
|
| with cols[0]: |
| pcc = st.selectbox('Pus Cell Count (PCC)', ['present', 'notpresent']) |
| with cols[1]: |
| ba = st.selectbox('Bacteria (BA)', ['present', 'notpresent']) |
| with cols[2]: |
| bgr = st.number_input('Blood Glucose Random (BGR)', min_value=0, value=120, step=1) |
| with cols[3]: |
| bu = st.number_input('Blood Urea (BU)', min_value=0, value=10, step=1) |
| with cols[4]: |
| sc = st.number_input('Serum Creatinine (SC)', min_value=0.0, value=0.8, step=0.1) |
|
|
| |
| cols = st.columns(5) |
|
|
| with cols[0]: |
| sod = st.number_input('Sodium (SOD)', min_value=0.0, value=135.0, step=0.1) |
| with cols[1]: |
| pot = st.number_input('Potassium (POT)', min_value=0.0, value=4.0, step=0.1) |
| with cols[2]: |
| hemo = st.number_input('Hemoglobin (HEMO)', min_value=0.0, value=15.0, step=0.1) |
| with cols[3]: |
| pcv = st.number_input('Packed Cell Volume (PCV)', min_value=0.0, value=45.0, step=0.1) |
| with cols[4]: |
| wc = st.number_input('White Cell Count (WC)', min_value=0, value=7000, step=1) |
|
|
| |
| cols = st.columns(5) |
|
|
| with cols[0]: |
| rc = st.number_input('Red Cell Count (RC)', min_value=0.0, value=5.0, step=0.1) |
| with cols[1]: |
| htn = st.selectbox('Hypertension (HTN)', ['yes', 'no']) |
| with cols[2]: |
| dm = st.selectbox('Diabetes Mellitus (DM)', ['yes', 'no']) |
| with cols[3]: |
| cad = st.selectbox('Coronary Artery Disease (CAD)', ['yes', 'no']) |
| with cols[4]: |
| appet = st.selectbox('Appetite', ['good', 'poor']) |
|
|
| |
| cols = st.columns(2) |
|
|
| with cols[0]: |
| pe = st.selectbox('Pedal Edema (PE)', ['yes', 'no']) |
| with cols[1]: |
| ane = st.selectbox('Anemia (ANE)', ['yes', 'no']) |
|
|
| |
| categorical_mapping = { |
| 'present': 1, 'notpresent': 0, |
| 'yes': 1, 'no': 0, |
| 'good': 0, 'poor': 1 |
| } |
|
|
| |
| input_data = { |
| 'age': age, |
| 'bp': bp, |
| 'sg': sg, |
| 'al': al, |
| 'su': su, |
| 'pcc': categorical_mapping[pcc], |
| 'ba': categorical_mapping[ba], |
| 'bgr': bgr, |
| 'bu': bu, |
| 'sc': sc, |
| 'sod': sod, |
| 'pot': pot, |
| 'hemo': hemo, |
| 'pcv': pcv, |
| 'wc': wc, |
| 'rc': rc, |
| 'htn': categorical_mapping[htn], |
| 'dm': categorical_mapping[dm], |
| 'cad': categorical_mapping[cad], |
| 'appet': categorical_mapping[appet], |
| 'pe': categorical_mapping[pe], |
| 'ane': categorical_mapping[ane] |
| } |
|
|
| |
| input_df = pd.DataFrame([input_data]) |
|
|
| |
| input_df_scaled = scaler.transform(input_df) |
|
|
| |
| if st.button('Predict'): |
| prediction = make_prediction(model_choice, input_df_scaled) |
| |
| st.subheader('Prediction') |
| if prediction[0] == 1: |
| st.markdown('<p class="green">No Kidney Disease Found</p>', unsafe_allow_html=True) |
| else: |
| st.markdown('<p class="red">Kidney Disease Found</p>', unsafe_allow_html=True) |
|
|