|
import streamlit as st |
|
import joblib |
|
import pandas as pd |
|
import pickle |
|
|
|
|
|
|
|
|
|
|
|
|
|
model_path = 'model_rfbest_pipe_rfbest_pipe_rfbest_pipe_rf.pkl' |
|
with open(model_path, 'rb') as file: |
|
model = pickle.load(file) |
|
|
|
|
|
|
|
|
|
st.title("Prediksi Churn Pelanggan") |
|
|
|
|
|
st.subheader("Masukkan Data Pelanggan") |
|
|
|
|
|
gender = st.selectbox('Gender', ['Female', 'Male']) |
|
senior_citizen = st.selectbox('Senior Citizen', [0, 1]) |
|
partner = st.selectbox('Partner', ['Yes', 'No']) |
|
dependents = st.selectbox('Dependents', ['Yes', 'No']) |
|
tenure = st.number_input('Tenure (bulan)', min_value=0, max_value=72, value=45) |
|
phone_service = st.selectbox('Phone Service', ['Yes', 'No']) |
|
multiple_lines = st.selectbox('Multiple Lines', ['Yes', 'No']) |
|
internet_service = st.selectbox('Internet Service', ['DSL', 'Fiber optic', 'No']) |
|
online_security = st.selectbox('Online Security', ['Yes', 'No']) |
|
online_backup = st.selectbox('Online Backup', ['Yes', 'No']) |
|
device_protection = st.selectbox('Device Protection', ['Yes', 'No']) |
|
tech_support = st.selectbox('Tech Support', ['Yes', 'No']) |
|
streaming_tv = st.selectbox('Streaming TV', ['Yes', 'No']) |
|
streaming_movies = st.selectbox('Streaming Movies', ['Yes', 'No']) |
|
contract = st.selectbox('Contract', ['Month-to-month', 'One year', 'Two year']) |
|
paperless_billing = st.selectbox('Paperless Billing', ['Yes', 'No']) |
|
payment_method = st.selectbox('Payment Method', ['Electronic check', 'Mailed check', 'Bank transfer (automatic)', 'Credit card (automatic)']) |
|
monthly_charges = st.number_input('Monthly Charges', min_value=0.0, value=70.35) |
|
total_charges = st.number_input('Total Charges', min_value=0.0, value=346.45) |
|
|
|
|
|
data_baru = { |
|
'gender': [gender], |
|
'SeniorCitizen': [senior_citizen], |
|
'Partner': [partner], |
|
'Dependents': [dependents], |
|
'tenure': [tenure], |
|
'PhoneService': [phone_service], |
|
'MultipleLines': [multiple_lines], |
|
'InternetService': [internet_service], |
|
'OnlineSecurity': [online_security], |
|
'OnlineBackup': [online_backup], |
|
'DeviceProtection': [device_protection], |
|
'TechSupport': [tech_support], |
|
'StreamingTV': [streaming_tv], |
|
'StreamingMovies': [streaming_movies], |
|
'Contract': [contract], |
|
'PaperlessBilling': [paperless_billing], |
|
'PaymentMethod': [payment_method], |
|
'MonthlyCharges': [monthly_charges], |
|
'TotalCharges': [total_charges] |
|
} |
|
|
|
df_baru = pd.DataFrame(data_baru) |
|
|
|
|
|
categorical_columns = df_baru.select_dtypes(include=['object']).columns |
|
df_baru = pd.get_dummies(df_baru, columns=categorical_columns, drop_first=True) |
|
|
|
|
|
st.subheader("Data Pelanggan yang Dimasukkan:") |
|
st.write(df_baru) |
|
|
|
|
|
if st.button('Prediction'): |
|
|
|
prediksi = model.predict(df_baru) |
|
|
|
|
|
if prediksi[0] == 1: |
|
hasil = 'Yes' |
|
else: |
|
hasil = 'No' |
|
|
|
st.subheader(f"Hasil Prediksi Churn: {hasil}") |
|
|
|
|
|
probabilitas = model.predict_proba(df_baru)[:, 1] |
|
st.subheader(f"Probabilitas Churn: {probabilitas[0]:.2f}") |
|
|