Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // we run marksDf on the pipeline, so split marksDf
- val Array(pipelineTrainingData, pipelineTestingData) = creditDf.randomSplit(Array(0.7, 0.3), seed)
- // VectorAssembler and StringIndexer are transformers
- // LogisticRegression is the estimator
- val stages = Array(assembler, indexer, randomForestClassifier)
- // build pipeline
- val pipeline = new Pipeline().setStages(stages)
- val pipelineModel = pipeline.fit(pipelineTrainingData)
- // test model with test data
- val pipelinePredictionDf = pipelineModel.transform(pipelineTestingData)
- pipelinePredictionDf.show(10)
- /*
- * output
- +-------------+-------+--------+-------+-------+------+-------+----------+-----------+----------+----------+-----------------+------+---+----------+---------+-------+----------+----------+--------+-------+--------------------+-----+--------------------+--------------------+----------+
- |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|
- +-------------+-------+--------+-------+-------+------+-------+----------+-----------+----------+----------+-----------------+------+---+----------+---------+-------+----------+----------+--------+-------+--------------------+-----+--------------------+--------------------+----------+
- | 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|
- | 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|
- | 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|
- | 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|
- | 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|
- | 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|
- | 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|
- | 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|
- | 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|
- | 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|
- +-------------+-------+--------+-------+-------+------+-------+----------+-----------+----------+----------+-----------------+------+---+----------+---------+-------+----------+----------+--------+-------+--------------------+-----+--------------------+--------------------+----------+
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement