【发布时间】:2019-06-08 01:24:41
【问题描述】:
在本页https://www.kaggle.com/baghern/a-deep-dive-into-sklearn-pipelines
它调用fit_transfrom 对数据进行如下转换:
from sklearn.pipeline import FeatureUnion
feats = FeatureUnion([('text', text),
('length', length),
('words', words),
('words_not_stopword', words_not_stopword),
('avg_word_length', avg_word_length),
('commas', commas)])
feature_processing = Pipeline([('feats', feats)])
feature_processing.fit_transform(X_train)
在使用特征处理进行训练时,它只使用fit 然后predict
from sklearn.ensemble import RandomForestClassifier
pipeline = Pipeline([
('features',feats),
('classifier', RandomForestClassifier(random_state = 42)),
])
pipeline.fit(X_train, y_train)
preds = pipeline.predict(X_test)
np.mean(preds == y_test)
问题是,对于第二种情况,fit 是否对X_train 进行了转换(正如transform 所实现的,因为我们在这里没有调用fit_transform)?
【问题讨论】:
标签: python-3.x scikit-learn pipeline