【问题标题】:pyspark---randomForests specify categorical variables using "categoricalFeaturesInfo"pyspark---randomForests 使用“categoricalFeaturesInfo”指定分类变量
【发布时间】:2015-06-25 11:17:07
【问题描述】:

如何在 pyspark randomForests 中指定 categoricalFeaturesInfo?

文档对此不是很清楚,我尝试了一些类似的方法:

categoricalFeaturesInfo= {(12,4)}

categoricalFeaturesInfo= {(12->4)}

categoricalFeaturesInfo= {地图[int,int](12,4)}

... 等等,但它们都不起作用。非常感谢任何帮助。

【问题讨论】:

    标签: apache-spark categories random-forest decision-tree pyspark


    【解决方案1】:

    适用于 spark 2.0 及以上版本

    它是一本字典 以键作为 rdd(feature) 中变量的索引/位置 和值作为类别数

    【讨论】:

      【解决方案2】:

      从我们拥有的python文档中:

      categoricalFeaturesInfo: Map storing arity of categorical
                   features.  E.g., an entry (n -> k) indicates that
                   feature n is categorical with k categories indexed
                   from 0: {0, 1, ..., k-1}.
      

      尝试使用:

      categoricalFeaturesInfo = {12:4}
      

      【讨论】:

      • categoricalFeaturesInfo = {12:4}:也不工作
      • 我的错,我忘了这里的 python 索引从 0 开始......所以 categoricalFeaturesInfo = {11:4} 有效
      • 如何使用months 变量,类别从1 到12?如果months 是第一列:categoricalFeaturesInfo = {0:12} 将不起作用,因为它将查找 0 到 11 之间的类别!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-22
      • 1970-01-01
      • 2022-11-17
      • 2016-08-20
      • 2018-03-21
      • 1970-01-01
      • 2021-10-07
      相关资源
      最近更新 更多