Py学习  »  机器学习算法

在spark中创建n个机器学习模型,并行化[复制]

Ryan • 4 年前 • 529 次点击  

所以我已经尝试了几天在Spark的map函数中运行ML算法我发布了一个更具体的 question 但是引用Spark的ML算法会产生以下错误:

AttributeError: Cannot load _jvm from SparkContext. Is SparkContext initialized?

显然我不能引用 SparkContext 在里面 apply_classifier 功能。 我的代码与上一个问题中的建议类似,但仍然没有找到解决我所寻找的问题的方法:

def apply_classifier(clf):
    dt = DecisionTreeClassifier(labelCol="indexedLabel", featuresCol="indexedFeatures", maxDepth=3)
    if clf == 0:
        clf = DecisionTreeClassifier(labelCol="indexedLabel", featuresCol="indexedFeatures", maxDepth=3)
    elif clf == 1:
        clf = RandomForestClassifier(labelCol="indexedLabel", featuresCol="indexedFeatures", numTrees=5)

classifiers = [0, 1]

sc.parallelize(classifiers).map(lambda x: apply_classifier(x)).collect() 

我试过用 flatMap 而不是 map 但我知道 NoneType object is not iterable .

我还想在 应用分类器 功能。 最后,有可能做我想做的事吗?有哪些选择?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/48378
 
529 次点击