Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +39 -0
- model.pkl +3 -0
- prediction.py +80 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Milestone 2
|
3 |
+
Nama: Qothrunnadaa Alyaa
|
4 |
+
Batch: HCK-009
|
5 |
+
|
6 |
+
File ini digunakan untuk menjalankan home page model prediksi penggunaan kupon diskon
|
7 |
+
"""
|
8 |
+
|
9 |
+
import streamlit as st
|
10 |
+
import eda
|
11 |
+
import prediction
|
12 |
+
|
13 |
+
|
14 |
+
page = st.sidebar.selectbox(label='Pilih menu untuk memulai:', options=['Home Page', 'Exploratory Data Analysis', 'Prediction Model'])
|
15 |
+
|
16 |
+
if page == 'Home Page':
|
17 |
+
st.header('Welcome to Coupon Redemption Predictor!')
|
18 |
+
st.write('')
|
19 |
+
st.subheader('Milestone 2')
|
20 |
+
st.write('Nama : Qothrunnadaa Alyaa')
|
21 |
+
st.write('Batch : HCK-009')
|
22 |
+
st.write('Dataset : Predictng Coupon Redemption')
|
23 |
+
st.write('')
|
24 |
+
st.write('')
|
25 |
+
st.write('')
|
26 |
+
with st.expander('Objektif'):
|
27 |
+
st.caption('Memprediksi apakah seorang pelanggan akan menggunakan kupon untuk medapatkan diskon')
|
28 |
+
|
29 |
+
with st.expander('Problem Statement'):
|
30 |
+
st.caption('Bagaimana cara memprediksi apakah seorang pelanggan akan menggunakan kupon diskon yang tersedia pada suatu transaksi yang dilakukan pelanggan tersebut?')
|
31 |
+
|
32 |
+
with st.expander('Kesimpulan'):
|
33 |
+
st.caption('Untuk memprediksi apakah seorang pelanggan akan menggunakan kupon diskon yang disediakan akan diprediksi menggunakan model Random Forest, di mana model ini dapat memprediksi penggunaan kupon diskon dengan akurasi sekitar 90% (F1 Score).')
|
34 |
+
|
35 |
+
elif page == 'Exploratory Data Analysis':
|
36 |
+
eda.run()
|
37 |
+
|
38 |
+
else:
|
39 |
+
prediction.run()
|
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ae52a921c2ba96b9734ecbf64dba5f126823b15a14507a7b30d9af5fe496feeb
|
3 |
+
size 18981406
|
prediction.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Milestone 2
|
3 |
+
Nama: Qothrunnadaa Alyaa
|
4 |
+
Batch: HCK-009
|
5 |
+
|
6 |
+
File ini digunakan untuk menjalankan home page model prediksi penggunaan kupon diskon
|
7 |
+
"""
|
8 |
+
|
9 |
+
import streamlit as st
|
10 |
+
import pandas as pd
|
11 |
+
import pickle
|
12 |
+
|
13 |
+
# Membuat function untuk dipanggil di app.py
|
14 |
+
def run():
|
15 |
+
st.title('Coupon Redemption Predictor')
|
16 |
+
|
17 |
+
# Memasukkan besaran diskon menggunakan kupon
|
18 |
+
coupon_discount = st.number_input(label='Discount from Coupon', min_value=0.00)
|
19 |
+
|
20 |
+
# Memasukkan lamanya periode promo
|
21 |
+
campaign_length = st.number_input(label='Promo Period (in Days)', min_value=0.00)
|
22 |
+
|
23 |
+
# Memasukkan lamanya periode promo
|
24 |
+
trx_day = st.number_input(label='Transaction Date', min_value=0.00)
|
25 |
+
|
26 |
+
# Memasukkan lamanya periode promo
|
27 |
+
start_day = st.number_input(label='Promotion Start Date', min_value=0.00)
|
28 |
+
|
29 |
+
# Memasukkan lamanya periode promo
|
30 |
+
end_day = st.number_input(label='Promotion End Date', min_value=0.00)
|
31 |
+
|
32 |
+
# Memasukkan lamanya periode promo
|
33 |
+
brand_type = st.selectbox(label='Brand Type', options=['Established','Local'])
|
34 |
+
|
35 |
+
# Memasukkan lamanya periode promo
|
36 |
+
category_opt = ['Dairy, Juices & Snacks','Grocery','Seafood','Prepared Food','Packaged Meat','Meat',
|
37 |
+
'Pharmaceutical','Natural Products','Skin & Hair Care','Flowers & Plants','Garden',
|
38 |
+
'Travel','Miscellaneous','Bakery','Vegetables (cut)','Salads']
|
39 |
+
|
40 |
+
category = st.selectbox(label='Item Category', options=category_opt)
|
41 |
+
|
42 |
+
# Memasukkan lamanya periode promo
|
43 |
+
campaign_type = st.selectbox(label='Campaign Type', options=['Y','X'])
|
44 |
+
|
45 |
+
# Memasukkan lamanya periode promo
|
46 |
+
age_option = ['18-25','26-35','36-45','46-55','56-70','70+']
|
47 |
+
age_range = st.selectbox(label='Customer Age Range', options=age_option)
|
48 |
+
|
49 |
+
# Memasukkan lamanya periode promo
|
50 |
+
income_bracket = st.select_slider(label='Customer Income Bracket',options=[n for n in range(1,13)])
|
51 |
+
|
52 |
+
# Membuat data inference dari data yang dimasukkin
|
53 |
+
data_inf = pd.DataFrame({
|
54 |
+
'coupon_discount': coupon_discount,
|
55 |
+
'campaign_length': campaign_length,
|
56 |
+
'trx_day': trx_day,
|
57 |
+
'start_day': start_day,
|
58 |
+
'end_day': end_day,
|
59 |
+
'brand_type': brand_type,
|
60 |
+
'category': category,
|
61 |
+
'campaign_type': campaign_type,
|
62 |
+
'age_range': age_range,
|
63 |
+
'income_bracket': income_bracket
|
64 |
+
}, index=[0])
|
65 |
+
|
66 |
+
# Menampilkan data
|
67 |
+
st.header("Transaction Overview")
|
68 |
+
st.table(data_inf)
|
69 |
+
|
70 |
+
# Memprediksi apakah nasabah akan mengalami default atau tidak
|
71 |
+
if st.button(label='Predict'):
|
72 |
+
with open('model.pkl','rb') as model:
|
73 |
+
model = pickle.load(model)
|
74 |
+
|
75 |
+
y_pred_inf = model.predict(data_inf)
|
76 |
+
|
77 |
+
if y_pred_inf == 0:
|
78 |
+
st.write('Coupon was not redeemed.')
|
79 |
+
else:
|
80 |
+
st.write('Coupon was redeemed.')
|