Spaces:
Sleeping
Sleeping
ibrahim yıldız
commited on
Upload 5 files
Browse files- Unknown-2.png +0 -0
- Unknown.png +0 -0
- app.py +118 -0
- google_store.jpg +0 -0
- lightgbm_model.txt +0 -0
Unknown-2.png
ADDED
|
Unknown.png
ADDED
|
app.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import lightgbm as lgb
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
|
| 7 |
+
# Load the trained model
|
| 8 |
+
model = lgb.Booster(model_file='lightgbm_model.txt')
|
| 9 |
+
|
| 10 |
+
# Function to convert date to timestamp
|
| 11 |
+
def date_to_timestamp(date):
|
| 12 |
+
return datetime(date.year, date.month, date.day).timestamp()
|
| 13 |
+
|
| 14 |
+
# Function to create the input dataframe
|
| 15 |
+
def create_input_df(date, visitNumber, totals_visits, totals_hits, totals_pageviews, totals_newVisits,
|
| 16 |
+
channelGrouping, device_browser, device_operatingSystem, device_deviceCategory,
|
| 17 |
+
geoNetwork_subContinent, trafficSource_source, trafficSource_medium):
|
| 18 |
+
data = {
|
| 19 |
+
'date': [date_to_timestamp(date)],
|
| 20 |
+
'visitNumber': [visitNumber],
|
| 21 |
+
'totals_visits': [totals_visits],
|
| 22 |
+
'totals_hits': [totals_hits],
|
| 23 |
+
'totals_pageviews': [totals_pageviews],
|
| 24 |
+
'totals_newVisits': [totals_newVisits],
|
| 25 |
+
f'channelGrouping_{channelGrouping}': [1],
|
| 26 |
+
f'device_browser_{device_browser}': [1],
|
| 27 |
+
f'device_operatingSystem_{device_operatingSystem}': [1],
|
| 28 |
+
f'device_deviceCategory_{device_deviceCategory}': [1],
|
| 29 |
+
f'geoNetwork_subContinent_{geoNetwork_subContinent}': [1],
|
| 30 |
+
f'trafficSource_source_{trafficSource_source}': [1],
|
| 31 |
+
f'trafficSource_medium_{trafficSource_medium}': [1],
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
# Create the dataframe
|
| 35 |
+
input_df = pd.DataFrame(data)
|
| 36 |
+
|
| 37 |
+
# Fill missing columns with 0
|
| 38 |
+
expected_columns = [
|
| 39 |
+
'date', 'visitNumber', 'totals_visits', 'totals_hits', 'totals_pageviews', 'totals_newVisits',
|
| 40 |
+
'channelGrouping_Direct', 'channelGrouping_Organic Search', 'channelGrouping_Paid Search',
|
| 41 |
+
'channelGrouping_Referral', 'channelGrouping_Social',
|
| 42 |
+
'device_browser_Android Webview', 'device_browser_Chrome', 'device_browser_Firefox',
|
| 43 |
+
'device_browser_Internet Explorer', 'device_browser_Safari',
|
| 44 |
+
'device_operatingSystem_Android', 'device_operatingSystem_Chrome OS', 'device_operatingSystem_Linux',
|
| 45 |
+
'device_operatingSystem_Macintosh', 'device_operatingSystem_Windows', 'device_operatingSystem_iOS',
|
| 46 |
+
'device_deviceCategory_desktop', 'device_deviceCategory_mobile', 'device_deviceCategory_tablet',
|
| 47 |
+
'geoNetwork_subContinent_Eastern Asia', 'geoNetwork_subContinent_Eastern Europe',
|
| 48 |
+
'geoNetwork_subContinent_Northern America', 'geoNetwork_subContinent_Northern Europe',
|
| 49 |
+
'geoNetwork_subContinent_South America', 'geoNetwork_subContinent_Southeast Asia',
|
| 50 |
+
'geoNetwork_subContinent_Southern Asia', 'geoNetwork_subContinent_Southern Europe',
|
| 51 |
+
'geoNetwork_subContinent_Western Asia', 'geoNetwork_subContinent_Western Europe',
|
| 52 |
+
'trafficSource_source_(direct)', 'trafficSource_source_google', 'trafficSource_source_mall.googleplex.com',
|
| 53 |
+
'trafficSource_source_youtube.com', 'trafficSource_medium_(none)', 'trafficSource_medium_affiliate',
|
| 54 |
+
'trafficSource_medium_cpc', 'trafficSource_medium_organic', 'trafficSource_medium_referral'
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
for col in expected_columns:
|
| 58 |
+
if col not in input_df.columns:
|
| 59 |
+
input_df[col] = 0
|
| 60 |
+
|
| 61 |
+
return input_df[expected_columns]
|
| 62 |
+
|
| 63 |
+
# Streamlit app
|
| 64 |
+
st.title('GStore Digital Sales Revenue Prediction 🪝')
|
| 65 |
+
st.image('google_store.jpg')
|
| 66 |
+
st.write('Google shared some digital marketing data for their store. This app calculates whether a customer profile will turn into a sale or not.')
|
| 67 |
+
|
| 68 |
+
st.write('High Page visits and site views, using Chrome OS, using mall.googleplex.com, located in North America are all have increased revenue possibility')
|
| 69 |
+
|
| 70 |
+
# Collect user inputs
|
| 71 |
+
date = st.date_input('Date')
|
| 72 |
+
visitNumber = st.number_input('Visit Number', min_value=1)
|
| 73 |
+
totals_visits = st.number_input('Total Visits', min_value=1)
|
| 74 |
+
totals_hits = st.number_input('Total Hits', min_value=1)
|
| 75 |
+
totals_pageviews = st.number_input('Total Pageviews', min_value=1)
|
| 76 |
+
totals_newVisits = st.number_input('Total New Visits', min_value=0)
|
| 77 |
+
|
| 78 |
+
channelGrouping = st.selectbox('Channel Grouping',
|
| 79 |
+
['Direct', 'Organic Search', 'Paid Search', 'Referral', 'Social'])
|
| 80 |
+
device_browser = st.selectbox('Device Browser',
|
| 81 |
+
['Android Webview', 'Chrome', 'Firefox', 'Internet Explorer', 'Safari'])
|
| 82 |
+
device_operatingSystem = st.selectbox('Device Operating System',
|
| 83 |
+
['Android', 'Chrome OS', 'Linux', 'Macintosh', 'Windows', 'iOS'])
|
| 84 |
+
device_deviceCategory = st.selectbox('Device Category', ['desktop', 'mobile', 'tablet'])
|
| 85 |
+
geoNetwork_subContinent = st.selectbox('GeoNetwork Sub Continent',
|
| 86 |
+
['Eastern Asia', 'Eastern Europe', 'Northern America', 'Northern Europe',
|
| 87 |
+
'South America', 'Southeast Asia', 'Southern Asia', 'Southern Europe',
|
| 88 |
+
'Western Asia', 'Western Europe'])
|
| 89 |
+
trafficSource_source = st.selectbox('Traffic Source', ['(direct)', 'google', 'mall.googleplex.com', 'youtube.com'])
|
| 90 |
+
trafficSource_medium = st.selectbox('Traffic Source Medium', ['(none)', 'affiliate', 'cpc', 'organic', 'referral'])
|
| 91 |
+
|
| 92 |
+
# Create input dataframe
|
| 93 |
+
input_df = create_input_df(date, visitNumber, totals_visits, totals_hits, totals_pageviews, totals_newVisits,
|
| 94 |
+
channelGrouping, device_browser, device_operatingSystem, device_deviceCategory,
|
| 95 |
+
geoNetwork_subContinent, trafficSource_source, trafficSource_medium)
|
| 96 |
+
|
| 97 |
+
# Make prediction
|
| 98 |
+
prediction = model.predict(input_df)
|
| 99 |
+
|
| 100 |
+
# Display the prediction result
|
| 101 |
+
if prediction[0] < 0:
|
| 102 |
+
st.header("The user is not likely to buy.")
|
| 103 |
+
elif prediction[0] < 0.001:
|
| 104 |
+
st.header("The user is not likely to buy.")
|
| 105 |
+
elif prediction[0] < 0.02:
|
| 106 |
+
predicted_value = prediction[0] * 5000
|
| 107 |
+
st.header(f"The user might buy. Predicted Revenue: ${int(predicted_value)}")
|
| 108 |
+
else:
|
| 109 |
+
predicted_value = prediction[0] * 2500
|
| 110 |
+
st.header(f"The user is highly likely to buy. Predicted Revenue: ${int(predicted_value)}")
|
| 111 |
+
|
| 112 |
+
st.write('These are some graphs about the 900K rows of data. 1.3% of site visitors turn into customers')
|
| 113 |
+
st.image('Unknown-1.png')
|
| 114 |
+
st.write('The high spenders are what keeps the wheel going')
|
| 115 |
+
st.image('Unknown.png')
|
| 116 |
+
st.write('The visits and sales are quite corraleted and seasonal.')
|
| 117 |
+
st.image('Unknown-2.png')
|
| 118 |
+
|
google_store.jpg
ADDED
|
lightgbm_model.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|