Evan Derin Ihsanudin commited on
Commit
8f2919f
1 Parent(s): 0af581c

final project ARIA Deployment

Browse files
Files changed (6) hide show
  1. app.py +30 -0
  2. aria_data.xlsx +0 -0
  3. eda.py +67 -0
  4. model_opt.pkl +3 -0
  5. prediction.py +53 -0
  6. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda
3
+ import prediction
4
+
5
+
6
+ # Set Config dan icon
7
+ st.set_page_config(
8
+ page_title='Plant Nutrition Prediction',
9
+ layout='wide',
10
+ )
11
+
12
+ # Hide Streamlit Style
13
+ hide_streamlit_style = """
14
+ <style>
15
+ #MainMenu {visibility: hidden;}
16
+ footer {visibility: hidden;}
17
+ </style>
18
+ """
19
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)
20
+
21
+ # Membuat navigasi
22
+ st.sidebar.markdown("# Evan Derin Ihsanudin - RMT-FTDS-17")
23
+ navigation = st.sidebar.selectbox('Pilih Halaman (Plant Nutrition Prediction/EDA): ', ('Plant Nutrition Prediction','Exploratory Data Analysis'))
24
+ st.sidebar.image("https://imgur.com/FZTgNj9.png", use_column_width=True)
25
+
26
+ # Run modul dengan if else
27
+ if navigation == 'Plant Nutrition Prediction' :
28
+ prediction.run()
29
+ else :
30
+ eda.run()
aria_data.xlsx ADDED
Binary file (19.6 kB). View file
 
eda.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pandas as pd
4
+ import seaborn as sns
5
+ import matplotlib.pyplot as plt
6
+ import plotly.express as px
7
+ from PIL import Image
8
+
9
+
10
+ # Load data dengan pandas dan assign ke variabel df
11
+ df = pd.read_excel('aria_data.xlsx')
12
+
13
+ def run() :
14
+ # Membuat Title
15
+ st.markdown("<h1 style='text-align: center;'>Exploratory Data Analysis</h1>", unsafe_allow_html=True)
16
+ st.write('Berikut adalah EDA dari setiap feature')
17
+
18
+ # Membuat Sub Header
19
+ st.subheader('**Distribution Plot**')
20
+ pilihan = st.selectbox('**Silahkan pilih column :** ',('v1', 'v2', 'v3', 'v4', 'v5', 'v6', 'v7', 'v8', 'target'))
21
+ fig = plt.figure(figsize=(20,10))
22
+ sns.histplot(df[pilihan],bins=30,kde=True)
23
+ title = 'Distribution Plot ' + pilihan
24
+ plt.title(title, fontsize=20)
25
+ plt.xlabel(pilihan, fontsize=14)
26
+ plt.ylabel('Counts', fontsize=14)
27
+ st.pyplot(fig)
28
+
29
+ # Membuat Sub Header
30
+ st.subheader('**Heatmap Correlation**')
31
+ st.write('Berikut Heatmap Correlation antar feature')
32
+ fig = plt.figure(figsize=(15,10))
33
+ sns.heatmap(df.corr(), annot = True, color = 'blue', cmap = 'YlGn')
34
+ st.pyplot(fig)
35
+
36
+ # Membuat Sub Header
37
+ st.subheader('**Distribusi Sample Type**')
38
+ st.write('Berikut visualisasi distribusi sample type dengan barchart dan piechart (persentase)')
39
+ # Visualisasi
40
+ fig, ax =plt.subplots(1,2,figsize=(15,6))
41
+ sns.countplot(x='sample_type', data=df, palette="winter", ax=ax[0])
42
+ ax[0].set_xlabel("Lab", fontsize= 12)
43
+ ax[0].set_ylabel("# of Tested Plant", fontsize= 12)
44
+ fig.suptitle('Count of Tested Plant in each Lab', fontsize=18, fontweight='bold')
45
+ ax[0].set_ylim(0,110)
46
+
47
+ ax[0].set_xticks([0,1], ['Lab 1', 'Lab 2'], fontsize = 11)
48
+ for p in ax[0].patches:
49
+ ax[0].annotate("%.0f"%(p.get_height()), (p.get_x() + p.get_width() / 2,
50
+ p.get_height()+2), ha='center', va='center',fontsize = 11)
51
+ df['sample_type'].value_counts().plot(kind='pie', labels = ['Lab 1','Lab 2'],autopct='%1.1f%%',explode = [0,0.05] ,colors = ['indigo','salmon'],textprops = {"fontsize":12})
52
+ ax[1].set_ylabel("% of Tested Plant", fontsize= 12)
53
+ st.pyplot(fig)
54
+
55
+ # Membuat Sub Header
56
+ st.subheader('**Distribusi Sample Type berdasarkan target**')
57
+ st.write('Dari visualisasi dibawah dapat disimpulkan bahwa :')
58
+ st.markdown('- Lab 1 sering menguji tanaman dengan tingkat nutrisi 4.6 - 4.85')
59
+ st.markdown('- Lab 2 sering menguji tanaman dengan tingkat nutrisi 4.5 - 5')
60
+ # Visualisasi
61
+ fig = plt.figure(figsize=(15,8))
62
+ sns.boxenplot(y=df['target'], x= df['sample_type'], palette = 'Blues')
63
+ plt.title('Sample Type vs Target', fontsize = 15)
64
+ st.pyplot(fig)
65
+
66
+ if __name__ == '__main__':
67
+ run()
model_opt.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f2334774d2ec3527a5f91958f7a6ee29596540751066d07181182ebfeef21b6d
3
+ size 66419
prediction.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import pickle
5
+ import sklearn
6
+
7
+ # Load Model
8
+ with open('model_opt.pkl', 'rb') as file_1:
9
+ model_opt = pickle.load(file_1)
10
+
11
+ def run() :
12
+ # Membuat Title
13
+ st.markdown("<h1 style='text-align: center;'>Plant Nutrition Prediction</h1>", unsafe_allow_html=True)
14
+ st.write('Page ini berisi model untuk prediksi nutrisi tanaman dengan 8 variable dan sample_type. Mohon persiapkan data terlebih dahulu sebelum melakukan prediksi')
15
+
16
+ # Membuat Form
17
+ with st.form(key= 'form_plant'):
18
+ st.markdown('## **Variable**')
19
+ v1 = st.number_input('**V1**', min_value=227.28, max_value= 678.37, value=295.16 ,step=1.,format="%.2f")
20
+ v2 = st.number_input('**V2**', min_value=178.80, max_value= 422.81, value=204.18 ,step=1.,format="%.2f")
21
+ v3 = st.number_input('**V3**', min_value=348.93, max_value= 722.31, value=414.38 ,step=1.,format="%.2f")
22
+ v4 = st.number_input('**V4**', min_value=313.73, max_value= 558.50, value=370.74 ,step=1.,format="%.2f")
23
+ v5 = st.number_input('**V5**', min_value=373.33, max_value= 721.00, value=456.03 ,step=1.,format="%.2f")
24
+ v6 = st.number_input('**V6**', min_value=189.20, max_value= 415.37, value=226.06 ,step=1.,format="%.2f")
25
+ v7 = st.number_input('**V7**', min_value=586.26, max_value= 853.46, value=718.83 ,step=1.,format="%.2f")
26
+ v8 = st.number_input('**V8**', min_value=3725.66, max_value= 5086.37, value=4554.76 ,step=1.,format="%.2f")
27
+ st.markdown('---')
28
+ sample_type = st.selectbox('Sample Type',('lab 1','lab 2'),index=1)
29
+ submitted = st.form_submit_button('Predict')
30
+
31
+ # Membuat Dataframe
32
+ data_inf = {
33
+ 'v1' : v1,
34
+ 'v2' : v2,
35
+ 'v3' : v3,
36
+ 'v4' : v4,
37
+ 'v5' : v5,
38
+ 'v6' : v6,
39
+ 'v7' : v7,
40
+ 'v8' : v8,
41
+ 'sample_type' : sample_type
42
+ }
43
+ data_inf = pd.DataFrame([data_inf])
44
+ data_inf
45
+
46
+ # Prediksi
47
+ if submitted :
48
+ # Predict using Random Forest Parameter Tuning
49
+ y_pred_inf = model_opt.predict(data_inf)
50
+ st.write('# **Plant Nutrition Prediction :** ',y_pred_inf[0])
51
+
52
+ if __name__ == '__main__':
53
+ run()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ seaborn
4
+ matplotlib
5
+ scikit-learn == 1.0.2
6
+ numpy
7
+ plotly