Created
September 13, 2018 00:12
-
-
Save hyounggyu/a0c346cb3952318a244232a474f9efad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.spark.ml.classification.LogisticRegression | |
import org.apache.spark.ml.feature.VectorAssembler | |
import org.apache.spark.sql.SparkSession | |
object LogiReg extends App { | |
val spark = SparkSession | |
.builder() | |
.master("local[*]") | |
.appName("LogiReg") | |
.getOrCreate() | |
import spark.implicits._ | |
val df = spark.read | |
.format("csv") | |
.option("header", "false") | |
.option("inferSchema", "true") | |
.load("src/main/resources/breastcancer.csv") | |
val assembler = new VectorAssembler() | |
.setInputCols(Array("_c1", "_c2", "_c3", "_c4", "_c5", "_c6", "_c7", "_c8", "_c9")) | |
.setOutputCol("features") | |
val output = assembler.transform(df) | |
val training = output.withColumnRenamed("_c10", "label") | |
val lr = new LogisticRegression() | |
.setMaxIter(10) | |
.setRegParam(0.3) | |
.setElasticNetParam(0.8) | |
val lrModel = lr.fit(training) | |
println(s"Coffecients: ${lrModel.coefficientMatrix} Intercept: ${lrModel.interceptVector}") | |
val trainingSummary = lrModel.summary | |
val objectiveHistory = trainingSummary.objectiveHistory | |
println("objectiveHistory") | |
objectiveHistory.foreach(loss => println(loss)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment