Apache Spark,文档中的ALS推荐示例有一个额外的列,我不知道它的用途



在ALS示例中,我有以下代码:

(http://spark.apache.org/docs/latest/ml-collaborative-filtering.html)

from pyspark.ml.evaluation import RegressionEvaluator
from pyspark.ml.recommendation import ALS
from pyspark.sql import Row
lines = spark.read.text("data/mllib/als/sample_movielens_ratings.txt").rdd
parts = lines.map(lambda row: row.value.split("::"))
ratingsRDD = parts.map(lambda p: Row(userId=int(p[0]), movieId=int(p[1]),
                                     rating=float(p[2]), timestamp=long(p[3])))
ratings = spark.createDataFrame(ratingsRDD)
(training, test) = ratings.randomSplit([0.8, 0.2])
# Build the recommendation model using ALS on the training data
als = ALS(maxIter=5, regParam=0.01, userCol="userId", itemCol="movieId", ratingCol="rating")
model = als.fit(training)
# Evaluate the model by computing the RMSE on the test data
predictions = model.transform(test)
evaluator = RegressionEvaluator(metricName="rmse", labelCol="rating", predictionCol="prediction")
rmse = evaluator.evaluate(predictions)
print("Root-mean-square error = " + str(rmse))

如果你看到它使用属性时间戳创建行,但随后在 ALS 创建

中使用它。

行中属性时间戳的用途是什么?

None。它只是MovieLens数据附带的字段之一。对于ALS,它没有用,你可以忽略它。

相关内容

最新更新