def train(self, userFeatureTable, ratingsMat):
userFeatureTable.loc[:, "age"] = userFeatureTable.loc[:, "age"] / 10.
# ad hoc fix, make sure feature's range is similar
self.knnModel = NearestNeighbors(n_neighbors=10, algorithm='ball_tree').fit(userFeatureTable)
# ratingMat is the rating matrix
self.ratingsMat = ratingsMat
self.userFeatureTable = userFeatureTable
self.userIds = self.userFeatureTable.index # the actual order seen by the knnmodel
评论列表
文章目录