-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob_salary.py
333 lines (222 loc) · 6.5 KB
/
job_salary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# -*- coding: utf-8 -*-
"""JobSalary.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/16gJawevsBMslRMByU4TvTaB7emBhCKkh
<a href="https://githubtocolab.com/giswqs/geemap/blob/master/examples/notebooks/35_geemap_colab.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"/></a>
"""
from google.colab import files
uploaded = files.upload()
# Import Library
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import roc_auc_score
df_train = pd.read_csv('train.csv')
df_test = pd.read_csv('test.csv')
df = [df_train, df_test]
df_train.head()
df_train = df_train.replace({
'?': np.nan,
'<=7jt': 0,
'>7jt': 1
})
df_test = df_test.replace('?', np.nan)
df = [df_train, df_test]
df_train.head()
df_train.info()
print("\n\n")
df_test.info()
df_train.describe()
# Analyze Data
# 'Kelas Pekerja' and 'Gaji'
df_train.groupby('Kelas Pekerja')[['Gaji']].mean()
# 'Pendidikan' and 'Gaji'
df_train.groupby('Pendidikan')[['Gaji']].mean()
# 'Status' and 'Gaji'
df_train.groupby('Status Perkawinan')[['Gaji']].mean()
# 'Pekerjaan' and 'Gaji'
df_train.groupby('Pekerjaan')[['Gaji']].mean()
# 'Jenis Kelamin' and 'Gaji'
df_train.groupby('Jenis Kelamin')[['Gaji']].mean()
# Visualizing Data
# 'Umur' and 'Gaji'
grid = sns.FacetGrid(df_train, col='Gaji')
grid.map(sns.kdeplot, 'Umur')
# 'Jenis Kelamin', 'Status Perkawinan', and 'Gaji'
grid = sns.FacetGrid(df_train, col='Jenis Kelamin', height=4)
grid.map(sns.barplot, 'Gaji', 'Status Perkawinan', ci=None)
grid.add_legend()
grid = sns.FacetGrid(df_train, col='Jenis Kelamin')
grid.map(sns.barplot, 'Gaji', 'Berat Akhir', ci=None)
grid.add_legend();
# Data Processing
# Handle Missing Value in 'Kelas Pekerja'
df_train['Kelas Pekerja'].value_counts()
for dataset in df:
dataset['Kelas Pekerja'] = dataset['Kelas Pekerja'].fillna('Wiraswasta')
df_train.head()
# Handle Missing Value in 'Pekerjaan'
df_train['Pekerjaan'].value_counts()
for dataset in df:
dataset['Pekerjaan'] = dataset['Pekerjaan'].fillna('Spesialis')
df_train.head()
# Convert 'Kelas Pekerja'
conv_kerja = {
'Pemerintah Negara': 0,
'Pemerintah Provinsi': 1,
'Pemerintah Lokal': 2,
'Pekerja Bebas Perusahaan': 3,
'Pekerja Bebas Bukan Perusahan': 4,
'Wiraswasta': 5,
'Tidak Pernah Bekerja': 6,
'Tanpa di Bayar': 7
}
for dataset in df:
dataset['Kelas Pekerja'] = dataset['Kelas Pekerja'].map(conv_kerja)
df_train.head()
# Convert 'Pendidikan'
for dataset in df:
dataset['Pendidikan'] = dataset['Pendidikan'].replace(['1st-4th', '5th-6th'], 'SD')
dataset['Pendidikan'] = dataset['Pendidikan'].replace(['7th-8th', '9th'], 'SMP')
dataset['Pendidikan'] = dataset['Pendidikan'].replace(['10th', '11th', '12th'], 'SMA')
dataset['Pendidikan'] = dataset['Pendidikan'].replace(['Sarjana', 'D4'], 'D4/Sarjana')
dataset['Pendidikan'] = dataset['Pendidikan'].replace('Sekolah Professional', 'Pendidikan Tinggi')
df_train.groupby('Pendidikan')[['Gaji']].mean()
conv_didik = {
'SD': 0,
'SMP': 1,
'SMA': 2,
'D3': 3,
'D4/Sarjana': 4,
'Master': 5,
'Doktor': 6,
'Pendidikan Tinggi': 7
}
for dataset in df:
dataset['Pendidikan'] = dataset['Pendidikan'].map(conv_didik)
df_train.head()
df_train.groupby('Status Perkawinan')[['Gaji']].mean()
# Convert 'Status Perkawinan'
for dataset in df:
dataset['Status Perkawinan'] = dataset['Status Perkawinan'].replace(['Belum Pernah Menikah', 'Berpisah', 'Cerai', 'Janda'], 'Tidak Menikah')
dataset['Status Perkawinan'] = dataset['Status Perkawinan'].replace('Menikah LDR', 'Menikah')
df_train.groupby('Status Perkawinan')[['Gaji']].mean()
for dataset in df:
dataset['Status Perkawinan'] = dataset['Status Perkawinan'].map({
'Tidak Menikah': 0,
'Menikah': 1
})
df_train.head()
# Convert 'Pekerjaan'
conv_kerja = {
'Asisten Rumah Tangga': 0,
'Ekesekutif Managerial': 1,
'Mesin Inspeksi': 2,
'Pembersih': 3,
'Pemuka Agama': 4,
'Penjaga': 5,
'Perbaikan Kerajinan': 6,
'Petani': 7,
'Sales': 8,
'Servis Lainnya': 9,
'Spesialis': 10,
'Supir': 11,
'Tech-support': 12,
'Tentara': 13,
}
for dataset in df:
dataset['Pekerjaan'] = dataset['Pekerjaan'].map(conv_kerja)
df_train.head()
# Convert 'Jenis Kelamin'
for dataset in df:
dataset['Jenis Kelamin'] = dataset['Jenis Kelamin'].map({
'Perempuan': 0,
'Laki2': 1
})
df_train.head()
# There are too many zero values in 'Kerugian Capital' and 'Keuntungan Capital'
# There are no correlation 'Jumlah Tahun Pendidikan' with 'Gaji'
df_train = df_train.drop(['Kerugian Capital', 'Keuntungan Kapital', 'Jmlh Tahun Pendidikan'], axis=1)
df_test = df_test.drop(['Kerugian Capital', 'Keuntungan Kapital', 'Jmlh Tahun Pendidikan'], axis=1)
df = [df_train, df_test]
df_train.info()
df_train.head()
# Modeling
X = df_train.drop(['id', 'Gaji'], axis=1)
y = df_train['Gaji']
# X_test = df_test.drop(['id'], axis=1).copy()
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, stratify=y)
"""
---
---
"""
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=151, criterion='entropy', random_state=0)
model.fit(X_train, y_train)
# Predicting with Test Data
y_test_pred = model.predict(X_test)
y_test_pred
# Scoring
eval = roc_auc_score(y_test, y_test_pred)
eval
"""
---
---
---
"""
from sklearn.svm import SVC
model = SVC()
model.fit(X_train, y_train)
# Predicting with Test Data
y_test_pred = model.predict(X_test)
y_test_pred
# Scoring
eval = roc_auc_score(y_test, y_test_pred)
eval
"""
---
---
---
"""
from sklearn.neighbors import KNeighborsClassifier
model = KNeighborsClassifier()
model.fit(X_train, y_train)
# Predicting with Test Data
y_test_pred = model.predict(X_test)
y_test_pred
# Scoring
eval = roc_auc_score(y_test, y_test_pred)
eval
"""
---
---
---
"""
from sklearn.tree import DecisionTreeClassifier
model = DecisionTreeClassifier()
model.fit(X_train, y_train)
# Predicting with Test Data
y_test_pred = model.predict(X_test)
y_test_pred
# Scoring
eval = roc_auc_score(y_test, y_test_pred)
eval
"""
---
---
---
"""
# Predicting with New Data
X_pred = df_test.drop(['id'], axis=1).copy()
y_pred = model.predict(X_pred)
y_pred
result = pd.DataFrame({
'id': df_test['id'],
'Gaji': y_pred
})
result
result.to_csv('submission_gaji1.csv', index=False)