logo
Loading...

作業Day015-labelencoder 為甚麼要特別選取len(list(app_train[col].unique())) <= 2的?? - Cupoy

# 將只有兩種值的類別型欄位, 做 Label Encoder, 計算相關係數時讓這些欄位可以被包含...

作業Day015-labelencoder 為甚麼要特別選取len(list(app_train[col].unique())) <= 2的??

2020/07/12 上午 08:27
機器學習共學討論版
黃宜靜
觀看數:4
回答數:1
收藏數:0

# 將只有兩種值的類別型欄位, 做 Label Encoder, 計算相關係數時讓這些欄位可以被包含在內

from sklearn.preprocessing import LabelEncoder

le = LabelEncoder()


# 檢查每一個 column

for col in app_train:

   if app_train[col].dtype == 'object':

       # 如果只有兩種值的類別型欄位

       if len(list(app_train[col].unique())) <= 2:

           # 就做 Label Encoder, 以加入相關係數檢查

           app_train[col] = le.fit_transform(app_train[col])            

print(app_train.shape)

app_train.head()

回答列表

  • 2020/07/15 上午 00:03
    張維元 (WeiYuan)
    贊同數:0
    不贊同數:0
    留言數:0

    如果欄位只有兩種,不需要特別用 One-Hot Encoder 處理