Advertisement
JunkPile77

Untitled

Apr 29th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.29 KB | None | 0 0
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. import org.apache.spark.mllib.linalg._
  35. import org.apache.spark.mllib.regression._
  36. import org.apache.spark.mllib.evaluation._
  37. import org.apache.spark.mllib.tree._
  38. import org.apache.spark.mllib.tree.model._
  39. import org.apache.spark.mllib.rdd._
  40.  
  41. //download and prepare data
  42. val file =sc.textFile("processed.hungarian.data")
  43.  
  44.  
  45. val fileData = file.map{ x=> x.split(",")}
  46. val parsedData = fileData.map( x=> (if(x(0)=="?"){-1} else{x(0).toDouble},
  47.                         if(x(4)=="?"){-1} else{x(4).toDouble},
  48.                         if(x(13)=="?"){-1} else{x(13).toDouble}))
  49.  
  50. val data = val featurevector = Vectors.dense(x._1, x._2)
  51.         val featurevector = Vectors.dense(x._1, x._2)
  52.         val label = x._3
  53.         LabeledPoint(label, featurevector)
  54.         }
  55.  
  56. val categoricalfeatureinfo = Map[Int, Int] ()
  57. val model = DecisionTree.trainClassifier(data, 2, categoricalfeatureinfo, "gini", 7, 300 );
  58. //data taken in, how many possible outcomes for final result,           , algorithm, depth of tree, 100 is number of trees
  59.  
  60. //test
  61. val testData = Vectors.dense(32,201)
  62.  
  63. val prediction = model.predict(testData)
  64. //println("Model Tree : \n " + model.toDebugString)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement