Waze_User_Churn / app.py
Parthebhan's picture
Update app.py
44beeb5 verified
raw
history blame
4.2 kB
import pickle
import gradio as gr
# Load the pickled model
with open('./xgb_waze.pickle' , 'rb') as file:
model = pickle.load(file)
# Define the function for making predictions
def salifort(sessions, drives, total_sessions, n_days_after_onboarding, total_navigations_fav1, total_navigations_fav2, driven_km_drives, duration_minutes_drives, activity_days, driving_days, km_per_driving_day, percent_sessions_in_last_month, professional_driver, total_sessions_per_day, km_per_hour, km_per_drive, percent_of_drives_to_favorite, device2):
inputs = [['sessions', 'drives', 'total_sessions', 'n_days_after_onboarding',
'total_navigations_fav1', 'total_navigations_fav2', 'driven_km_drives',
'duration_minutes_drives', 'activity_days', 'driving_days',
'km_per_driving_day', 'percent_sessions_in_last_month',
'professional_driver', 'total_sessions_per_day', 'km_per_hour',
'km_per_drive', 'percent_of_drives_to_favorite', 'device2']]
prediction = model.predict(inputs)
prediction_value = prediction[0]
if prediction_value == 0:
label_text = 'User Retained 🟒'
else:
label_text = 'User Churned πŸ”΄'
return label_text
# Create the Gradio interface
salifort_ga = gr.Interface(fn=salifort,
inputs = [
gr.Number(0, 743, label="sessions: [0 to 743]"),
gr.Number(0, 596, label="drives: [0 to 596]"),
gr.Number(0, 1216, label="total_sessions: [0 to 1216]"),
gr.Number(4, 3500, label="n_days_after_onboarding: [4 to 3500]"),
gr.Number(0, 1236, label="total_navigations_fav1: [0 to 1236]"),
gr.Number(0, 415, label="total_navigations_fav2: [0 to 415]"),
gr.Number(60, 21183, label="driven_km_drives: [60 to 21183]"),
gr.Number(18, 15852, label="duration_minutes_drives: [18 to 15852]"),
gr.Number(0, 31, label="activity_days: [0 to 31]"),
gr.Number(0, 30, label="driving_days: [0 to 30]"),
gr.Number(0, 15420, label="km_per_driving_day: [0 to 15420]"),
gr.Number(0, 1.5, label="percent_sessions_in_last_month: [0 to 1.5]"),
gr.Number(0, 1, label="professional_driver: [0 to 1]"),
gr.Number(0, 39, label="total_sessions_per_day: [0 to 39]"),
gr.Number(72, 23642, label="km_per_hour: [72 to 23642]"),
gr.Number(0, 15777, label="km_per_drive: [0 to 15777]"),
gr.Number(0, 777, label="percent_of_drives_to_favorite: [0 to 777]"),
gr.Number(0, 1, label="device2: [0 to 1]"),
],
outputs = "text", title="Data-driven suggestions for Waze - User Churn",
examples = [
[30, 30, 207, 2239, 11, 12, 3919, 2182, 26, 25, 157, 0, 0, 0, 108, 131, 0, 0],
[47, 40, 144, 36, 353, 0, 10764, 4617, 18, 17, 633, 0, 0, 4, 140, 269, 2, 0],
[75, 61, 87, 2825, 67, 94, 243, 183, 2, 0, 0, 1, 0, 0, 80, 4, 2, 0, 0, 0],
[0, 0, 291, 1589, 447, 110, 1574, 1163, 17, 16, 98, 0, 0, 0, 81, 0, 2, 1, 0],
[56, 45, 82, 701, 80, 32, 1515, 691, 20, 15, 101, 1, 0, 0, 132, 34, 1, 0, 0]
],
description="User Churn Prediction Using Machine Learning",
theme='dark'
)
salifort_ga.launch(share=True)