-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
55 lines (48 loc) · 2.38 KB
/
Copy pathapp.py
File metadata and controls
55 lines (48 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import streamlit as st
import pickle
import numpy as np
# Load the churn model
with open("churn_model.pkl", "rb") as file:
model = pickle.load(file)
# Set custom CSS for background
page_bg = """
<style>
.stApp {
background: url("https://source.unsplash.com/random/1600x900") no-repeat center center fixed;
background-size: cover;
}
</style>
"""
st.markdown(page_bg, unsafe_allow_html=True)
# App title
st.title("Customer Churn Prediction App")
# User inputs
st.header("Enter Customer Details")
# Collect all 16 features (Example)
gender = st.selectbox("Gender (0 = Female, 1 = Male)", [0, 1])
senior_citizen = st.selectbox("Senior Citizen (0 = No, 1 = Yes)", [0, 1])
partner = st.selectbox("Has Partner (0 = No, 1 = Yes)", [0, 1])
dependents = st.selectbox("Has Dependents (0 = No, 1 = Yes)", [0, 1])
tenure = st.number_input("Tenure (in months)", min_value=0, max_value=100, step=1)
phone_service = st.selectbox("Phone Service (0 = No, 1 = Yes)", [0, 1])
multiple_lines = st.selectbox("Multiple Lines (0 = No, 1 = Yes)", [0, 1])
internet_service = st.selectbox("Internet Service (0 = DSL, 1 = Fiber, 2 = No)", [0, 1, 2])
online_security = st.selectbox("Online Security (0 = No, 1 = Yes)", [0, 1])
online_backup = st.selectbox("Online Backup (0 = No, 1 = Yes)", [0, 1])
device_protection = st.selectbox("Device Protection (0 = No, 1 = Yes)", [0, 1])
tech_support = st.selectbox("Tech Support (0 = No, 1 = Yes)", [0, 1])
streaming_tv = st.selectbox("Streaming TV (0 = No, 1 = Yes)", [0, 1])
streaming_movies = st.selectbox("Streaming Movies (0 = No, 1 = Yes)", [0, 1])
monthly_charges = st.number_input("Monthly Charges", min_value=0.0, max_value=500.0, step=0.1)
total_charges = st.number_input("Total Charges", min_value=0.0, max_value=10000.0, step=0.1)
# Prepare feature array
features = np.array([[gender, senior_citizen, partner, dependents, tenure, phone_service, multiple_lines,
internet_service, online_security, online_backup, device_protection, tech_support,
streaming_tv, streaming_movies, monthly_charges, total_charges]])
# Make prediction
if st.button("Predict Churn"):
prediction = model.predict(features)
prediction_proba = model.predict_proba(features)[:, 1] # Get churn probability
result = "Churn" if prediction[0] == 1 else "No Churn"
st.subheader(f"Prediction: {result}")
st.write(f"Confidence: {prediction_proba[0] * 100:.2f}%")