我有一个pyspark 2.0.0脚本,定义了以下会话:
TypeError: sc should be a SparkContext, got type <class 'pyspark.sql.session.SparkSession'>
我训练了一个随机的森林模型,我想保存它。因此我调用以下方法:
from pyspark import SparkContext
sc =SparkContext()
model_rf.save( sc, "/home/Desktop")
但它会引发以下编译错误:
Cannot run multiple SparkContexts at once; existing SparkContext(app=Python Spark, master=local[*]) created by getOrCreate at <ipython-input-1-c5f83810f880>:24
当我定义Spark上下文时,如下所示:
{{1}}
我收到错误:
{{1}}
答案 0 :(得分:4)
使用spark.sparkContext
(SparkSession
对象将sparkContext
)
model_rf.save( spark.sparkContext, "/home/Desktop")