Created
June 23, 2021 16:47
-
-
Save kshirsagarsiddharth/1f1f0e530a643ad3c4d3c81ccb18b4af to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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