请教一下为什么用catboost编码使用fit_transform和transform结果不一样?
我参考的原文链接:https://moonapi.com/news/581.html
# import libraries
import category_encoders as ce
import pandas as pd
# Make dataset
train = pd.DataFrame({
'color': ["red", "blue", "blue", "green", "red",
"red", "black", "black", "blue", "green"],
'interests': ["sketching", "painting", "instruments",
"sketching", "painting", "video games",
"painting", "instruments", "sketching",
"sketching"],
'height': [68, 64, 87, 45, 54, 64, 67, 98, 90, 87],
'grade': [1, 2, 3, 2, 3, 1, 4, 4, 2, 3], })
# Define train and target
target = train[['grade']]
train = train.drop('grade', axis = 1)
# Define catboost encoder
cbe_encoder = ce.cat_boost.CatBoostEncoder()
# Fit encoder and transform the features
cbe_encoder.fit(train, target)
train_cbe = cbe_encoder.transform(train)
# We can use fit_transform() instead of fit() and transform() separately as follows:
cbe_encoder1 = ce.cat_boost.CatBoostEncoder()
train_cbe1 = cbe_encoder1.fit_transform(train,target)