title: Spark sample code not serializable
body: <p>I ran the sample code from spark tutorial. It works fine before but the second time I run it. It says it's not serializable.
  Here is the code</p>
  
  <pre><code>import org.apache.spark.mllib.tree.RandomForest
  import org.apache.spark.mllib.tree.model.RandomForestModel
  import org.apache.spark.mllib.util.MLUtils
  
  // Load and parse the data file.
  val data = MLUtils.loadLibSVMFile(sc, "/home/liushiqi9/spark-1.3.0-src/data/mllib/sample_libsvm_data.txt")
  // Split the data into training and test sets (30% held out for testing)
  val splits = data.randomSplit(Array(0.7, 0.3))
  val (trainingData, testData) = (splits(0), splits(1))
  
  // Train a RandomForest model.
  //  Empty categoricalFeaturesInfo indicates all features are continuous.
  val numClasses = 2
  val categoricalFeaturesInfo = Map[Int, Int]()
  val numTrees = 3 // Use more in practice.
  val featureSubsetStrategy = "auto" // Let the algorithm choose.
  val impurity = "gini"
  val maxDepth = 4
  val maxBins = 32
  
  val model = RandomForest.trainClassifier(trainingData, numClasses, categoricalFeaturesInfo,
    numTrees, featureSubsetStrategy, impurity, maxDepth, maxBins)
  
  // Evaluate model on test instances and compute test error
  val labelAndPreds = testData.map { point =&gt;
    val prediction = model.predict(point.features)
    (point.label, prediction)
  }
  val testErr = labelAndPreds.filter(r =&gt; r._1 != r._2).count.toDouble / testData.count()
  println("Test Error = " + testErr)
  println("Learned classification forest model:\n" + model.toDebugString)
  </code></pre>
  
  <p>It's from this Link:<a href="https://spark.apache.org/docs/latest/mllib-ensembles.html#random-forests" rel="nofollow">Random Forest</a></p>
  
  <p>The Logs look like this:</p>
  
  <pre><code>import org.apache.spark.mllib.tree.RandomForest
  import org.apache.spark.mllib.tree.model.RandomForestModel
  import org.apache.spark.mllib.util.MLUtils
  data: org.apache.spark.rdd.RDD[org.apache.spark.mllib.regression.LabeledPoint] = MapPartitionsRDD[735] at map at MLUtils.scala:98
  splits: Array[org.apache.spark.rdd.RDD[org.apache.spark.mllib.regression.LabeledPoint]] = Array(MapPartitionsRDD[736] at randomSplit at &lt;console&gt;:126, MapPartitionsRDD[737] at randomSplit at &lt;console&gt;:126)
  trainingData: org.apache.spark.rdd.RDD[org.apache.spark.mllib.regression.LabeledPoint] = MapPartitionsRDD[736] at randomSplit at &lt;console&gt;:126
  testData: org.apache.spark.rdd.RDD[org.apache.spark.mllib.regression.LabeledPoint] = MapPartitionsRDD[737] at randomSplit at &lt;console&gt;:126
  numClasses: Int = 2
  categoricalFeaturesInfo: scala.collection.immutable.Map[Int,Int] = Map()
  numTrees: Int = 3
  featureSubsetStrategy: String = auto
  impurity: String = gini
  maxDepth: Int = 4
  maxBins: Int = 32
  model: org.apache.spark.mllib.tree.model.RandomForestModel = 
  TreeEnsembleModel classifier with 3 trees
  
  org.apache.spark.SparkException: Task not serializable
      at org.apache.spark.util.ClosureCleaner$.ensureSerializable(ClosureCleaner.scala:315)
      at org.apache.spark.util.ClosureCleaner$.org$apache$spark$util$ClosureCleaner$$clean(ClosureCleaner.scala:305)
      at org.apache.spark.util.ClosureCleaner$.clean(ClosureCleaner.scala:132)
      at org.apache.spark.SparkContext.clean(SparkContext.scala:1891)
      at org.apache.spark.rdd.RDD$$anonfun$map$1.apply(RDD.scala:294)
      at org.apache.spark.rdd.RDD$$anonfun$map$1.apply(RDD.scala:293)
      at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:148)
      at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:109)
      at org.apache.spark.rdd.RDD.withScope(RDD.scala:286)
      at org.apache.spark.rdd.RDD.map(RDD.scala:293)
      at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.&lt;init&gt;(&lt;console&gt;:141)
  </code></pre>
  
  <p>I just don't understand why this task was just fine and then it didn't work.
  I didn't reinstall my spark or anything.
  Thanks!</p>