Spaces:
Runtime error
Runtime error
fix ui
Browse files- app.py +2 -2
- eda.py +23 -29
- prediction.py +70 -9
app.py
CHANGED
@@ -2,9 +2,9 @@ import streamlit as st
|
|
2 |
import eda
|
3 |
import prediction
|
4 |
|
5 |
-
navigation = st.sidebar.selectbox('
|
6 |
|
7 |
-
if navigation == '
|
8 |
eda.run()
|
9 |
else:
|
10 |
prediction.run()
|
|
|
2 |
import eda
|
3 |
import prediction
|
4 |
|
5 |
+
navigation = st.sidebar.selectbox('Chọn trang: ', ('Phân tích dữ liệu', 'Dự đoán lương'))
|
6 |
|
7 |
+
if navigation == 'Phân tích dữ liệu':
|
8 |
eda.run()
|
9 |
else:
|
10 |
prediction.run()
|
eda.py
CHANGED
@@ -18,48 +18,44 @@ def run():
|
|
18 |
st.title('Công cụ ước tính lương nghề khoa học dữ liệu')
|
19 |
|
20 |
# Sub header
|
21 |
-
|
22 |
|
23 |
# Insert Gambar
|
24 |
image = Image.open('gaji.jpg')
|
25 |
st.image(image, caption='Lương', use_column_width=True)
|
26 |
|
27 |
# description
|
28 |
-
st.
|
29 |
st.write(
|
30 |
'Với tư cách là một nhà khoa học dữ liệu, tôi muốn biết liệu tôi có nhận được mức lương xứng đáng từ công ty hay không, vì vậy tôi đã tạo ra mô hình học máy này để dự đoán mức lương cho các công việc trong thế giới dữ liệu.')
|
31 |
-
st.write('
|
32 |
-
st.markdown('---')
|
33 |
-
|
34 |
-
# Menambahkan Deskripsi
|
35 |
-
st.write('Trang này được tạo để hiển thị trực quan của tập dữ liệu')
|
36 |
-
|
37 |
st.markdown('---')
|
38 |
|
39 |
-
st.
|
40 |
st.write('Cấp độ kinh nghiệm')
|
41 |
-
st.
|
42 |
-
'
|
43 |
-
|
44 |
-
st.write('Hình thức hợp đồng')
|
45 |
-
st.write('FT, tức là Toàn thời gian. PT, tức là Bán thời gian. CT, đó là Hợp đồng. FL, đó là nghề tự do.')
|
46 |
|
47 |
-
st.write('Tỷ lệ làm từ xa')
|
48 |
-
st.write('100, hoàn toàn từ xa. 50, là loại kết hợp. 0, là hoàn toàn làm trên công ty.')
|
49 |
|
50 |
st.markdown('---')
|
51 |
|
52 |
# show dataframe
|
53 |
data = pd.read_csv('DataScienceSalaries.csv')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
st.dataframe(data)
|
55 |
|
56 |
# membuat histogram salary
|
57 |
-
st.write('### Biểu đồ lương')
|
58 |
fig = plt.figure(figsize=(10, 5), dpi=150)
|
59 |
sns.histplot(data['salary_in_usd'], kde=True, bins=40)
|
60 |
-
plt.xlabel('Lương bằng
|
61 |
plt.ylabel('Số lượng', fontsize=15)
|
62 |
-
plt.title('Biểu đồ lương bằng usd', fontsize=15)
|
63 |
st.pyplot(fig)
|
64 |
|
65 |
# membuat pie chart experience
|
@@ -76,7 +72,6 @@ def run():
|
|
76 |
|
77 |
fig = plt.figure(figsize=(5, 5), dpi=150)
|
78 |
exp.plot.pie(autopct=make_autopct(exp))
|
79 |
-
plt.title('Biểu đồ phân phối cấp độ kinh nghiệm', fontsize=15)
|
80 |
st.pyplot(fig)
|
81 |
|
82 |
# barchart posisi dengan gaji terbesar
|
@@ -85,31 +80,29 @@ def run():
|
|
85 |
work = work_rate.nlargest(5)
|
86 |
fig = plt.figure(figsize=(15, 5), dpi=150)
|
87 |
work.plot(kind="bar")
|
88 |
-
plt.title('5 Vị trí có mức lương cao nhất', fontsize=15)
|
89 |
plt.xlabel('Tên vị trí', fontsize=15)
|
90 |
-
plt.xticks(rotation=45)
|
91 |
-
plt.ylabel('Lương bằng
|
92 |
st.pyplot(fig)
|
93 |
|
94 |
# negara dengan gaji tertinggi
|
95 |
st.write('### 5 Quốc gia có mức lương cao nhất')
|
96 |
-
location_payrate = data.groupby(['company_location'])['salary_in_usd'].
|
97 |
lar = location_payrate.nlargest(5)
|
98 |
fig = plt.figure(figsize=(15, 8), dpi=150)
|
99 |
lar.plot(kind="bar")
|
100 |
-
plt.title('5 Quốc gia có mức lương cao nhất', fontsize=15)
|
101 |
plt.xlabel('Tên quốc gia', fontsize=15)
|
102 |
-
plt.xticks(rotation=0)
|
103 |
plt.ylabel('Lương bằng usd', fontsize=15)
|
104 |
st.pyplot(fig)
|
105 |
|
106 |
# popular job
|
107 |
-
st.write('### Top 10 công việc')
|
108 |
job = data.groupby(['job_title'])['job_title'].count()
|
109 |
top_job = job.nlargest(10)
|
110 |
fig = plt.figure(figsize=(12, 12), dpi=150)
|
111 |
-
plt.xticks(rotation=0)
|
112 |
-
plt.
|
113 |
plt.ylabel('Tên công việc', fontsize=15)
|
114 |
plt.xlabel('Số lượng', fontsize=15)
|
115 |
sns.barplot(y=top_job.index, x=top_job.values)
|
@@ -117,6 +110,7 @@ def run():
|
|
117 |
|
118 |
# wordcloud
|
119 |
# see most job with word cloud
|
|
|
120 |
text = " ".join(i for i in data.job_title)
|
121 |
stopwords = set(STOPWORDS)
|
122 |
wordcloud = WordCloud(width=1600, height=800).generate(text)
|
|
|
18 |
st.title('Công cụ ước tính lương nghề khoa học dữ liệu')
|
19 |
|
20 |
# Sub header
|
21 |
+
|
22 |
|
23 |
# Insert Gambar
|
24 |
image = Image.open('gaji.jpg')
|
25 |
st.image(image, caption='Lương', use_column_width=True)
|
26 |
|
27 |
# description
|
28 |
+
st.markdown('## Mục tiêu của công cụ ước tính lương')
|
29 |
st.write(
|
30 |
'Với tư cách là một nhà khoa học dữ liệu, tôi muốn biết liệu tôi có nhận được mức lương xứng đáng từ công ty hay không, vì vậy tôi đã tạo ra mô hình học máy này để dự đoán mức lương cho các công việc trong thế giới dữ liệu.')
|
31 |
+
st.write('Công cụ ước tính lương này có thể giúp các bạn biết liệu mình có nhận được mức lương xứng đáng hay không.')
|
|
|
|
|
|
|
|
|
|
|
32 |
st.markdown('---')
|
33 |
|
34 |
+
st.markdown('## Mô tả')
|
35 |
st.write('Cấp độ kinh nghiệm')
|
36 |
+
st.markdown(
|
37 |
+
'- Entry-level: người mới ra trường họặc ít năm kinh nghiệm.\n- Mid-level: vị trí có một mức độ kinh nghiệm và chuyên môn nhất định, vượt qua cấp độ mới vào nghề (Entry-level) nhưng chưa đạt đến cấp độ cao cấp (Senior-level).\n- Senior-level: vị trí có mức độ kinh nghiệm, chuyên môn và thẩm quyền cao.\n- Executive-level: cấp điều hành.')
|
|
|
|
|
|
|
38 |
|
|
|
|
|
39 |
|
40 |
st.markdown('---')
|
41 |
|
42 |
# show dataframe
|
43 |
data = pd.read_csv('DataScienceSalaries.csv')
|
44 |
+
map_ex = {'SE': 'Senior-level', 'MI': 'Mid-level', 'EN': 'Entry-level', 'EX': 'Executive-level'}
|
45 |
+
map_type = {'FT': 'Toàn thời gian', 'PT': 'Bán thời gian', 'CT': 'Hợp đồng', 'FL': 'Tự do'}
|
46 |
+
map_size = {'S': 'Nhỏ', 'M': 'Vừa', 'L': 'Lớn'}
|
47 |
+
data['experience_level'] = data['experience_level'].map(map_ex)
|
48 |
+
data['employment_type'] = data['employment_type'].map(map_type)
|
49 |
+
data['company_size'] = data['company_size'].map(map_size)
|
50 |
+
|
51 |
st.dataframe(data)
|
52 |
|
53 |
# membuat histogram salary
|
54 |
+
st.write('### Biểu đồ lương bằng USD')
|
55 |
fig = plt.figure(figsize=(10, 5), dpi=150)
|
56 |
sns.histplot(data['salary_in_usd'], kde=True, bins=40)
|
57 |
+
plt.xlabel('Lương bằng USD', fontsize=15)
|
58 |
plt.ylabel('Số lượng', fontsize=15)
|
|
|
59 |
st.pyplot(fig)
|
60 |
|
61 |
# membuat pie chart experience
|
|
|
72 |
|
73 |
fig = plt.figure(figsize=(5, 5), dpi=150)
|
74 |
exp.plot.pie(autopct=make_autopct(exp))
|
|
|
75 |
st.pyplot(fig)
|
76 |
|
77 |
# barchart posisi dengan gaji terbesar
|
|
|
80 |
work = work_rate.nlargest(5)
|
81 |
fig = plt.figure(figsize=(15, 5), dpi=150)
|
82 |
work.plot(kind="bar")
|
|
|
83 |
plt.xlabel('Tên vị trí', fontsize=15)
|
84 |
+
plt.xticks(rotation=45, fontsize=15)
|
85 |
+
plt.ylabel('Lương bằng USD', fontsize=15)
|
86 |
st.pyplot(fig)
|
87 |
|
88 |
# negara dengan gaji tertinggi
|
89 |
st.write('### 5 Quốc gia có mức lương cao nhất')
|
90 |
+
location_payrate = data.groupby(['company_location'])['salary_in_usd'].mean()
|
91 |
lar = location_payrate.nlargest(5)
|
92 |
fig = plt.figure(figsize=(15, 8), dpi=150)
|
93 |
lar.plot(kind="bar")
|
|
|
94 |
plt.xlabel('Tên quốc gia', fontsize=15)
|
95 |
+
plt.xticks(rotation=0, fontsize=15)
|
96 |
plt.ylabel('Lương bằng usd', fontsize=15)
|
97 |
st.pyplot(fig)
|
98 |
|
99 |
# popular job
|
100 |
+
st.write('### Top 10 công việc được tuyển dụng nhiều nhất')
|
101 |
job = data.groupby(['job_title'])['job_title'].count()
|
102 |
top_job = job.nlargest(10)
|
103 |
fig = plt.figure(figsize=(12, 12), dpi=150)
|
104 |
+
plt.xticks(rotation=0, fontsize = 15)
|
105 |
+
plt.yticks(fontsize = 15)
|
106 |
plt.ylabel('Tên công việc', fontsize=15)
|
107 |
plt.xlabel('Số lượng', fontsize=15)
|
108 |
sns.barplot(y=top_job.index, x=top_job.values)
|
|
|
110 |
|
111 |
# wordcloud
|
112 |
# see most job with word cloud
|
113 |
+
st.write('### Word-cloud các từ được nhắc tới nhiều nhất')
|
114 |
text = " ".join(i for i in data.job_title)
|
115 |
stopwords = set(STOPWORDS)
|
116 |
wordcloud = WordCloud(width=1600, height=800).generate(text)
|
prediction.py
CHANGED
@@ -7,27 +7,88 @@ import joblib as jb
|
|
7 |
|
8 |
# load models
|
9 |
model = jb.load('model.pkl')
|
10 |
-
|
11 |
# load data
|
12 |
df = pd.read_csv('DataScienceSalaries.csv')
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
def run():
|
16 |
-
st.markdown("<h1 style='text-align: center;'>
|
17 |
# description
|
18 |
|
19 |
st.subheader('Vui lòng kiểm tra mức lương của bạn tại đây.')
|
20 |
|
21 |
with st.form('key=form_prediction'):
|
22 |
year = st.selectbox('Năm làm việc', df['work_year'].unique())
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
residence = st.selectbox('Quốc tịch', sorted(df['employee_residence'].unique()))
|
27 |
-
remote = st.selectbox('Làm việc từ xa', df['remote_ratio'].unique())
|
28 |
location = st.selectbox('Vị trí công ty', sorted(df['company_location'].unique()))
|
29 |
-
|
30 |
-
|
31 |
submitted = st.form_submit_button('Dự đoán')
|
32 |
|
33 |
inf = {
|
@@ -48,7 +109,7 @@ def run():
|
|
48 |
# Predict using bagging
|
49 |
y_pred_inf = model.predict(data_inf)
|
50 |
|
51 |
-
st.write('Với kinh nghiệm này bạn sẽ nhận được mức lương khoảng')
|
52 |
st.write('# $', str(int(y_pred_inf)))
|
53 |
st.write(
|
54 |
'LƯU Ý: Hãy nhớ rằng mô hình này không chính xác 100%, vui lòng kiểm tra lại với một trang web khác về tiền lương như Glassdoor')
|
|
|
7 |
|
8 |
# load models
|
9 |
model = jb.load('model.pkl')
|
|
|
10 |
# load data
|
11 |
df = pd.read_csv('DataScienceSalaries.csv')
|
12 |
|
13 |
+
map_ex = {'SE': 'Senior-level', 'MI': 'Mid-level', 'EN': 'Entry-level', 'EX': 'Executive-level'}
|
14 |
+
map_ex_inverse = {v: k for k, v in map_ex.items()}
|
15 |
+
map_type = {'FT': 'Toàn thời gian', 'PT': 'Bán thời gian', 'CT': 'Hợp đồng', 'FL': 'Tự do'}
|
16 |
+
map_type_inverse = {v: k for k, v in map_type.items()}
|
17 |
+
map_size = {'S': 'Nhỏ', 'M': 'Vừa', 'L': 'Lớn'}
|
18 |
+
map_size_inverse = {v: k for k, v in map_size.items()}
|
19 |
+
map_job = {
|
20 |
+
"Principal Data Scientist": "Chuyên gia Khoa học Dữ liệu Cấp cao",
|
21 |
+
"ML Engineer": "Kỹ sư Máy học",
|
22 |
+
"Data Scientist": "Nhà khoa học Dữ liệu",
|
23 |
+
"Data Analyst": "Nhà phân tích Dữ liệu",
|
24 |
+
"Machine Learning Scientist": "Nhà khoa học Máy học",
|
25 |
+
"AI Scientist": "Nhà khoa học Trí tuệ Nhân tạo",
|
26 |
+
"Director of Data Science": "Giám đốc Khoa học Dữ liệu",
|
27 |
+
"Data Engineering Manager": "Quản lý Kỹ thuật Dữ liệu",
|
28 |
+
"Data Engineer": "Kỹ sư Dữ liệu",
|
29 |
+
"Machine Learning Engineer": "Kỹ sư Máy học",
|
30 |
+
"Machine Learning Developer": "Nhà phát triển Máy học",
|
31 |
+
"Big Data Engineer": "Kỹ sư Big Data",
|
32 |
+
"Business Intelligence Developer": "Nhà phát triển Trí tuệ Kinh doanh",
|
33 |
+
"BI Data Analyst": "Nhà phân tích Dữ liệu BI",
|
34 |
+
"Lead Data Analyst": "Trưởng nhóm Nhà phân tích Dữ liệu",
|
35 |
+
"Lead Data Engineer": "Trưởng nhóm Kỹ sư Dữ liệu",
|
36 |
+
"Lead Data Scientist": "Trưởng nhóm Nhà khoa học Dữ liệu",
|
37 |
+
"Research Scientist": "Nhà khoa học Nghiên cứu",
|
38 |
+
"Data Science Manager": "Quản lý Khoa học Dữ liệu",
|
39 |
+
"Product Data Analyst": "Nhà phân tích Dữ liệu Sản phẩm",
|
40 |
+
"Head of Data": "Trưởng phòng Dữ liệu",
|
41 |
+
"Analytics Engineer": "Kỹ sư Phân tích",
|
42 |
+
"Data Science Consultant": "Tư vấn Khoa học Dữ liệu",
|
43 |
+
"Machine Learning Infrastructure Engineer": "Kỹ sư Cơ sở hạ tầng Máy học",
|
44 |
+
"Applied Data Scientist": "Nhà khoa học Dữ liệu Ứng dụng",
|
45 |
+
"Data Analytics Engineer": "Kỹ sư Phân tích Dữ liệu",
|
46 |
+
"Data Architecture": "Kiến trúc Dữ liệu",
|
47 |
+
"Database Administrator": "Quản trị viên Cơ sở dữ liệu",
|
48 |
+
"Software Engineer": "Kỹ sư Phần mềm",
|
49 |
+
"Statistician": "Nhà thống kê",
|
50 |
+
"Product Manager": "Quản lý Sản phẩm",
|
51 |
+
"Marketing Data Analyst": "Nhà phân tích Dữ liệu Tiếp thị",
|
52 |
+
"Financial Data Analyst": "Nhà phân tích Dữ liệu Tài chính",
|
53 |
+
"Data Science Engineer": "Kỹ sư Khoa học Dữ liệu",
|
54 |
+
"Principal Data Engineer": "Chuyên gia Kỹ sư Dữ liệu Cấp cao",
|
55 |
+
"AI Engineer": "Kỹ sư Trí tuệ Nhân tạo",
|
56 |
+
"Data Operations Analyst": "Nhà phân tích Hoạt động Dữ liệu",
|
57 |
+
"Business Data Analyst": "Nhà phân tích Dữ liệu Kinh doanh",
|
58 |
+
"Applied Machine Learning Engineer": "Kỹ sư Máy học Ứng dụng",
|
59 |
+
"Data Product Manager": "Quản lý Sản phẩm Dữ liệu",
|
60 |
+
"Data Specialist": "Chuyên gia Dữ liệu",
|
61 |
+
"Head of Data Science": "Trưởng phòng Khoa học Dữ liệu",
|
62 |
+
"Machine Learning Operations Engineer": "Kỹ sư Hoạt động Máy học",
|
63 |
+
"Data Architect": "Kiến trúc sư Dữ liệu",
|
64 |
+
"Data Science Instructor": "Giảng viên Khoa học Dữ liệu",
|
65 |
+
"Principal Data Analyst": "Chuyên gia Phân tích Dữ liệu Cấp cao",
|
66 |
+
"Senior Data Scientist": "Nhà khoa học Dữ liệu Cấp cao",
|
67 |
+
"Senior Data Engineer": "Kỹ sư Dữ liệu Cấp cao",
|
68 |
+
}
|
69 |
+
map_job_inverse = {v: k for k, v in map_job.items()}
|
70 |
+
|
71 |
|
72 |
def run():
|
73 |
+
st.markdown("<h1 style='text-align: center;'>Mô hình dự đoán lương</h1>", unsafe_allow_html=True)
|
74 |
# description
|
75 |
|
76 |
st.subheader('Vui lòng kiểm tra mức lương của bạn tại đây.')
|
77 |
|
78 |
with st.form('key=form_prediction'):
|
79 |
year = st.selectbox('Năm làm việc', df['work_year'].unique())
|
80 |
+
experience_select = st.selectbox('Cấp độ kinh nghiệm', map_ex.values())
|
81 |
+
experience = map_ex_inverse[experience_select]
|
82 |
+
employment_select = st.selectbox('Hình thức hợp đồng', map_type.values())
|
83 |
+
employment = map_type_inverse[employment_select]
|
84 |
+
|
85 |
+
job_select = st.selectbox('Vị trí công việc', map_job.values())
|
86 |
+
job = map_job_inverse[job_select]
|
87 |
residence = st.selectbox('Quốc tịch', sorted(df['employee_residence'].unique()))
|
88 |
+
remote = st.selectbox('Làm việc từ xa [%]', df['remote_ratio'].unique())
|
89 |
location = st.selectbox('Vị trí công ty', sorted(df['company_location'].unique()))
|
90 |
+
size_select = st.selectbox('Quy mô công ty', map_size.values())
|
91 |
+
size = map_size_inverse[size_select]
|
92 |
submitted = st.form_submit_button('Dự đoán')
|
93 |
|
94 |
inf = {
|
|
|
109 |
# Predict using bagging
|
110 |
y_pred_inf = model.predict(data_inf)
|
111 |
|
112 |
+
st.write('Với kinh nghiệm này bạn sẽ nhận được mức lương 1 năm khoảng')
|
113 |
st.write('# $', str(int(y_pred_inf)))
|
114 |
st.write(
|
115 |
'LƯU Ý: Hãy nhớ rằng mô hình này không chính xác 100%, vui lòng kiểm tra lại với một trang web khác về tiền lương như Glassdoor')
|