Build RMSE evaluator
Now that you know how to fit a model to training data and generate test predictions, you need a way to evaluate how well your model performs. For this we'll build an evaluator. Evaluators in Spark can be built out in various ways. For our purposes, we want a regressionEvaluator that calculates the RMSE. After we build our regressionEvaluator, we can fit the model to our data and generate predictions.
Diese Übung ist Teil des Kurses
Building Recommendation Engines with PySpark
Anleitung zur Übung
- Import the required
RegressionEvaluatorpackage from thepyspark.ml.evaluationclass. - Complete the
evaluatorcode, specifying themetric nameto be"rmse". Set thelabelColto the name of the column in ourratingsdata that contains our ratings (use theratings.columnsmethod to see column names) and set thepredictioncolumn name to"prediction". - Confirm that the
evaluatorwas properly created by extracting each of the three parameters from it. Do this by running the following 3 lines of code, each within a print statement:evaluator.getMetricName()evaluator.getLabelCol()evaluator.getPredictionCol()
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Import RegressionEvaluator
from pyspark.ml.evaluation import ____
# Complete the evaluator code
evaluator = RegressionEvaluator(metricName="____", labelCol="____", predictionCol="____")
# Extract the 3 parameters
print(evaluator.get____())
print(evaluator.get____())
print(evaluator.get____())