chanyaphas commited on
Commit
d40b8b9
·
1 Parent(s): d17c163

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -2,14 +2,20 @@ import joblib
2
  import pandas as pd
3
  import streamlit as st
4
 
5
- # โหลดโมเดลและข้อมูลที่จำเป็น
 
 
 
 
 
 
 
 
6
  model = joblib.load('model.joblib')
7
  unique_values = joblib.load('unique_values.joblib')
8
 
9
  def main():
10
  st.title("Customer Segmentation Prediction")
11
-
12
- # สร้างฟอร์มสำหรับป้อนข้อมูล
13
  with st.form("questionnaire"):
14
  Gender = st.selectbox("Gender", unique_values["Gender"])
15
  Ever_Married = st.selectbox("Ever Married", unique_values["Ever_Married"])
@@ -22,10 +28,8 @@ def main():
22
  Var_1 = st.selectbox("Var_1", unique_values["Var_1"])
23
  ID = st.slider("ID", min_value=458982, max_value=467974)
24
 
25
- # สร้างปุ่มสำหรับการทำนาย
26
  clicked = st.form_submit_button("Predict Segmentation")
27
  if clicked:
28
- # ใช้โมเดลทำนาย Segmentation จากข้อมูลที่ป้อน
29
  result = model.predict(pd.DataFrame({"Gender": [Gender],
30
  "Ever_Married": [Ever_Married],
31
  "Age": [Age],
@@ -37,7 +41,6 @@ def main():
37
  "Family_Size": [Family_Size],
38
  "Var_1": [Var_1]
39
  }))
40
- # แปลงผลลัพธ์ให้เป็นข้อความ
41
  if result[0] == 0:
42
  result = "A"
43
  elif result[0] == 1:
@@ -46,7 +49,6 @@ def main():
46
  result = "C"
47
  else:
48
  result = "D"
49
- # แสดงผลลัพธ์
50
  st.success('Predicted Segmentation: {}'.format(result))
51
 
52
  if __name__ == '__main__':
 
2
  import pandas as pd
3
  import streamlit as st
4
 
5
+ Pros= {'Engineer': 1,
6
+ 'Healthcare': 2,
7
+ 'Executive': 3,
8
+ 'Doctor': 4,
9
+ 'Artist': 5,
10
+ 'Lawyer': 6,
11
+ 'Entertainment': 7,
12
+ 'Homemaker': 8,
13
+ 'Marketing': 9}
14
  model = joblib.load('model.joblib')
15
  unique_values = joblib.load('unique_values.joblib')
16
 
17
  def main():
18
  st.title("Customer Segmentation Prediction")
 
 
19
  with st.form("questionnaire"):
20
  Gender = st.selectbox("Gender", unique_values["Gender"])
21
  Ever_Married = st.selectbox("Ever Married", unique_values["Ever_Married"])
 
28
  Var_1 = st.selectbox("Var_1", unique_values["Var_1"])
29
  ID = st.slider("ID", min_value=458982, max_value=467974)
30
 
 
31
  clicked = st.form_submit_button("Predict Segmentation")
32
  if clicked:
 
33
  result = model.predict(pd.DataFrame({"Gender": [Gender],
34
  "Ever_Married": [Ever_Married],
35
  "Age": [Age],
 
41
  "Family_Size": [Family_Size],
42
  "Var_1": [Var_1]
43
  }))
 
44
  if result[0] == 0:
45
  result = "A"
46
  elif result[0] == 1:
 
49
  result = "C"
50
  else:
51
  result = "D"
 
52
  st.success('Predicted Segmentation: {}'.format(result))
53
 
54
  if __name__ == '__main__':