-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathavg_files.py
56 lines (48 loc) · 1.73 KB
/
avg_files.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
import glob
import pandas as pd
import numpy as np
import joblib
from sklearn.metrics import mean_absolute_error
MODEL_PATH = "cache/ens_2/*"
def main():
model_files = [
".".join(x.split(".")[:-1])
for x in glob.glob(MODEL_PATH) if x.endswith(".pd")]
val_tmp, test_tmp = [], []
y = pd.read_csv("data/training-set.csv")["Next_Premium"].values
df_test = pd.read_csv("data/testing-set.csv")[["Policy_Number"]]
print("Validation")
for filename in model_files:
val_tmp.append(
np.clip(pd.read_pickle(
filename + ".pd"
).values[:, 0], 0, 2e8)
)
print("%.2f %.2f %.2f %.2f %.2f" % (
np.min(val_tmp), np.percentile(val_tmp, 25),
np.median(val_tmp), np.percentile(val_tmp, 75),
np.max(val_tmp)))
print("=" * 20)
print(np.stack(val_tmp, axis=1).shape)
print(np.corrcoef(np.stack(val_tmp, axis=1), rowvar=False))
print("=" * 20)
print("Test")
for filename in model_files:
test_tmp.append(
np.clip(joblib.load(filename + ".pkl"), 0, 2e8)
)
print("%.2f %.2f %.2f %.2f %.2f" % (
np.min(test_tmp), np.percentile(test_tmp, 25),
np.median(test_tmp), np.percentile(test_tmp, 75),
np.max(test_tmp)))
print("=" * 20)
print(np.stack(test_tmp, axis=1).shape)
print(np.corrcoef(np.stack(test_tmp, axis=1), rowvar=False))
val_preds = np.mean(val_tmp, axis=0)
print("Val loss: %.2f" % mean_absolute_error(y, val_preds))
test_preds = np.mean(test_tmp, axis=0)
df_test["Next_Premium"] = test_preds
print(df_test.head())
df_test.to_csv("sub_ens.csv", index=False, float_format="%.4f")
if __name__ == "__main__":
main()