import streamlit as st from joblib import load model = load("kmeans_model.pkl") st.title("Customer Segmentation") # inputs Sex = st.selectbox("gender of a customer",options= ["Male","Female"]) Sex=1 if Sex=="Male" else 0 Marital_status = st.selectbox("Marital Status",options= ["Single","Non-single"]) Marital_status=0 if Sex=="Single" else 1 Age = st.number_input("age of the customer",min_value=18,max_value=90) Education = st.selectbox("Education Level of education of the customer", options= ["other / unknown","high school","university","graduate school"]) Education_d={"other / unknown":0,"high school":1,"university":2,"graduate school":3} Education = Education_d[Education] Income = st.number_input("Self-reported annual income in US dollars of the customer",step=100,min_value=30000) Occupation = st.selectbox("occupation of the customer", options= ["unemployed / unskilled","skilled employee","highly qualified employee"]) Occupation_d={"unemployed / unskilled":0,"skilled employee":1,"highly qualified employee":2} Occupation = Occupation_d[Occupation] Settlement_size = st.selectbox("The size of the city that the customer lives in", options= ["small city","mid-sized city","big city"]) Settlement_size_d={"small city":0,"mid-sized city":1,"big city":2} Settlement_size = Settlement_size_d[Settlement_size] values = [Sex,Marital_status, Age,Education,Income,Occupation,Settlement_size] if st.button("Predict"): label = model.predict([values])[0] st.success(f"Customer Belongs to Segment *{label}*")