-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
76 lines (56 loc) · 1.96 KB
/
main.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
"""
HOME CREDIT DEFAULT RISK RUNNER FUNCTION
"""
import gc
import time
from contextlib import contextmanager
import warnings
from src.helper_functions import get_namespace
from src.preprocessing import application_train_test, bureau_and_balance, previous_applications, pos_cash, \
installments_payments, credit_card_balance
from src.train import kfold_lightgbm
from src.config import FINAL_TRAIN_DF, FINAL_TEST_DF
warnings.simplefilter(action='ignore', category=FutureWarning)
@contextmanager
def timer(title):
t0 = time.time()
yield
print("{} - done in {:.0f}s".format(title, time.time() - t0))
def main(debug=False):
num_rows = 10000 if debug else None
with timer("Pre-Processing"):
# application_train_test
df = application_train_test(num_rows)
# bureau & bureau_balance
bureau = bureau_and_balance(num_rows)
df = df.join(bureau, how='left', on='SK_ID_CURR')
del bureau
# previous_applications
prev = previous_applications(num_rows)
df = df.join(prev, how='left', on='SK_ID_CURR')
del prev
# posh_cash
pos = pos_cash(num_rows)
df = df.join(pos, how='left', on='SK_ID_CURR')
del pos
# installments_payments
ins = installments_payments(num_rows)
df = df.join(ins, how='left', on='SK_ID_CURR')
del ins
# credit_card_balance
cc = credit_card_balance(num_rows)
df = df.join(cc, how='left', on='SK_ID_CURR')
del cc
# saving final dataframes
train_df = df[df['TARGET'].notnull()]
test_df = df[df['TARGET'].isnull()]
train_df.to_pickle(FINAL_TRAIN_DF)
test_df.to_pickle(FINAL_TEST_DF)
del train_df, test_df
gc.collect()
with timer("Run LightGBM"):
feat_importance = kfold_lightgbm(df, debug=debug)
if __name__ == "__main__":
namespace = get_namespace()
with timer("Full model run"):
main(debug=namespace.debug)