-
Notifications
You must be signed in to change notification settings - Fork 0
/
gs.py
128 lines (116 loc) · 3.67 KB
/
gs.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
import pandas as pd
import matplotlib as plt
import numpy as np
import xgboost as xgb
train = pd.read_csv("gcTrianingSet.csv")
sub= pd.read_csv("gcPredictionFile.csv")
sub.fillna(0, inplace=True)
X_train = train[['initialUsedMemory', 'initialFreeMemory', 'query token','cpuTimeTaken','gcRun']]
y_train1=train['finalUsedMemory']
y_train2=train['finalFreeMemory']
y_train3=train['gcRun']
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.model_selection import cross_val_score
X_train=pd.get_dummies(X_train)
sub=pd.get_dummies(sub)
from sklearn.model_selection import train_test_split
X_train1, X_test1, y_train1, y_test1 = train_test_split(X_train, y_train1, test_size=0.33)
X_train2, X_test2, y_train2, y_test2 = train_test_split(X_train, y_train2, test_size=0.33)
X_train3, X_test3, y_train3, y_test3 = train_test_split(X_train.drop(['gcRun'], axis=1), y_train3, test_size=0.33)
from sklearn.metrics import confusion_matrix
dtrain1 = xgb.DMatrix(X_train1, y_train1)
dtrain2 = xgb.DMatrix(X_train2, y_train2)
dtrain3 = xgb.DMatrix(X_train3, y_train3)
dtest1 = xgb.DMatrix(X_test1)
dtest2 = xgb.DMatrix(X_test2)
dtest3 = xgb.DMatrix(X_test3)
xgb_params1 = {
'n_trees': 500,
'eta': 0.01,
'max_depth': 4,
'min_child_weight': 1,
'subsample': 0.95,
'objective': 'reg:linear',
'eval_metric': 'rmse',
'silent': 1
}
'''
cv_result = xgb.cv(xgb_params1,
dtrain1,
nfold=5,
num_boost_round=2000,
early_stopping_rounds=50,
verbose_eval=50,
show_stdv=False,
seed=0
)
'''
xgb_params2 = {
'n_trees': 500,
'eta': 0.01,
'max_depth': 4,
'min_child_weight': 1,
'subsample': 0.95,
'objective': 'reg:linear',
'eval_metric': 'rmse',
'silent': 1
}
'''
cv_result = xgb.cv(xgb_params2,
dtrain2,
nfold=5,
num_boost_round=2000,
early_stopping_rounds=50,
verbose_eval=50,
show_stdv=False,
seed=0
)
'''
xgb_params3 = {
'n_trees': 500,
'eta': 0.01,
'max_depth': 4,
'min_child_weight': 1,
'subsample': 0.95,
'objective': 'binary:logistic',
'eval_metric': 'logloss',
'silent': 1
}
'''
cv_result = xgb.cv(xgb_params3,
dtrain3,
nfold=5,
num_boost_round=2000,
early_stopping_rounds=50,
verbose_eval=50,
show_stdv=False,
seed=0
)
'''
model1 = xgb.train(xgb_params1, dtrain1, num_boost_round=2050)
y_pred1 = model1.predict(dtest1)
from sklearn.metrics import r2_score
print r2_score(y_test1, y_pred1)
model2 = xgb.train(xgb_params2, dtrain2, num_boost_round=2050)
y_pred2 = model2.predict(dtest2)
from sklearn.metrics import r2_score
print r2_score(y_test2, y_pred2)
model3 = xgb.train(xgb_params3, dtrain3, num_boost_round=2050)
y_pred3 = model3.predict(dtest3)
'''
col1=model1.predict(xgb.DMatrix(sub.iloc[[0]]))
col2=model2.predict(xgb.DMatrix(sub.iloc[[0]]))
sub.set_value(1,'initialUsedMemory',col1)
sub.set_value(1,'initialFreeMemory',col2)
'''
for i, row in sub.iterrows():
col1=model1.predict(xgb.DMatrix(sub.iloc[[i]]))
col2=model2.predict(xgb.DMatrix(sub.iloc[[i]]))
sub.set_value(i+1,'initialUsedMemory',col1)
sub.set_value(i+1,'initialFreeMemory',col2)
col3=model3.predict(xgb.DMatrix(sub.iloc[[i+1]].drop(['gcRun'], axis=1)))
if col3>0.45:
sub.set_value(i+1,'gcRun',1)
if col3<0.45:
sub.set_value(i+1,'gcRun',0)
sub[['initialFreeMemory','gcRun']].to_csv('./GSsubmission.csv', index_label=None)