我已成功加载 sklearn 模型,但无法对 pyspark 数据帧进行预测。运行下面给定的代码时,出现下面提到的错误。请帮助我获取在 pyspark 上使用 sklearn 模型进行预测的代码。我也搜索过相关问题,但没有找到解决方案。
sc = spark.sparkContext
braodcast_model = sc.broadcast(loaded_model)
braodcast_model.value
#update prediction method
def predictor(cols):
#call predict method for model
return model.value.predict(*cols)
udf_predictor = udf(predictor, FloatType())
#apply the udf to dataframe
df_prediction = df.withColumn("prediction", udf_predictor(df.select(list_of_columns)))
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息
TypeError: Invalid argument, not a string or column. For column literals, use 'lit', 'array',
'struct' or 'create_map' function.
Run Code Online (Sandbox Code Playgroud)