我的程序已经使用 pyspark.ml 包中的 CountVectorizer 运行良好。但是,这个 CountVectorizer 没有像 sklearn.feature_extraction.text 包中的 CountVectorizer 那样的 maxDF 参数,它删除了在文档列表中出现过于频繁的术语。有什么方法可以将其应用于 pyspark.ml 包中的 CountVectorizer?
请您参考如下方法:
maxDF Param 已包含在 Spark 2.4.0 中(尚未正式发布,但已可从 PyPi 和 Apache Foundation 文件中获取):
- SPARK-23166 - 将 maxDF 参数添加到 CountVectorizer
- SPARK-23615 - 将 maxDF 参数添加到 Python CountVectorizer
和can be used as any other Param :
from pyspark.ml.feature import CountVectorizer
vectorizer = CountVectorizer(maxDF=99)
或
vectorizer = CountVectorizer().setMaxDF(99)
要使用它,您必须将 Spark 更新到 2.4.0 或更高版本,或者向后移植相应的 PR 和 build Spark from source .
