spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From SK <>
Subject RandomForest in Pyspark (version 1.4.1)
Date Sat, 01 Aug 2015 01:36:24 GMT


I tried to develop a RandomForest model for my data in PySpark as follows:

       rf_model = RandomForest.trainClassifier(train_idf, 2, {},
numTrees=15, seed=144)
       print "RF: Num trees = %d, Num nodes = %d\n" %(rf_model.numTrees(),

       pred_label = p:
(float(rf_model.predict(p.features)), p.label))
       print pred_label.take(5)  ##--------> exception

I am  getting the following error at the highlighted statement.
         Exception: It appears that you are attempting to reference
SparkContext from a broadcast variable, action, or   transforamtion.
SparkContext can only be used on the driver, not in code that it run on
workers. For more information, see SPARK-5063.

 I have used the same set of statements for linear models
(LogisticRegresssion and SVM) in PySpark and was able to get the predictions
abd print them.  I am not sure why I am getting the above exception. I am
not using the SparkContenxt directly in any of the above statements. I would
appreciate your help. 


View this message in context:
Sent from the Apache Spark User List mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message