grcvlrn/Ecorse_Final_Project
0
1# Import all the libraries that are going to be used2import streamlit as st3import pandas as pd4import pickle5 6# Create a 7def run():8 # Load the file that will be used to predict the cluster9 with open('pipeline.pkl', 'rb') as file:10 pipeline = pickle.load(file)11 12 # Create the input for each label to find the cluster13 order_id = st.number_input(label='Input Order ID!', min_value=000001.0, max_value=999999.0)14 product_category = st.selectbox(label='Choose Product Category!', options=['Laptops and Computers', 'Home Appliances', 'Charging Cables', 'Monitors', 'Batterie', 'Audio Devices', 'Phones and Accessories', 'Entertainment Devices'])15 product = st.selectbox(label='Choose Product!', options=['Macbook Pro Laptop', 'LG Washing Machine', 'USB-C Charging Cable', '27in FHD Monitor', 'AA Batteries (4-pack)', 'Bose SoundSport Headphones', 'AAA Batteries (4-pack)', 'ThinkPad Laptop', 'Lightning Charging Cable', 'Google Phone', 'Wired Headphones', 'Apple Airpods Headphones', 'Vareebadd Phone', 'iPhone', '20in Monitor', '34in Ultrawide Monitor', 'Flatscreen TV', '27in 4K Gaming Monitor', 'LG Dryer'])16 quantity_ordered = st.number_input(label='Input Quantity Ordered!', min_value=1.0, max_value=30.0)17 price_each = st.number_input(label='Input Price Each Ordered Item!', min_value=1.0, max_value=5000.0)18 order_date = st.date_input("When's the Order Date?", value=None) 19 purchase_address = st.text_input("Enter Purchase Address!", "")20 month = st.selectbox(label='What Month is the Order Made in?', options=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])21 sales = st.number_input(label='Input Amount of Sales!', min_value=1.0, max_value=510000.0)22 city = st.selectbox(label='In Which City Was the Order Made?', options=[' New York City', ' San Francisco', ' Atlanta', ' Portland', ' Dallas', ' Los Angeles', ' Boston', ' Austin', ' Seattle'])23 hour = st.selectbox(label='In Which Hour Was the Order Made?', options=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ,24])24 time_of_day = st.selectbox(label='Which Time of Day Was the Order Made?', options=['Night', 'Morning', 'Evening', 'Afternoon'])25 26 # Telling user the next part27 st.write('The following is the result:')28 29 # Labeling the inputs as the data inference to be clustered30 data_inf = pd.DataFrame({31 'order_id': [order_id],32 'product_category': [product_category],33 'product': [product],34 'quantity_ordered': [quantity_ordered],35 'price_each': [price_each],36 'order_date': [order_date],37 'purchase_address': [purchase_address],38 'month': [month],39 'sales': [sales],40 'city': [city],41 'hour': [hour],42 'time_of_day': [time_of_day]43 })44 45 # Putting the data inference as a label46 st.table(data_inf)47 48 # Make a button that will show the cluster49 if st.button(label='Cluster'):50 # Data Dummy prediction51 cluster = pipeline.predict(data_inf)52 st.metric(label="Here is the Cluster:", value=cluster[0])53 54 product0 = '''USB-C Charging Cable 55 Lightning Charging Cable 56 AAA Batteries (4-pack) 57 AA Batteries (4-pack) 58 Wired Headphones59 '''60 61 product1 = '''Macbook Pro Laptop 62 LG Washing Machine 63 27in FHD Monitor 64 ThinkPad Laptop 65 Apple Airpods Headphones66 '''67 68 if cluster[0] == 0:69 st.write("Cluster 0 adalah customer yang melakukan pembelian pada waktu tengah malam hingga menjelang sore atau sebelum jam 15:00. Kemungkinan adalah cluster ini untuk para customer yang memiliki urgensi membeli barang elektronik yang dibutuhkan disaat sudah tidak memiliki persediaan cadangan dan customer pada cluster ini memiliki lebih banyak waktu luang untuk membeli barang elektronik.")70 st.write(f"##### Recommended products: ")71 st.markdown(product0)72 else:73 st.write("Cluster 1 adalah customer yang melakukan pembelian pada waktu sore hari hingga menjelang tengah malam, atau pada jam 15:00 hingga mendekati jam 00:00. Kemungkinan customer pada cluster ini adalah customer yang sibuk bekerja di luar rumah, karena jam pembelian cluster ini dapat disimpulkan berada pada jam luar kantor. Jadi kemungkinan adalah customer pada cluster ini biasanya melakukan pembelian berbarengan dengan pulang kantor.")74 st.write(f"##### Recommended products: ")75 st.markdown(product0)76 77# Running the function78if __name__ == "__main__":79 run()