Description

Make predictions based on model trained from AlsTrainBatchOp.

There are two types of predictions: 1) rating prediction: given user and item, predict the rating. 2) recommend prediction: given a list of users, recommend k items for each users.

Parameters

Name Description Type Required? Default Value
userCol User column name String
itemCol Item column name String
predictionCol Column name of prediction. String

Script Example

Code

  1. data = np.array([
  2. [1, 1, 0.6],
  3. [2, 2, 0.8],
  4. [2, 3, 0.6],
  5. [4, 1, 0.6],
  6. [4, 2, 0.3],
  7. [4, 3, 0.4],
  8. ])
  9. df_data = pd.DataFrame({
  10. "user": data[:, 0],
  11. "item": data[:, 1],
  12. "rating": data[:, 2],
  13. })
  14. df_data["user"] = df_data["user"].astype('int')
  15. df_data["item"] = df_data["item"].astype('int')
  16. data = dataframeToOperator(df_data, schemaStr='user bigint, item bigint, rating double', op_type='batch')
  17. als = AlsTrainBatchOp().setUserCol("user").setItemCol("item").setRateCol("rating") \
  18. .setNumIter(10).setRank(10).setLambda(0.01)
  19. predictor = AlsPredictBatchOp()\
  20. .setUserCol("user").setItemCol("item").setPredictionCol("predicted_rating")
  21. model = als.linkFrom(data)
  22. predictor.linkFrom(model, data).print()

Results

  1. user item rating predicted_rating
  2. 0 1 1 0.6 0.579622
  3. 1 2 2 0.8 0.766851
  4. 2 2 3 0.6 0.581079
  5. 3 4 1 0.6 0.574481
  6. 4 4 2 0.3 0.298500
  7. 5 4 3 0.4 0.382157