Spaces:
Build error
Build error
Download Lab07.py from chanyaphas/CustomerSegmentationPrediction: direct link, hf CLI and curl.
- Browser
- Download file 2.7 kB
-
https://huggingface.co/spaces/chanyaphas/CustomerSegmentationPrediction/resolve/main/Lab07.py
- Command line
-
hf download hf://spaces/chanyaphas/CustomerSegmentationPrediction/Lab07.py
-
curl -L -o Lab07.py https://huggingface.co/spaces/chanyaphas/CustomerSegmentationPrediction/resolve/main/Lab07.py
2.7 kB
| import joblib | |
| import pandas as pd | |
| import streamlit as st | |
| # โหลดโมเดลและข้อมูลที่จำเป็น | |
| model = joblib.load('model.joblib') | |
| unique_values = joblib.load('unique_values.joblib') | |
| def main(): | |
| st.title("Customer Segmentation Prediction") | |
| # สร้างฟอร์มสำหรับป้อนข้อมูล | |
| with st.form("questionnaire"): | |
| Gender = st.selectbox("Gender", unique_values["Gender"]) | |
| Ever_Married = st.selectbox("Ever Married", unique_values["Ever_Married"]) | |
| Age = st.slider("Age", min_value=18, max_value=89) | |
| Graduated = st.selectbox("Graduated", unique_values["Graduated"]) | |
| Profession = st.selectbox("Profession", unique_values["Profession"]) | |
| Work_Experience = st.slider("Work Experience", min_value=0, max_value=14) | |
| Spending_Score = st.selectbox("Spending Score", unique_values["Spending_Score"]) | |
| Family_Size = st.slider("Family Size", min_value=1, max_value=9) | |
| Var_1 = st.selectbox("Var_1", unique_values["Var_1"]) | |
| ID = st.slider("ID", min_value=458982, max_value=467974) | |
| # สร้างปุ่มสำหรับการทำนาย | |
| clicked = st.form_submit_button("Predict Segmentation") | |
| if clicked: | |
| # ใช้โมเดลทำนาย Segmentation จากข้อมูลที่ป้อน | |
| result = model.predict(pd.DataFrame({"Gender": [Gender], | |
| "Ever_Married": [Ever_Married], | |
| "Age": [Age], | |
| "ID": [ID], | |
| "Graduated": [Graduated], | |
| "Profession": [Pros[Profession]], | |
| "Work_Experience": [Work_Experience], | |
| "Spending_Score": [Spending_Score], | |
| "Family_Size": [Family_Size], | |
| "Var_1": [Var_1] | |
| })) | |
| # แปลงผลลัพธ์ให้เป็นข้อความ | |
| if result[0] == 0: | |
| result = "A" | |
| elif result[0] == 1: | |
| result = "B" | |
| elif result[0] == 2: | |
| result = "C" | |
| else: | |
| result = "D" | |
| # แสดงผลลัพธ์ | |
| st.success('Predicted Segmentation: {}'.format(result)) | |
| if __name__ == '__main__': | |
| main() | |