File size: 2,100 Bytes
061961e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)
      diabetes = st.selectbox('Diabetes', (0, 1), index=1)
      high_blood_pressure = st.selectbox('High blood pressure', (0, 1), index=1)
      serum_sodium = st.number_input('Serum Sodium', min_value=100, max_value=150, value=100)
      sex = st.selectbox('Sex', (0, 1), index=1)
      smoking = st.selectbox('Sex', (0, 1), index=1)
      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)
      binned_creat_serum = st.selectbox('High serum creatinine', (1, 2), index=1)
      binned_cpk = st.selectbox('CPK Value', (1,2,3), index=1)
      binned_ejection = st.selectbox(' Ejection frraction', (1,2,3), index=1)
      binned_cpk = st.selectbox('CPK Value', (1,2,3), index=1)
      binned_platelets = st.selectbox('Platelets count', (0, 1, 2), index=1)
      st.markdown('---')

      submitted = st.form_submit_button('Predict')

  data_inf = {
    'anemia': 1,
    'diabetes': 1,
    'high_blood_pressure' : 1,
    'serum_sodium': 130,
    'sex': 1,  
    'smoking': 1,
    'time': 150,
    'binned_age': 3,
    'binned_creat_serum' : 2,
    'binned_cpk' : 2,
    'binned_ejection' : 2,
    'binned_platelets': 2
  }

  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('# Rating: ', str(int(y_pred_inf)))
      
if __name__ == '__main__':
    run()