0
私はSparkの新機能です。SparkにJSONの入力を理解させようとしていますが、管理していません。要約すると、SparkのALSアルゴリズムを使用して推奨事項を提示しています。入力としてCSVファイルを提供すると、すべて正常に動作します。JSONとPythonのRDDをスパークする
all_user_recipe_rating = [{'rating': 1, 'recipe_id': 8798, 'user_id': 2108}, {'rating': 4, 'recipe_id': 6985, 'user_id': 4236}, {'rating': 4, 'recipe_id': 13572, 'user_id': 2743}, {'rating': 4, 'recipe_id': 6312, 'user_id': 3156}, {'rating': 1, 'recipe_id': 12836, 'user_id': 768}, {'rating': 1, 'recipe_id': 9237, 'user_id': 1599}, {'rating': 2, 'recipe_id': 16946, 'user_id': 2687}, {'rating': 2, 'recipe_id': 20728, 'user_id': 58}, {'rating': 4, 'recipe_id': 12921, 'user_id': 2221}, {'rating': 2, 'recipe_id': 10693, 'user_id': 2114}, {'rating': 2, 'recipe_id': 18301, 'user_id': 4898}, {'rating': 2, 'recipe_id': 9967, 'user_id': 3010}, {'rating': 2, 'recipe_id': 16393, 'user_id': 4830}, {'rating': 4, 'recipe_id': 14838, 'user_id': 583}]
ratings_RDD = self.spark.parallelize(all_user_recipe_rating)
ratings = ratings_RDD.map(lambda row:
(Rating(int(row['user_id']),
int(row['recipe_id']),
float(row['rating']))))
model = self.build_model(ratings)
これは、私はいくつかの例を見た後に思い付いたものですが、これは私が得るものです::しかし、次のように私の入力は、JSONは、実際にある
MatrixFactorizationModel: User factor is not cached. Prediction could be slow.
16/12/21 03:54:53 WARN MatrixFactorizationModel: Product factor does not have a partitioner. Prediction on individual records could be slow.
16/12/21 03:54:53 WARN MatrixFactorizationModel: Product factor is not cached. Prediction could be slow.
16/12/21 03:54:53 WARN MatrixFactorizationModelWrapper: User factor does not have a partitioner. Prediction on individual records could be slow.
そして
File "/usr/local/spark/python/pyspark/mllib/recommendation.py", line 147, in <lambda>
user_product = user_product.map(lambda u_p: (int(u_p[0]), int(u_p[1])))
TypeError: int() argument must be a string or a number, not 'Rating'
誰かが私に手を差し伸べることができますか? :)ありがとう!