Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在sklearn管道中集成R代码?_Python_R_Scikit Learn_Time Series_Pipeline - Fatal编程技术网

Python 如何在sklearn管道中集成R代码?

Python 如何在sklearn管道中集成R代码?,python,r,scikit-learn,time-series,pipeline,Python,R,Scikit Learn,Time Series,Pipeline,我有一个复杂的方法,有单独的模型,上面有堆垛机。比如: # 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_

我有一个复杂的方法,有单独的模型,上面有堆垛机。比如:

# 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()
)
然而,我还使用
forecast
包在R中实现了一个管道。就实现/重写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
然后像管道中的常规步骤一样使用该类

或者你知道更酷的方法吗