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)
}
}
}
}
我想要做類似這樣的代碼什麼的,而是針對每個特徵向量我回所有功能/邊緣值對的列表。請注意,在我的數據集中,所有功能都是分類的,並且在構建林時適當使用了倉設置。