qq_42333805 2022-12-11 12:17 采纳率: 0%
浏览 9
已结题

为什么fit_transform和transform结果不一样?

请教一下为什么用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)

img

img

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 12月19日
    • 创建了问题 12月11日

    悬赏问题

    • ¥15 求高通平台Softsim调试经验
    • ¥15 canal如何实现将mysql多张表(月表)采集入库到目标表中(一张表)?
    • ¥15 wpf ScrollViewer实现冻结左侧宽度w范围内的视图
    • ¥15 栅极驱动低侧烧毁MOSFET
    • ¥30 写segy数据时出错3
    • ¥100 linux下qt运行QCefView demo报错
    • ¥50 F1C100S下的红外解码IR_RX驱动问题
    • ¥20 基于matlab的航迹融合 航迹关联 航迹插补
    • ¥15 用Matlab实现图中的光线追迹
    • ¥15 联想笔记本开机出现系统更新界面