Skip to content

Instantly share code, notes, and snippets.

@kshirsagarsiddharth
Created June 23, 2021 16:47
Show Gist options
  • Save kshirsagarsiddharth/1f1f0e530a643ad3c4d3c81ccb18b4af to your computer and use it in GitHub Desktop.
Save kshirsagarsiddharth/1f1f0e530a643ad3c4d3c81ccb18b4af to your computer and use it in GitHub Desktop.
from pyspark.ml.recommendation import ALS
from pyspark.ml.evaluation import RegressionEvaluator
training, test = indexed.randomSplit([0.8,0.1])
als = ALS(maxIter = 10 ,
regParam = 0.9,
userCol = "user_id",
itemCol = "isbn_indexed",
ratingCol = "book_rating",
nonnegative = True,
coldStartStrategy = 'drop')
model = als.fit(training)
from pyspark.ml.evaluation import RegressionEvaluator
predictions = model.transform(test)
evaluator = RegressionEvaluator(metricName = 'rmse', labelCol = 'book_rating', predictionCol = "prediction")
rmse = evaluator.evaluate(predictions)
print("Root mean squared error: ",rmse)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment