I trained a random forest algorithm with Python and would like to apply it on a big dataset with PySpark.
I first loaded the trained sklearn RF model (with joblib), loaded my data that contains the features into a Spark dataframe and then I add a column with the predictions, with a user-defined function like that:
def predictClass(features):
return rf.predict(features)
udfFunction = udf(predictClass, StringType())
new_dataframe = dataframe.withColumn('prediction',
udfFunction('features'))
It takes so much time to run though, is there a more efficient way to do the same thing? (without using Spark ML)