我有一个复杂的方法,在它们之上使用单独的模型和Stacker。像:
# GLMNET
glmnet_pipe = Pipeline([
("DATA_CLEANER", DataCleaner(demo='HH_F', mode='strict')),
("DATA_ENCODING", Encoder(encoder_name='code')),
("MODELLING", glm)
])
# XGBoost
xgb_1_pipe = Pipeline([
("DATA_CLEANER", DataCleaner(demo='HH_F', mode='strict')),
("DATA_ENCODING", Encoder(encoder_name='code')),
("SCALE", Normalizer(normalizer=NORMALIZE)),
("FEATURE_SELECTION", huber_feature_selector),
("MODELLING", xgb_1)
])
# set of our models
base_models = [glmnet_pipe, xgb1_pipe]
# using Stacker on top of those ones
StackingRegressor(
regressors=base_models,
meta_regressor=SVR()
)
但是,我还在R中使用forecast
包实现了一个管道。就Python的实现/重写速度而言,我的所有R结果都有点“独特”。
是否有将R代码合并到sklearn
的方法?
到目前为止,我看到了以下可能性:
import subprocess
CustomRModel = class():
def __init__(self, path, args):
self.path = path
self.args = args
self.cmd = ['RScript', self.path] + self.args
def fit(self, X, Y):
# call fit in R
subprocess.check_output(self.cmd, universal_newlines=True)
# read ouput of R.csv to Python dataframe
# pd.read_csv
return self
def predict(X):
# call predict in R
subprocess.check_output(self.cmd, universal_newlines=True)
# read ouput of R.csv to Python dataframe
# pd.read_csv
# calculate predict
return predict
以后使用该类作为Pipeline中的常规步骤。
或者你知道更酷的方法吗?