我使用的是Spark
和pyspark
,我有一个pipeline
设置了一组StringIndexer
对象,用于将字符串列编码为索引列:
indexers = [StringIndexer(inputCol=column, outputCol=column + '_index').setHandleInvalid('skip')
for column in list(set(data_frame.columns) - ignore_columns)]
pipeline = Pipeline(stages=indexers)
new_data_frame = pipeline.fit(data_frame).transform(data_frame)
问题是,我需要在每个StringIndexer
对象装配好后得到它的标签列表。对于没有管道的单个列和单个StringIndexer
来说,这是一项简单的任务。在DataFrame
上安装索引器后,我可以访问labels
属性:
然而,当我使用管道时,这似乎是不可能的,或者至少我不知道如何做到这一点。在
所以我想我的问题归结为: 有没有一种方法可以访问索引过程中为每个单独列使用的标签?在
或者,在这个用例中,我将不得不放弃管道,例如遍历StringIndexer
对象列表并手动执行?)我相信这是可能的。不过,使用管道会更好)
示例数据和
Pipeline
:摘录自
^{pr2}$stages
:从已转换的
DataFrame
的元数据:相关问题 更多 >
编程相关推荐