Guest User

Untitled

a guest
Jul 22nd, 2019
82
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // columns that need to added to feature column
  2. val cols = Array("balance", "duration", "history", "purpose", "amount", "savings", "employment", "instPercent", "sexMarried",
  3. "guarantors", "residenceDuration", "assets", "age", "concCredit", "apartment", "credits", "occupation", "dependents", "hasPhone",
  4. "foreign")
  5.  
  6. // VectorAssembler to add feature column
  7. // input columns - cols
  8. // feature column - features
  9. val assembler = new VectorAssembler()
  10. .setInputCols(cols)
  11. .setOutputCol("features")
  12. val featureDf = assembler.transform(creditDf)
  13. featureDf.printSchema()
  14. /*
  15. *
  16. root
  17. |-- creditability: double (nullable = true)
  18. |-- balance: double (nullable = true)
  19. |-- duration: integer (nullable = true)
  20. |-- history: integer (nullable = true)
  21. |-- purpose: integer (nullable = true)
  22. |-- amount: integer (nullable = true)
  23. |-- savings: integer (nullable = true)
  24. |-- employment: integer (nullable = true)
  25. |-- instPercent: integer (nullable = true)
  26. |-- sexMarried: integer (nullable = true)
  27. |-- guarantors: integer (nullable = true)
  28. |-- residenceDuration: integer (nullable = true)
  29. |-- assets: integer (nullable = true)
  30. |-- age: integer (nullable = true)
  31. |-- concCredit: integer (nullable = true)
  32. |-- apartment: integer (nullable = true)
  33. |-- credits: integer (nullable = true)
  34. |-- occupation: integer (nullable = true)
  35. |-- dependents: integer (nullable = true)
  36. |-- hasPhone: integer (nullable = true)
  37. |-- foreign: integer (nullable = true)
  38. |-- features: vector (nullable = true)
  39. */
  40.  
  41. featureDf.show(10)
  42. /*
  43. * output
  44. +-------------+-------+--------+-------+-------+------+-------+----------+-----------+----------+----------+-----------------+------+---+----------+---------+-------+----------+----------+--------+-------+--------------------+
  45. |creditability|balance|duration|history|purpose|amount|savings|employment|instPercent|sexMarried|guarantors|residenceDuration|assets|age|concCredit|apartment|credits|occupation|dependents|hasPhone|foreign| features|
  46. +-------------+-------+--------+-------+-------+------+-------+----------+-----------+----------+----------+-----------------+------+---+----------+---------+-------+----------+----------+--------+-------+--------------------+
  47. | 1.0| 1.0| 9| 4| 0| 2799| 1| 3| 2| 3| 1| 2| 1| 36| 3| 1| 2| 3| 2| 1| 1|[1.0,9.0,4.0,0.0,...|
  48. | 1.0| 2.0| 12| 2| 9| 841| 2| 4| 2| 2| 1| 4| 1| 23| 3| 1| 1| 2| 1| 1| 1|[2.0,12.0,2.0,9.0...|
  49. | 1.0| 1.0| 12| 4| 0| 2122| 1| 3| 3| 3| 1| 2| 1| 39| 3| 1| 2| 2| 2| 1| 2|[1.0,12.0,4.0,0.0...|
  50. | 1.0| 1.0| 12| 4| 0| 2171| 1| 3| 4| 3| 1| 4| 2| 38| 1| 2| 2| 2| 1| 1| 2|[1.0,12.0,4.0,0.0...|
  51. | 1.0| 1.0| 10| 4| 0| 2241| 1| 2| 1| 3| 1| 3| 1| 48| 3| 1| 2| 2| 2| 1| 2|[1.0,10.0,4.0,0.0...|
  52. | 1.0| 1.0| 8| 4| 0| 3398| 1| 4| 1| 3| 1| 4| 1| 39| 3| 2| 2| 2| 1| 1| 2|[1.0,8.0,4.0,0.0,...|
  53. | 1.0| 1.0| 6| 4| 0| 1361| 1| 2| 2| 3| 1| 4| 1| 40| 3| 2| 1| 2| 2| 1| 2|[1.0,6.0,4.0,0.0,...|
  54. | 1.0| 4.0| 18| 4| 3| 1098| 1| 1| 4| 2| 1| 4| 3| 65| 3| 2| 2| 1| 1| 1| 1|[4.0,18.0,4.0,3.0...|
  55. | 1.0| 2.0| 24| 2| 3| 3758| 3| 1| 1| 2| 1| 4| 4| 23| 3| 1| 1| 1| 1| 1| 1|[2.0,24.0,2.0,3.0...|
  56. | 1.0| 1.0| 11| 4| 0| 3905| 1| 3| 2| 3| 1| 2| 1| 36| 3| 1| 2| 3| 2| 1| 1|[1.0,11.0,4.0,0.0...|
  57. +-------------+-------+--------+-------+-------+------+-------+----------+-----------+----------+----------+-----------------+------+---+----------+---------+-------+----------+----------+--------+-------+--------------------+
  58. */
RAW Paste Data