logo
Loading...

HW 023 # 均值編碼寫法可以解釋一下嗎, 看起來很繞? - Cupoy

# 均值編碼data = pd.concat([df[:train_num], train_Y], ...

均值編碼data,ml100-2,ml100-2-d23

HW 023 # 均值編碼寫法可以解釋一下嗎, 看起來很繞?

2019/05/09 02:10 PM
機器學習新手論壇
陳秉涵
觀看數:0
回答數:1
收藏數:2
均值編碼data
ml100-2
ml100-2-d23

# 均值編碼

data = pd.concat([df[:train_num], train_Y], axis=1)

for c in df.columns:    

    mean_df = data.groupby([c])['SalePrice'].mean().reset_index()    

    mean_df.columns = [c, f'{c}_mean']    

    data = pd.merge(data, mean_df, on=c, how='left')

    data = data.drop([c] , axis=1)

    data = data.drop(['SalePrice'] , axis=1)