我正在查看此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)
谢谢
通常与sklearn:
fit()
:用于从训练数据中学习模型参数
transform()
:使用从fit()方法学到的参数来生成转换后的数据集(不更改学到的参数)
fit_transform()
:fit()和transform()在同一数据集上的组合
因此,在此示例中,训练数据在被selection
模型训练之前,正在通过称为XGBClassifier
的模型进行转换