File size: 2,519 Bytes
df624d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b50229
 
 
8cae5d7
9b50229
 
df624d4
9b50229
 
 
 
4c5b0ca
df624d4
 
80f5a36
df624d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c5b0ca
df624d4
 
 
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
import streamlit as st
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import pickle
import json


# Load All Files

with open('gbc_model.pkl', 'rb') as file_1:
  gbc_model = pickle.load(file_1)

with open('scaler.pkl', 'rb') as file_2:
  scaler = pickle.load(file_2)


# bikin fungsi  
def run():

  with st.form(key='patient_condition'):
      anemia = st.selectbox('Anemia', (0, 1), index=1, help= '0 = No, \n 1 = yes')
      diabetes = st.selectbox('Diabetes', (0, 1), index=1, help= '0 = No, \n 1 = yes')
      high_blood_pressure = st.selectbox('High blood pressure', (0, 1), index=1, help= '0 = No, \n 1 = yes')
      serum_sodium = st.slider('Serum Sodium', 100, 150, 120)
      sex = st.selectbox('Sex', (0, 1), index=1, help= '0 = Woman, \n 1 = Man')
      smoking = st.selectbox('Smoking', (0, 1), index=1, help= '0 = No, \n 1 = yes')
      time = st.number_input('Time', min_value=100, max_value=150, value=100)
      binned_age  = st.selectbox('Range of age', (1, 2,3,4), index=1, help= '1 = 40-50, \n 2 = 50-60, \n 3 = 60-70, \n 4 = >70')
      binned_creat_serum = st.selectbox('High serum creatinine', (1, 2), index=1, help= '1 = Normal, \n 2 = High')
      binned_cpk = st.selectbox('CPK Value', (1,2,3), index=1, help= '1 = Normal, \n 2 = Medium, \n 3 =Dangerous')
      binned_ejection = st.selectbox(' Ejection fraction', (1,2,3), index=1, help= '1 = Normal, \n 2 = Attention, \n 3 = Dangerous')
      binned_platelets = st.selectbox('Platelets count', (0, 1, 2), index=1, help='0 = low, \n 1 = normal, \n 2 = high ')
      st.markdown('---')

      submitted = st.form_submit_button('Predict')

  data_inf = {
    'anemia': anemia,
    'diabetes': diabetes,
    'high_blood_pressure' : high_blood_pressure,
    'serum_sodium': serum_sodium,
    'sex': sex,  
    'smoking': smoking,
    'time': time,
    'binned_age': binned_age,
    'binned_creat_serum' : binned_creat_serum,
    'binned_cpk' : binned_cpk,
    'binned_ejection' : binned_ejection,
    'binned_platelets': binned_platelets
  }

  data_inf = pd.DataFrame([data_inf])
  st.dataframe(data_inf)

  if submitted:

   # Feature Scaling and Feature Encoding
      col_headers = list(data_inf.columns.values)
      data_inf_scaled = scaler.transform(data_inf)
      data_inf_df = pd.DataFrame(data_inf_scaled, columns=col_headers) 


      # Predict using gbc
      y_pred_inf = gbc_model.predict(data_inf_df)
      st.write('# Death possibility: ', str(int(y_pred_inf)))
      
if __name__ == '__main__':
    run()