請問 fit 跟 transform 為什麼要分開寫?
2019/09/02 下午 04:27
機器學習共學討論版
許永昕
觀看數:51
回答數:2
收藏數:0
day006
create
if
train
transform
keep
ml100-3
ml100-3-d06
# Create a label encoder object
le = LabelEncoder()
le_count = 0
# Iterate through the columns
for col in app_train:
if app_train[col].dtype == 'object':
# If 2 or fewer unique categories
if len(list(app_train[col].unique())) <= 2:
# Train on the training data
le.fit(app_train[col])
# Transform both training and testing data
app_train[col] = le.transform(app_train[col])
app_test[col] = le.transform(app_test[col])
# Keep track of how many columns were label encoded
le_count += 1
問題 :
請問 fit 跟 transform 為什麼要分開寫?
如果寫成這樣也可以嗎?app_train[col] = le.fit_transform(app_train[col])
想請問專家們分開寫的用義及優點是什麼 ?
回答列表
-
2019/09/02 下午 05:30張維元 (WeiYuan)贊同數:1不贊同數:0留言數:1
我覺得是習慣問題,可能看看有沒有其他專家有補充:)
-
2019/09/07 下午 09:20張維元 (WeiYuan)贊同數:1不贊同數:0留言數:0
fit => 模型會學習訓練資料,得到參數
transform => 將訓練好的模型應用在測試資料之上