Skip to content

Instantly share code, notes, and snippets.

@bgweber
Created January 21, 2019 01:58
Show Gist options
  • Save bgweber/fa83328b2f1efea98597141d1c77dbfe to your computer and use it in GitHub Desktop.
Save bgweber/fa83328b2f1efea98597141d1c77dbfe to your computer and use it in GitHub Desktop.
# linear regresion with Spark
from pyspark.ml.regression import LinearRegression
# linear regression
lr = LinearRegression(maxIter=10, regParam=0.1,
elasticNetParam=0.5, labelCol="target")
# Fit the model
model = lr.fit(boston_train)
boston_pred = model.transform(boston_test)
# calculate results
r = boston_pred.stat.corr("prediction", "target")
print("R-sqaured: " + str(r**2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment