343. IEEE-CIS Fraud Detection | ieee-fraud-detection
首先,我想祝贺所有的获奖者,因为你们的辛勤工作将得到回报。同时特别祝贺 @cdeotte “晋升”为竞赛大师。再拿3枚金牌,我们就将多一位三重特级大师。
祝贺 @fatihozturk 成为竞赛特级大师。
也要祝贺所有其他参与者,因为你们从每场比赛中获得的最大奖励就是你们所学到的知识。
这里还有一段关于 C 特征交互的代码,我在我最好的模型中使用了它,它稍微提高了模型的分数。我相信大约提高了 0.0002-0.0003。
C 特征列表:
c_cols = [col for col in X.columns if col.startswith('C') and len(col) <= 3]
两两之间的乘法和减法交互:
for i in range(len(c_cols)):
for j in range(i + 1, len(c_cols)):
X['{}_mul_{}'.format(c_cols[i], c_cols[j])] = X[c_cols[i]] * X[c_cols[j]]
X['{}_sub1_{}'.format(c_cols[i], c_cols[j])] = X[c_cols[i]] - X[c_cols[j]]
X['{}_sub2_{}'.format(c_cols[j], c_cols[i])] = X[c_cols[j]] - X[c_cols[i]]
test['{}_mul_{}'.format(c_cols[i], c_cols[j])] = test[c_cols[i]] * test[c_cols[j]]
test['{}_sub1_{}'.format(c_cols[i], c_cols[j])] = test[c_cols[i]] - test[c_cols[j]]
test['{}_sub2_{}'.format(c_cols[j], c_cols[i])] = test[c_cols[j]] - test[c_cols[i]]
计算所有新生成特征的相关矩阵:
sum_cols = [col for col in X.columns if '_mul_' in col or '_sub_' in col]
corr_matrix = X[sum_cols].corr()
然后移除所有高相关性的特征。保留那些与目标值相关性更好的特征。
to_drop = list()
# 从第二行开始迭代,因为位置 [0, 0] 是自相关,值为 1
for i in range(1, len(corr_matrix)):
# 迭代该行的列。只遍历对角线以下部分。
for j in range(i):
# 查看两个特征之间的相关性是否超过选定的阈值
if corr_matrix.iloc[i, j] >= 0.98:
# 然后保留两者中与目标相关性更好的那个
if abs(pd.concat([X[corr_matrix.index[i]], y], axis=1).corr().iloc[0][1]) > abs(pd.concat([X[corr_matrix.columns[j]], y], axis=1).corr().iloc[0][1]):
to_drop.append(corr_matrix.columns[j])
else:
to_drop.append(corr_matrix.index[i])
to_drop = list(set(to_drop))