1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| object EstimatorTransformerParamExam { def main(args: Array[String]): Unit = { val conf = new SparkConf().setAppName("EstimatorTransformerParamExam") conf.setMaster("local[4]") val sc = new SparkContext(conf) val spark = SparkSession.builder().getOrCreate() sc.setLogLevel("Error") val training = spark.createDataFrame(Seq( (1.0, Vectors.dense(0.0, 1.1, 0.1)), (0.0, Vectors.dense(2.0, 1.0, -1.0)), (0.0, Vectors.dense(2.0, 1.3, 1.0)), (1.0, Vectors.dense(0.0, 1.2, -0.5)) )).toDF("label", "features") training.show() val lr = new LogisticRegression() println("LogisticRegression parameters:\n" + lr.explainParams() + "\n") lr.setMaxIter(5) .setRegParam(0.01) val model1 = lr.fit(training) } }
|