Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
coderxiang committed Jun 3, 2015
1 parent d8616fd commit a0dae07
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions docs/ml-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,36 +191,22 @@ The following code illustrates how to load a sample dataset and use logistic reg

{% highlight scala %}

import scala.collection.mutable
import scala.language.reflectiveCalls

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.ml.{Pipeline, PipelineStage}
import org.apache.spark.ml.classification.{LogisticRegression, LogisticRegressionModel}
import org.apache.spark.ml.feature.StringIndexer
import org.apache.spark.ml.classification.LogisticRegression
import org.apache.spark.mllib.util.MLUtils
import org.apache.spark.sql.DataFrame

val regParam = 0.3
val elasticNetParam = 0.8
val tol = 1E-6
val dataPath = "data/mllib/sample_libsvm_data.txt"

println(s"LogisticRegressionExample with regParam $regParam and elasticNetParam $elasticNetParam")

// Load training and test data and cache it.
val training = MLUtils.loadLibSVMFile(sc, dataPath).toDF()
val training = MLUtils.loadLibSVMFile(sc, "data/mllib/sample_libsvm_data.txt").toDF()

val lor = new LogisticRegression()
.setRegParam(regParam)
.setElasticNetParam(elasticNetParam)
.setTol(tol)
.setRegParam(0.3)
.setElasticNetParam(0.8)
.setTol(1e-6)

// Fit the model
val lirModel = lor.fit(training)
val lorModel = lor.fit(training)

// Print the weights and intercept for logistic regression.
println(s"Weights: ${lirModel.weights} Intercept: ${lirModel.intercept}")
println(s"Weights: ${lorModel.weights} Intercept: ${lorModel.intercept}")

{% endhighlight %}

Expand Down

0 comments on commit a0dae07

Please sign in to comment.