【问题标题】:Add new fitted stage to a exitsting PipelineModel without fitting again将新的拟合阶段添加到现有 PipelineModel 而无需再次拟合
【发布时间】:2019-04-15 13:58:10
【问题描述】:

我想将几个经过训练的管道连接到一个,这类似于 "Spark add new fitted stage to a exitsting PipelineModel without fitting again" 但是下面的解决方案适用于 PySpark。

> pipe_model_new = PipelineModel(stages = [pipe_model , pipe_model2])
> final_df = pipe_model_new.transform(df1)

在 Apache Spark 2.0 中,“PipelineModel”的构造函数被标记为私有,因此不能在外部调用。在“Pipeline”类中,只有“fit”方法创建“PipelineModel”

val pipelineModel =  new PipelineModel("randomUID", trainedStages)
val df_final_full = pipelineModel.transform(df)
Error:(266, 26) constructor PipelineModel in class PipelineModel cannot be accessed in class Preprocessor
    val pipelineModel =  new PipelineModel("randomUID", trainedStages)

【问题讨论】:

    标签: apache-spark pipeline apache-spark-ml apache-spark-2.0


    【解决方案1】:

    with using Pipeline 和调用 fit 方法没有任何问题*。如果一个阶段是Transfomer,而PipelineModel 是**,则fit 的作用类似于身份。

    您可以查看relevant Python:

    if isinstance(stage, Transformer):
        transformers.append(stage)
        dataset = stage.transform(dataset)
    

    Scala code:

    这意味着拟合过程只会验证架构并创建一个新的PipelineModel 对象。

    case t: Transformer =>
      t
    

    * 唯一可能的问题是存在非惰性Transformers,但是,除了已弃用的OneHotEncoder,Spark 核心 API 不提供此类。

    ** 在 Python 中:

    from pyspark.ml import Transformer, PipelineModel
    
    issubclass(PipelineModel, Transformer)
    
    True 
    

    在 Scala 中

    import scala.reflect.runtime.universe.typeOf
    import org.apache.spark.ml._
    
    typeOf[PipelineModel] <:< typeOf[Transformer]
    
    Boolean = true
    

    【讨论】:

    • 我不明白你是如何解决这个问题的。有什么实现val pipelineModel = new PipelineModel("randomUID", trainedStages)的例子吗?
    • 因为我有类似的问题stackoverflow.com/questions/69891877/…
    猜你喜欢
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    • 2015-12-26
    • 2020-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多