Skip to content

Instantly share code, notes, and snippets.

@naiborhujosua
Created October 26, 2020 15:35
Show Gist options
  • Save naiborhujosua/232f07e4849e945a5aec0e61325a6e00 to your computer and use it in GitHub Desktop.
Save naiborhujosua/232f07e4849e945a5aec0e61325a6e00 to your computer and use it in GitHub Desktop.
# For loop will automatically create and store ALS models
for r in ranks:
for mi in maxIters:
for rp in regParams:
for a in alphas:
model_list.append(ALS(userCol= "userId", itemCol= "songId", ratingCol= "num_plays", rank = r, maxIter = mi, regParam = rp, alpha = a, coldStartStrategy="drop", nonnegative = True, implicitPrefs = True))
# Print the model list, and the length of model_list
print (model_list, "Length of model_list: ", len(model_list))
# Validate
len(model_list) == (len(ranks)*len(maxIters)*len(regParams)*len(alphas))
@naiborhujosua
Copy link
Author

Now that you have all of your hyperparameter values specified, let's have Spark build enough models to test each combination. To facilitate this, a for loop is provided here. Follow the instructions below to automatically create these ALS models. In subsequent exercises you will run these models on test datasets to see which one performs the best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment