Evan Derin Ihsanudin commited on
Commit
3eed95c
1 Parent(s): e5187e9

Kalbe Deployment

Browse files
Files changed (12) hide show
  1. app.py +33 -0
  2. eda.py +79 -0
  3. kalbe_data.xlsx +0 -0
  4. model_a.pkl +3 -0
  5. model_a1.pkl +3 -0
  6. model_a2.pkl +3 -0
  7. model_b.pkl +3 -0
  8. model_b1.pkl +3 -0
  9. model_b2.pkl +3 -0
  10. prediction_a.py +81 -0
  11. prediction_b.py +81 -0
  12. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda
3
+ import prediction_a
4
+ import prediction_b
5
+
6
+
7
+ # Set Config dan icon
8
+ st.set_page_config(
9
+ page_title='Sales Forecast Prediction',
10
+ layout='wide',
11
+ )
12
+
13
+ # Hide Streamlit Style
14
+ hide_streamlit_style = """
15
+ <style>
16
+ #MainMenu {visibility: hidden;}
17
+ footer {visibility: hidden;}
18
+ </style>
19
+ """
20
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)
21
+
22
+ # Membuat navigasi
23
+ st.sidebar.markdown("# Evan Derin Ihsanudin - RMT-FTDS-17")
24
+ navigation = st.sidebar.selectbox('Pilih Halaman (Forecast Category A/Forecast Category B/EDA): ', ('Forecast Category A','Forecast Category B','Exploratory Data Analysis'))
25
+ st.sidebar.image("https://imgur.com/qJ1Sryt.png", use_column_width=True)
26
+
27
+ # Run modul dengan if else
28
+ if navigation == 'Forecast Category A' :
29
+ prediction_a.run()
30
+ elif navigation == 'Forecast Category B' :
31
+ prediction_b.run()
32
+ else :
33
+ eda.run()
eda.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ xls = pd.ExcelFile('kalbe_data.xlsx')
12
+ df_a1 = pd.read_excel(xls,'A1')
13
+ df_a2 = pd.read_excel(xls,'A2')
14
+ df_b1 = pd.read_excel(xls,'B1')
15
+ df_b2 = pd.read_excel(xls,'B2')
16
+
17
+ # Membuat df kategori A
18
+ df_a = df_a1.copy()
19
+ df_a.rename(columns = {'Sales':'Sales_A1'}, inplace = True)
20
+ # Concat & rename
21
+ df_a = pd.concat([df_a, df_a2['Sales']], axis=1)
22
+ df_a.rename(columns = {'Sales':'Sales_A2'}, inplace = True)
23
+ df_a.replace(np.nan, 0, inplace=True)
24
+ # Menghitung total sales kategori A
25
+ df_a['sales_total'] = df_a['Sales_A1'] + df_a['Sales_A2']
26
+ # Membuat df kategori B
27
+ df_b = df_b1.copy()
28
+ df_b.rename(columns = {'Sales':'Sales_B1'}, inplace = True)
29
+ # Concat & rename
30
+ df_b = pd.concat([df_b, df_b2['Sales']], axis=1)
31
+ df_b.rename(columns = {'Sales':'Sales_B2'}, inplace = True)
32
+ df_b.replace(np.nan, 0, inplace=True)
33
+ # Menghitung total sales kategori B
34
+ df_b['sales_total'] = df_b['Sales_B1'] + df_b['Sales_B2']
35
+
36
+
37
+ def run() :
38
+ # Membuat Title
39
+ st.markdown("<h1 style='text-align: center;'>Exploratory Data Analysis</h1>", unsafe_allow_html=True)
40
+ st.write('Berikut adalah EDA dari setiap feature')
41
+
42
+ # Membuat Sub Header
43
+ st.subheader('**Trend Category A**')
44
+ fig = px.line(df_a, x=df_a.Day, y=df_a.sales_total)
45
+ fig.update_layout(xaxis_title="Day", yaxis_title="Actual Sales")
46
+ st.plotly_chart(fig)
47
+
48
+ # Membuat Sub Header
49
+ st.subheader('**Trend Category B**')
50
+ fig = px.line(df_b, x=df_b.Day, y=df_b.sales_total)
51
+ fig.update_layout(xaxis_title="Day", yaxis_title="Actual Sales")
52
+ st.plotly_chart(fig)
53
+
54
+ # Membuat Sub Header
55
+ st.subheader('**Trend Product A1**')
56
+ fig = px.line(df_a1, x=df_a1.Day, y=df_a1.Sales)
57
+ fig.update_layout(xaxis_title="Day", yaxis_title="Actual Sales")
58
+ st.plotly_chart(fig)
59
+
60
+ # Membuat Sub Header
61
+ st.subheader('**Trend Product A2**')
62
+ fig = px.line(df_a2, x=df_a2.Day, y=df_a2.Sales)
63
+ fig.update_layout(xaxis_title="Day", yaxis_title="Actual Sales")
64
+ st.plotly_chart(fig)
65
+
66
+ # Membuat Sub Header
67
+ st.subheader('**Trend Product B1**')
68
+ fig = px.line(df_b1, x=df_b1.Day, y=df_b1.Sales)
69
+ fig.update_layout(xaxis_title="Day", yaxis_title="Actual Sales")
70
+ st.plotly_chart(fig)
71
+
72
+ # Membuat Sub Header
73
+ st.subheader('**Trend Product B2**')
74
+ fig = px.line(df_b2, x=df_b2.Day, y=df_b2.Sales)
75
+ fig.update_layout(xaxis_title="Day", yaxis_title="Actual Sales")
76
+ st.plotly_chart(fig)
77
+
78
+ if __name__ == '__main__':
79
+ run()
kalbe_data.xlsx ADDED
Binary file (39.5 kB). View file
 
model_a.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:54e045da3cf1e2fb26e1bc6c243e17a944d5785a38654d431253e97108ed5980
3
+ size 851642
model_a1.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7bc2df4fb5ecb1b09f4e6811579e94aa48d9abaa3857d8345986bcb15100ed8e
3
+ size 1768541
model_a2.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bcdfb46e3d634ca36ad061725dc370c74ee67f182dabf05444fc87f4daf74a84
3
+ size 1766783
model_b.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f52420d72418244517acb237c9c50d6ab292bbccf6ad95b258eae13b5cda4c0c
3
+ size 1516101
model_b1.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ab4afde91bcf88f24198f02648afb29a13893cf6d5722483b16f0b150ba29c4b
3
+ size 9872
model_b2.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ab4afde91bcf88f24198f02648afb29a13893cf6d5722483b16f0b150ba29c4b
3
+ size 9872
prediction_a.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import pickle
5
+ import matplotlib.pyplot as plt
6
+ import plotly.express as px
7
+
8
+ # Load Model Kategori A
9
+ with open('model_a.pkl', 'rb') as file_1:
10
+ model_a = pickle.load(file_1)
11
+
12
+ # Load Model Produk A1
13
+ with open('model_a1.pkl', 'rb') as file_3:
14
+ model_a1 = pickle.load(file_3)
15
+
16
+ # Load Model Produk A2
17
+ with open('model_a2.pkl', 'rb') as file_4:
18
+ model_a2 = pickle.load(file_4)
19
+
20
+ def run() :
21
+ st.markdown("<h1 style='text-align: center;'>Category A Sales Prediction</h1>", unsafe_allow_html=True)
22
+ st.write('Page ini berisi model untuk prediksi sales Category A, Product A1 & Product A2')
23
+
24
+ with st.form(key= 'form_a'):
25
+ st.markdown('##### **Forecast Sales Category A**')
26
+ input_a = st.number_input('Periode', min_value=0, max_value=90, value=5 ,step=1)
27
+ st.write('###### **Mean Absolute Error :** ', 3.69)
28
+ submitted_a = st.form_submit_button('Predict')
29
+
30
+ if submitted_a :
31
+ # Prediction
32
+ result_a = model_a.forecast(input_a)
33
+ result_a = pd.DataFrame(result_a)
34
+
35
+ # Visualisasi
36
+ fig = px.line(result_a, x=result_a.index, y=result_a.predicted_mean, title='Prediction Category A')
37
+ fig.update_layout(xaxis_title="Days", yaxis_title="Prediction")
38
+ fig.update_traces(line_color='red')
39
+ st.plotly_chart(fig)
40
+ st.write('**Prediction Category A :** ', result_a)
41
+
42
+ with st.form(key= 'form_a1'):
43
+ st.markdown('##### **Forecast Sales Product A1**')
44
+ input_a1 = st.number_input('Periode', min_value=0, max_value=90, value=5 ,step=1)
45
+ st.write('###### **Mean Absolute Error :** ', 7.4)
46
+ submitted_a1 = st.form_submit_button('Predict')
47
+
48
+ if submitted_a1 :
49
+ # Prediction
50
+ result_a1 = model_a1.forecast(input_a1)
51
+ result_a1 = pd.DataFrame(result_a1)
52
+
53
+ # Visualisasi
54
+ fig = px.line(result_a1, x=result_a1.index, y=result_a1.predicted_mean, title='Prediction Product A1')
55
+ fig.update_layout(xaxis_title="Days", yaxis_title="Prediction")
56
+ fig.update_traces(line_color='red')
57
+ st.plotly_chart(fig)
58
+ st.write('**Prediction Product A1 :** ', result_a1)
59
+
60
+ with st.form(key= 'form_a2'):
61
+ st.markdown('##### **Forecast Sales Product A2**')
62
+ input_a2 = st.number_input('Periode', min_value=0, max_value=90, value=5 ,step=1)
63
+ st.write('###### **Mean Absolute Error :** ', 1.73)
64
+ submitted_a2 = st.form_submit_button('Predict')
65
+
66
+ if submitted_a2 :
67
+ # Prediction
68
+ result_a2 = model_a2.forecast(input_a2)
69
+ result_a2 = pd.DataFrame(result_a2)
70
+
71
+ # Visualisasi
72
+ fig = px.line(result_a2, x=result_a2.index, y=result_a2.predicted_mean, title='Prediction Product A2')
73
+ fig.update_layout(xaxis_title="Days", yaxis_title="Prediction")
74
+ fig.update_traces(line_color='red')
75
+ st.plotly_chart(fig)
76
+ st.write('**Prediction Product A2 :** ', result_a2)
77
+
78
+
79
+ if __name__ == '__main__':
80
+ run()
81
+
prediction_b.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import pickle
5
+ import matplotlib.pyplot as plt
6
+ import plotly.express as px
7
+
8
+ # Load Model Kategori B
9
+ with open('model_b.pkl', 'rb') as file_2:
10
+ model_b = pickle.load(file_2)
11
+
12
+ # Load Model Produk B1
13
+ with open('model_b1.pkl', 'rb') as file_5:
14
+ model_b1 = pickle.load(file_5)
15
+
16
+ # Load Model Produk B2
17
+ with open('model_b2.pkl', 'rb') as file_6:
18
+ model_b2 = pickle.load(file_6)
19
+
20
+ def run() :
21
+ st.markdown("<h1 style='text-align: center;'>Category B Sales Prediction</h1>", unsafe_allow_html=True)
22
+ st.write('Page ini berisi model untuk prediksi sales Category B, Product B1 & Product B2')
23
+
24
+ with st.form(key= 'form_b'):
25
+ st.markdown('##### **Forecast Sales Category B**')
26
+ input_b = st.number_input('Periode', min_value=0, max_value=90, value=5 ,step=1)
27
+ st.write('###### **Mean Absolute Error :** ', 194.48)
28
+ submitted_b = st.form_submit_button('Predict')
29
+
30
+ if submitted_b :
31
+ # Prediction
32
+ result_b = model_b.forecast(input_b)
33
+ result_b = pd.DataFrame(result_b)
34
+
35
+ # Visualisasi
36
+ fig = px.line(result_b, x=result_b.index, y=result_b.predicted_mean, title='Prediction Category B')
37
+ fig.update_layout(xaxis_title="Days", yaxis_title="Prediction")
38
+ fig.update_traces(line_color='red')
39
+ st.plotly_chart(fig)
40
+ st.write('**Prediction Category B :** ', result_b)
41
+
42
+ with st.form(key= 'form_b1'):
43
+ st.markdown('##### **Forecast Sales Product B1**')
44
+ input_b1 = st.number_input('Periode', min_value=0, max_value=90, value=5 ,step=1)
45
+ st.write('###### **Mean Absolute Error :** ', 120.9)
46
+ submitted_b1 = st.form_submit_button('Predict')
47
+
48
+ if submitted_b1 :
49
+ # Prediction
50
+ result_b1 = model_b1.forecast(input_b1)
51
+ result_b1 = pd.DataFrame(result_b1, columns=['predicted_mean'])
52
+
53
+ # Visualisasi
54
+ fig = px.line(result_b1, x=result_b1.index, y= result_b1.predicted_mean, title='Prediction Product B1')
55
+ fig.update_layout(xaxis_title="Days", yaxis_title="Prediction")
56
+ fig.update_traces(line_color='red')
57
+ st.plotly_chart(fig)
58
+ st.write('**Prediction Product B1 :** ', result_b1)
59
+
60
+ with st.form(key= 'form_b2'):
61
+ st.markdown('##### **Forecast Sales Product B2**')
62
+ input_b2 = st.number_input('Periode', min_value=0, max_value=90, value=5 ,step=1)
63
+ st.write('###### **Mean Absolute Error :** ', 118.66)
64
+ submitted_b2 = st.form_submit_button('Predict')
65
+
66
+ if submitted_b2 :
67
+ # Prediction
68
+ result_b2 = model_b2.forecast(input_b2)
69
+ result_b2 = pd.DataFrame(result_b2, columns=['predicted_mean'])
70
+
71
+ # Visualisasi
72
+ fig = px.line(result_b2, x=result_b2.index, y=result_b2.predicted_mean, title='Prediction Product B2')
73
+ fig.update_layout(xaxis_title="Days", yaxis_title="Prediction")
74
+ fig.update_traces(line_color='red')
75
+ st.plotly_chart(fig)
76
+ st.write('**Prediction Product B2 :** ', result_b2)
77
+
78
+
79
+ if __name__ == '__main__':
80
+ run()
81
+
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