微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么 apache spark ALS 没有给出与我的输入相似的评级?

如何解决为什么 apache spark ALS 没有给出与我的输入相似的评级?

当用一个小矩阵尝试 apache spark 的交替最小二乘法时,所有的评分都在 0-1 之间,有时略高于 1。像这样:

Predictions for user 1:
    Product: 0,rating: 0.9907378275132337
    Product: 3,rating: 0.9894800004944013
    Product: 2,rating: 0.9467786142665756
    Product: 1,rating: 0.3263834039084612

但是,我的带有隐式数据的测试输入矩阵如下所示(我稍后将使用的实际大数据将具有相似的值):

double[][] interestMatrix = {{100,100,0},{50,5,70},50,{1,0.0},{5,0}};

我认为这些评级会给我一个类似于我的interestMatrix(大约1-100)的分数,但它似乎根本没有这样做。这是我的代码

public List<rating> setupratingList() {
    List<rating> ratings = new ArrayList<rating>();
    for (int i = 0; i < interestMatrix.length; i++) {
        for (int j = 0; j < interestMatrix[i].length; j++) {
            ratings.add(new rating(i,j,interestMatrix[i][j]));
        }
    }
    return ratings;
}

public void calculatealternatingLeastSquare(int maxIterations,double confidence,double regularization,int rank) {
    this.rdd = sparkContext.parallelize(setupratingList());
    this.ratings = sparkSession.createDataFrame(this.rdd,rating.class);

    ALS als = new ALS();
    als.setRank(rank)
            .setImplicitPrefs(true)
            .setLambda(regularization)
            .setIterations(maxIterations)
            .setAlpha(confidence);
    this.featureModel = als.run(this.rdd);
}

public void checkRecommendation() {
    interestMatrix = {{100,0}};

    calculatealternatingLeastSquare(10,0.5,10);
    rating[] ratings = this.featureModel.recommendProducts(1,4);

    for (rating rating : ratings) {
        System.out.println("Product: " + rating.product() + ",rating: " + rating.rating());
    }
}

此外,如果我将 interestMatrix 中的所有值除以 100,评级也会给出类似的行为。我不明白,因为我认为 ALS 试图通过矩阵分解来接近原始矩阵?
此外,为什么在上面的预测列表中对产品 1 的评价如此之低?用户 1 在矩阵中是 {50,70} ,就像我刚才说的,我认为 ALS 试图接近原始矩阵,但是当它试图接近这些条目的零时,你如何预测产品?就像它给了产品 1 0.326 而产品 2 有 0.946 即使产品 2 的原始评分仅为 5(相对于其他评分较低)并且产品 1 似乎受到更多其他用户的评价。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。