【发布时间】:2016-03-06 00:05:02
【问题描述】:
我正在研究Classification,在Spark 中使用Random Forest 算法有一个示例dataset,如下所示:
Level1,Male,New York,New York,352.888890
Level1,Male,San Fransisco,California,495.8001345
Level2,Male,New York,New York,-495.8001345
Level1,Male,Columbus,Ohio,165.22352099
Level3,Male,New York,New York,495.8
Level4,Male,Columbus,Ohio,652.8
Level5,Female,Stamford,Connecticut,495.8
Level1,Female,San Fransisco,California,495.8001345
Level3,Male,Stamford,Connecticut,-552.8234
Level6,Female,Columbus,Ohio,7000
这里每行中的最后一个值将用作label,其余的用作features。但我想将label 视为一个类别而不是一个数字。所以165.22352099 将表示一个类别,-552.8234 也是如此。为此,我将features 和label 编码为分类数据。现在我遇到的困难是在SparkMlLib 中决定Random Forest 算法中的numClasses 参数应该传递什么?我的意思是它应该等于我的label 中唯一值的数量吗?我的标签有 10000 这样的唯一值,所以如果我将 10000 设置为 numClasses 的值,那么它不会显着降低性能吗?
这是在 MlLib 中为随机森林构建模型的典型签名:
model = RandomForest.trainClassifier(trainingData, numClasses=2, categoricalFeaturesInfo={},
numTrees=3, featureSubsetStrategy="auto",
impurity='gini', maxDepth=4, maxBins=32)
【问题讨论】:
标签: machine-learning classification pyspark random-forest apache-spark-mllib