2
我有一个Spark(1.5.2)数据框和训练有素的RandomForestClassificationModel
。我可以很容易地得到数据并得到一个预测,但我想深入分析哪些边缘值是每个二进制分类场景中最常见的参与者。随机森林分析
在过去,我做了类似于RDD
的功能,通过自己计算预测来跟踪功能使用情况。在下面的代码中,我跟踪用于计算预测的特征列表。 DataFrame似乎并不像RDD
那样直截了当。
def predict(node:Node, features: Vector, path_in:Array[Int]) : (Double,Double,Array[Int]) =
{
if (node.isLeaf)
{
(node.predict.predict,node.predict.prob,path_in)
}
else
{
//track our path through the tree
val path = path_in :+ node.split.get.feature
if (node.split.get.featureType == FeatureType.Continuous)
{
if (features(node.split.get.feature) <= node.split.get.threshold)
{
predict(node.leftNode.get, features, path)
}
else
{
predict(node.rightNode.get, features, path)
}
}
else
{
if (node.split.get.categories.contains(features(node.split.get.feature)))
{
predict(node.leftNode.get, features, path)
}
else
{
predict(node.rightNode.get, features, path)
}
}
}
}
我想要做类似这样的代码什么的,而是针对每个特征向量我回所有功能/边缘值对的列表。请注意,在我的数据集中,所有功能都是分类的,并且在构建林时适当使用了仓设置。