Last active
November 5, 2018 20:00
-
-
Save ajayborra/8e1d7332fe8334964fced5f0e0649c0a to your computer and use it in GitHub Desktop.
Linear Regression Model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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