特征工程构造新特征时, 可以考虑构造比例特征: 该特征为某标签时所占总数据的比例.
ratio = {}
for i in data.A.unique():
ratio[i] = len(data.loc[(data.A == i) & (data.label == 1)]) / len(data.loc[data.A == i])
data['ratio_A'] = data.A.map(ratio)
特征工程构造新特征时, 可以考虑构造比例特征: 该特征为某标签时所占总数据的比例.
ratio = {}
for i in data.A.unique():
ratio[i] = len(data.loc[(data.A == i) & (data.label == 1)]) / len(data.loc[data.A == i])
data['ratio_A'] = data.A.map(ratio)