Skip to content

Instantly share code, notes, and snippets.

@ajayborra
Last active November 5, 2018 20:00
Show Gist options
  • Save ajayborra/8e1d7332fe8334964fced5f0e0649c0a to your computer and use it in GitHub Desktop.
Save ajayborra/8e1d7332fe8334964fced5f0e0649c0a to your computer and use it in GitHub Desktop.
Linear Regression Model
//linear regression model
val lr = new LinearRegression().setLabelCol("medianHouseValue").setFeaturesCol("scaledFeatures")
.setMaxIter(100)
.setRegParam(0.3)
.setElasticNetParam(0.8)
// Using Training set for model building
val lrModel = lr.fit(split(0))
// Print the coefficients and intercept for linear regression
println(s"Coefficients: ${lrModel.coefficients} Intercept: ${lrModel.intercept}")
// Summarize the model over the training set and print out some metrics
val trainingSummary = lrModel.summary
println(s"numIterations: ${trainingSummary.totalIterations}")
println(s"objectiveHistory: [${trainingSummary.objectiveHistory.mkString(",")}]")
trainingSummary.residuals.show()
println(s"RMSE: ${trainingSummary.rootMeanSquaredError}")
println(s"r2: ${trainingSummary.r2}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment