Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. // we run marksDf on the pipeline, so split marksDf
  2. val Array(pipelineTrainingData, pipelineTestingData) = creditDf.randomSplit(Array(0.7, 0.3), seed)
  3.  
  4. // VectorAssembler and StringIndexer are transformers
  5. // LogisticRegression is the estimator
  6. val stages = Array(assembler, indexer, randomForestClassifier)
  7.  
  8. // build pipeline
  9. val pipeline = new Pipeline().setStages(stages)
  10. val pipelineModel = pipeline.fit(pipelineTrainingData)
  11.  
  12. // test model with test data
  13. val pipelinePredictionDf = pipelineModel.transform(pipelineTestingData)
  14. pipelinePredictionDf.show(10)
  15. /*
  16. * output
  17. +-------------+-------+--------+-------+-------+------+-------+----------+-----------+----------+----------+-----------------+------+---+----------+---------+-------+----------+----------+--------+-------+--------------------+-----+--------------------+--------------------+----------+
  18. |creditability|balance|duration|history|purpose|amount|savings|employment|instPercent|sexMarried|guarantors|residenceDuration|assets|age|concCredit|apartment|credits|occupation|dependents|hasPhone|foreign| features|label| rawPrediction| probability|prediction|
  19. +-------------+-------+--------+-------+-------+------+-------+----------+-----------+----------+----------+-----------------+------+---+----------+---------+-------+----------+----------+--------+-------+--------------------+-----+--------------------+--------------------+----------+
  20. | 0.0| 1.0| 6| 1| 6| 1198| 1| 5| 4| 2| 1| 4| 4| 35| 3| 3| 1| 3| 1| 1| 1|[1.0,6.0,1.0,6.0,...| 1.0|[10.7490734143103...|[0.53745367071551...| 0.0|
  21. | 0.0| 1.0| 6| 4| 2| 3384| 1| 3| 1| 1| 1| 4| 1| 44| 3| 1| 1| 4| 1| 2| 1|[1.0,6.0,4.0,2.0,...| 1.0|[15.7968574432531...|[0.78984287216265...| 0.0|
  22. | 0.0| 1.0| 9| 2| 3| 1366| 1| 2| 3| 2| 1| 4| 2| 22| 3| 1| 1| 3| 1| 1| 1|[1.0,9.0,2.0,3.0,...| 1.0|[12.1422936569444...|[0.60711468284722...| 0.0|
  23. | 0.0| 1.0| 12| 1| 0| 697| 1| 2| 4| 3| 1| 2| 3| 46| 1| 2| 2| 3| 1| 2| 1|[1.0,12.0,1.0,0.0...| 1.0|[9.73041760825665...|[0.48652088041283...| 1.0|
  24. | 0.0| 1.0| 12| 2| 4| 741| 2| 1| 4| 2| 1| 3| 2| 22| 3| 2| 1| 3| 1| 1| 1|[1.0,12.0,2.0,4.0...| 1.0|[10.6767838008722...|[0.53383919004361...| 0.0|
  25. | 0.0| 1.0| 18| 1| 0| 1442| 1| 4| 4| 3| 1| 4| 4| 32| 1| 3| 2| 2| 2| 1| 1|[1.0,18.0,1.0,0.0...| 1.0|[10.0807119629414...|[0.50403559814707...| 0.0|
  26. | 0.0| 1.0| 18| 2| 3| 3190| 1| 3| 2| 2| 1| 2| 1| 24| 3| 2| 1| 3| 1| 1| 1|[1.0,18.0,2.0,3.0...| 1.0|[11.9605710249254...|[0.59802855124627...| 0.0|
  27. | 0.0| 1.0| 18| 4| 2| 2124| 1| 3| 4| 2| 1| 4| 1| 24| 3| 1| 2| 3| 1| 1| 1|[1.0,18.0,4.0,2.0...| 1.0|[14.1539496952876...|[0.70769748476438...| 0.0|
  28. | 0.0| 1.0| 18| 4| 5| 1190| 1| 1| 2| 2| 1| 4| 4| 55| 3| 3| 3| 1| 2| 1| 1|[1.0,18.0,4.0,5.0...| 1.0|[14.1925605023117...|[0.70962802511558...| 0.0|
  29. | 0.0| 1.0| 20| 4| 0| 2235| 1| 3| 4| 4| 3| 2| 2| 33| 1| 1| 2| 3| 1| 1| 2|[1.0,20.0,4.0,0.0...| 1.0|[13.7055893085556...|[0.68527946542778...| 0.0|
  30. +-------------+-------+--------+-------+-------+------+-------+----------+-----------+----------+----------+-----------------+------+---+----------+---------+-------+----------+----------+--------+-------+--------------------+-----+--------------------+--------------------+----------+
  31. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement