【发布时间】:2019-10-26 10:59:44
【问题描述】:
如何使用自定义函数创建 sklearn 管道? 我有两个功能,一个用于清理数据,另一个用于构建模型。
def preprocess(df):
……………….
# clean data
return df_clean
def model(df_clean):
…………………
#split data train and test and build randomForest Model
return model
所以我使用 FunctionTransformer 并创建了管道
from sklearn.pipeline import Pipeline, make_pipeline
from sklearn.preprocessing import FunctionTransformer
pipe = Pipeline([("preprocess", FunctionTransformer(preprocess)),("model",FunctionTransformer(model))])
pred = pipe.predict_proba(new_test_data)
print(pred)
我知道上面是错误的,不知道如何处理,在管道中我需要先传递训练数据然后,我必须传递 new_test_data?
【问题讨论】:
标签: python scikit-learn pipeline