【问题标题】:PySpark - How to show what components are included in a Pipeline?PySpark - 如何显示管道中包含哪些组件?
【发布时间】:2021-03-20 05:31:27
【问题描述】:

在下面的代码中,PySpark 管道包含两个转换器。给定管道,如何打印出这两个转换器的名称?

from pyspark.ml.feature import (StringIndexer, OneHotEncoder)
from pyspark.ml import Pipeline
gender_indexer = StringIndexer(inputCol = 'Sex', outputCol = 'SexIndex')
gender_encoder = OneHotEncoder(inputCol='SexIndex', outputCol = 'SexVec')

pipeline = Pipeline(stages = [gender_indexer, gender_encoder])

【问题讨论】:

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


    【解决方案1】:

    pipeline.getStages() 将向您展示管道中的各个阶段:

    >>> pipeline.getStages()
    [StringIndexer_84633f93b8f6, OneHotEncoder_6a01b7a7cdc1]
    

    请注意,每个列表元素都是一个对象,而不是字符串。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-24
      • 2018-01-09
      • 1970-01-01
      • 2023-01-30
      • 1970-01-01
      • 1970-01-01
      • 2017-06-25
      • 2021-07-06
      相关资源
      最近更新 更多