scala
/**
-
Created by tetsuya on 2017/03/08.
*/
import org.apache.spark.ml.classification.LogisticRegression
import org.apache.spark.sql.SparkSession
object HelloWorld {
def main(args: Array[String]){val spark = SparkSession
.builder()
.appName("Spark Sample App")
.getOrCreate()// Load training data
val training = spark.read.format("libsvm").load("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}") }
}
build.sbt
name := "test"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core" % "2.0.0",
"org.apache.spark" %% "spark-mllib" % "2.0.0",
"org.apache.spark" %% "spark-sql" % "2.0.0",
"com.databricks" %% "spark-csv" % "1.4.0"
)
assemblyMergeStrategy in assembly := {
case PathList("javax", "servlet", xs @ _) => MergeStrategy.first
case PathList(ps @ _) if ps.last endsWith ".properties" => MergeStrategy.first
case PathList(ps @ _) if ps.last endsWith ".xml" => MergeStrategy.first
case PathList(ps @ _) if ps.last endsWith ".types" => MergeStrategy.first
case PathList(ps @ _*) if ps.last endsWith ".class" => MergeStrategy.first
case "application.conf" => MergeStrategy.concat
case "unwanted.txt" => MergeStrategy.discard
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
}
assembly.sbt
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.12.0")