-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstackingEm.py
164 lines (121 loc) · 3.61 KB
/
stackingEm.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
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 23 21:56:25 2019
@author: Lenovo
"""
import os
import numpy as np
import pandas as pd
import tqdm
from sklearn.linear_model import LogisticRegression
###############################################################################
#aaa = pd.read_csv('./sub/规则Em0.6929.csv')
#bbb = pd.read_csv('./sub/lgb.csv')
#ccc = pd.read_csv('./sub/cbt.csv')
#
#pre = []
##for i in range(120):
## a = cbt_pre.iloc[i, 1:].values
## b = lgb_pre.iloc[i, 1:].values
## c = xgb_pre.iloc[i, 1:].values
##
## if (a.max()-a.min()) > (b.max()-b.min()):
## if (a.max()-a.min()) > (c.max()-c.min()):
## pre.append(a)
## else:
## pre.append(c)
## else:
## if (b.max()-b.min()) > (c.max()-c.min()):
## pre.append(b)
## else:
## pre.append(c)
#
#for i in range(120):
# a = aaa.iloc[i, 1:].values
# b = bbb.iloc[i, 1:].values
# c = ccc.iloc[i, 1:].values
#
# if a.max() > b.max():
# if a.max() > c.max():
# pre.append(a)
# else:
# pre.append(c)
# else:
# if b.max() > c.max():
# pre.append(b)
# else:
# pre.append(c)
#
#pre = np.array(pre)
#
#sub = aaa[['Group']]
#prob_cols = [i for i in aaa.columns if i not in ['Group']]
#for i, f in enumerate(prob_cols):
# sub[f] = pre[:, i]
#sub = sub.drop_duplicates()
#sub.to_csv("./sub/sub.csv",index=False)
###############################################################################
'''
每个预测文件中,
取出相同Group的组进行比较,
把最大值最大的那个组作为最后的预测结果
'''
#submit = pd.read_csv('./data/submit_example2.csv')
#
#path = './em/'
#csv_name = os.listdir(path)
#print(csv_name)
#
#sub = []
#for i in tqdm.tqdm(range(120)):
# for j in range(len(csv_name)):
# df = pd.read_csv(path+csv_name[j])
#
# if j == 0:
# max_m = df.iloc[i, 1:].values
# else:
# a_a = df.iloc[i, 1:].values
## if (max_m.max() - max_m.min()) < (a_a.max() - a_a.min()):
## max_m = a_a
#
# if max_m.max() < a_a.max():
# max_m = a_a
#
# sub.append(max_m)
#
#sub = np.array(sub)
#submit.iloc[:, 1:] = sub
#submit.to_csv('./last/2.csv', index=False)
def em(path, outpath):
submit = pd.read_csv('./data/submit_example2.csv')
csv_name = os.listdir(path)
print(csv_name)
sub = []
for i in tqdm.tqdm(range(120)):
for j in range(len(csv_name)):
df = pd.read_csv(path+csv_name[j])
if j == 0:
max_m = df.iloc[i, 1:].values
else:
a_a = df.iloc[i, 1:].values
# if (max_m.max() - max_m.min()) < (a_a.max() - a_a.min()):
# max_m = a_a
if max_m.max() < a_a.max():
max_m = a_a
sub.append(max_m)
sub = np.array(sub)
submit.iloc[:, 1:] = sub
submit.to_csv(outpath, index=False)
em('./em/', 'e:/1.csv')
###############################################################################
'''
线性融合
'''
#a = pd.read_csv('./last/1.csv')
#b = pd.read_csv('./last/2.csv')
#
#
#s = a.copy()
#s.iloc[:, 1:] = a.iloc[:, 1:]*0.45 + b.iloc[:, 1:]*0.55
#s.to_csv('./last/LastSub.csv', index=False)
###############################################################################