了解应用于数据帧的变换

问题描述 投票:0回答:1

我正在查看此link中的代码,但是对于为什么在代码中使用transform的原因却非常迷惑,如下所示。有人可以解释为什么如此使用它吗?

thresholds = sort(model.feature_importances_)
for thresh in thresholds:
    # select features using threshold
    selection = SelectFromModel(model, threshold=thresh, prefit=True)
    select_X_train = selection.transform(X_train) ####What is this doing? 
    # train model
    selection_model = XGBClassifier()
    selection_model.fit(select_X_train, y_train)
    # eval model
    select_X_test = selection.transform(X_test)
    y_pred = selection_model.predict(select_X_test)

谢谢

python list dataframe
1个回答
0
投票

通常与sklearn:

fit():用于从训练数据中学习模型参数

transform():使用从fit()方法学到的参数来生成转换后的数据集(不更改学到的参数)

fit_transform():fit()和transform()在同一数据集上的组合

因此,在此示例中,训练数据在被selection模型训练之前,正在通过称为XGBClassifier的模型进行转换

© www.soinside.com 2019 - 2024. All rights reserved.