当前位置: 首页>>代码示例>>Python>>正文


Python DecisionTreeModel.predict方法代码示例

本文整理汇总了Python中pyspark.mllib.tree.DecisionTreeModel.predict方法的典型用法代码示例。如果您正苦于以下问题:Python DecisionTreeModel.predict方法的具体用法?Python DecisionTreeModel.predict怎么用?Python DecisionTreeModel.predict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyspark.mllib.tree.DecisionTreeModel的用法示例。


在下文中一共展示了DecisionTreeModel.predict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_probs_classify

# 需要导入模块: from pyspark.mllib.tree import DecisionTreeModel [as 别名]
# 或者: from pyspark.mllib.tree.DecisionTreeModel import predict [as 别名]
def get_probs_classify (model, data):
    # Collect the individual decision trees as JavaArray objects
    trees = model._java_model.trees()
    ntrees = model.numTrees()
    scores = DecisionTreeModel(trees[0]).predict(data)

    # For each tree, apply its prediction to the entire dataset and zip together the results
    for i in range(1,ntrees):
        dtm = DecisionTreeModel(trees[i])
        scores = scores.zip(dtm.predict(data))
        scores = scores.map(lambda x: x[0] + x[1])
    
    # Divide the accumulated scores over the number of trees
    return scores.map(lambda x: x/ntrees)
开发者ID:beatriceliang,项目名称:POPREU,代码行数:16,代码来源:stargalaxy.py

示例2: predict_proba

# 需要导入模块: from pyspark.mllib.tree import DecisionTreeModel [as 别名]
# 或者: from pyspark.mllib.tree.DecisionTreeModel import predict [as 别名]
def predict_proba(rf_model, testRDD):

        trees = rf_model._java_model.trees()
        ntrees = rf_model.numTrees()
        scores_dict = {i: 0 for i in range(0,10)}
        scoresRDD = testRDD.map(lambda x: scores_dict.copy())

        for tree in trees:
                dtm = DecisionTreeModel(tree)
                currentScoreRDD = dtm.predict(testRDD)
                scoresRDD = scoresRDD.zip(currentScoreRDD)

                def reduceTuple(x):
                        x[0][int(x[1])] += 1
                        return x[0]

                scoresRDD = scoresRDD.map(reduceTuple)
        return scoresRDD
开发者ID:Erin-Boehmer,项目名称:MIDS_tinytags,代码行数:20,代码来源:MLProcessing.py

示例3: predict_proba

# 需要导入模块: from pyspark.mllib.tree import DecisionTreeModel [as 别名]
# 或者: from pyspark.mllib.tree.DecisionTreeModel import predict [as 别名]
def predict_proba(rf_model, data):
    '''
    This wrapper overcomes the "binary" nature of predictions in the native
    RandomForestModel.
    '''  # Collect the individual decision tree models by calling the underlying
    # Java model. These are returned as JavaArray defined by py4j.
    trees = rf_model._java_model.trees()
    ntrees = rf_model.numTrees()
    scores = DecisionTreeModel(trees[0]).predict(data.map(
        lambda row: [float(row.SearchID), float(row.AdID), float(row.Position), float(row.ObjectType),
                     float(row.HistCTR)]))

    # For each decision tree, apply its prediction to the entire dataset and
    # accumulate the results using 'zip'.
    for i in range(1, ntrees):
        dtm = DecisionTreeModel(trees[i])
        scores = scores.zip(dtm.predict(data.map(lambda row : [float(row.SearchID),float(row.AdID),float(row.Position),float(row.ObjectType),float(row.HistCTR)])))
        scores = scores.map(lambda x: x[0] + x[1])

    # Divide the accumulated scores over the number of trees
    return scores.map(lambda x: x / ntrees)
开发者ID:abhishek-ch,项目名称:evolveML,代码行数:23,代码来源:Predict.py


注:本文中的pyspark.mllib.tree.DecisionTreeModel.predict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。