官术网_书友最值得收藏!

Logistic regression with Spark

We progress with logistic regression with Spark as follows:

import org.apache.spark.ml.classification.LogisticRegression

// Load training data
val training = spark.read.format("libsvm").load("data/mllib/sample_libsvm_data.txt")

val lr = new LogisticRegression()
  .setMaxIter(10)
  .setRegParam(0.3)
  .setElasticNetParam(0.8)

// Fit the model
val lrModel = lr.fit(training)

// Print the coefficients and intercept for logistic regression
println(s"Coefficients: ${lrModel.coefficients} Intercept: ${lrModel.intercept}")

// We can also use the multinomial family for binary classification
val mlr = new LogisticRegression()
  .setMaxIter(10)
  .setRegParam(0.3)
  .setElasticNetParam(0.8)
  .setFamily("multinomial")

val mlrModel = mlr.fit(training)

// Print the coefficients and intercepts for logistic regression with multinomial family
println(s"Multinomial coefficients: ${mlrModel.coefficientMatrix}")
println(s"Multinomial intercepts: ${mlrModel.interceptVector}")
主站蜘蛛池模板: 萨嘎县| 乐都县| 秦皇岛市| 苍梧县| 武宣县| 石阡县| 伊春市| 涞源县| 三明市| 定边县| 民权县| 原平市| 上思县| 通辽市| 绩溪县| 襄樊市| 安多县| 白城市| 东兴市| 顺平县| 平湖市| 田东县| 贺兰县| 会泽县| 阿克陶县| 本溪市| 襄汾县| 杭州市| 玉环县| 平湖市| 绍兴县| 定兴县| 昌平区| 乌苏市| 阿图什市| 宜良县| 东安县| 胶南市| 秦安县| 定结县| 郁南县|