Pyspark TypeError:在Spark MLlib中使用OneHotEncoder时,无法调用“列”对象

2024-09-27 00:17:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我是pyspark和ApacheSpark机器学习库的新手。 我正在尝试将OneHotEncoder应用于Spark MLlib中的几个分类列。 首先我使用了stringIndexer,它可以工作

categoricalColumns是数据集中我的分类列的列表

stringIndexer = StringIndexer(
    inputCols=[categoricalCol for categoricalCol in categoricalColumns],
    outputCols=[categoricalCol + "_index" for categoricalCol in categoricalColumns]
)
mod_si = stringIndexer.fit(spark_df)
indexed_si = mod_si.transform(spark_df)
indexed_si.printSchema()

下一个热编码器

encoder = OneHotEncoder(
    inputCols=[indexer.getOutputCol() for indexer in indexed_si],
    outputCols=["_encoded".format(indexer.getOutputCol()) for indexer in indexed_si]
)

我不断地发现这个错误:

TypeError: 'Column' object is not callable

我读了编程指南,但我还不能解决它。任何帮助都将不胜感激

https://spark.apache.org/docs/latest/ml-features.html#onehotencoder

多谢各位


Tags: inmoddffor分类indexedsparkindexer

热门问题