librec icon indicating copy to clipboard operation
librec copied to clipboard

how do I output the predict results only in the testset

Open danyang-liu opened this issue 6 years ago • 11 comments

I use BPR. I want to get the predict results for the u-i pairs in testset. But the results in ./result/ is the top_n item_rating for these users, not the items I want to predict.

danyang-liu avatar Oct 14 '18 14:10 danyang-liu

After training, You can run the predict(int userIdx, itemIdx) function with the testMatrix.

    // after training
    for (MatrixEntry me : testMatrix) {
        int userIdx = me.row(); // user
        int itemIdx = me.column(); // item
        double predictRating = predict(userIdx, itemIdx);
    }

SunYatong avatar Oct 19 '18 09:10 SunYatong

Can predict() be run form command line?

ran88dom99 avatar Oct 21 '18 14:10 ran88dom99

Hi SunYatong: Thanks, I will try.

danyang-liu avatar Oct 22 '18 08:10 danyang-liu

Can we predict values for a test set from the command line?

mvijaikumar avatar Feb 08 '19 12:02 mvijaikumar

Can we predict values for a test set from the command line? That is, instead of storing predicted values for training data or top-N values among the whole item set (in case of ranking based recommendation algorithm), can we store predicted values of a given test set from command line?

mvijaikumar avatar Feb 08 '19 12:02 mvijaikumar

@mvijaikumar Command line doesn't support this. You can denote the test set before training with TestSetSplitter, and add the code after training.

    // after training
    for (MatrixEntry me : testMatrix) {
        int userIdx = me.row(); // user
        int itemIdx = me.column(); // item
        double predictRating = predict(userIdx, itemIdx);
    }

SunYatong avatar Feb 11 '19 01:02 SunYatong

@SunYatong Thank you for your response. I am facing a peculiar problem in doing so as described above. If (userid, itemid) pair is not a part of a training set, and part of a test set (for obvious reason), testMatrix does not contain that pair.

I tested this on PMFRecommender. I could not understand why it is happening. Can you help me out?

mvijaikumar avatar Feb 11 '19 11:02 mvijaikumar

So you want to get the prediction of arbitrary user-item pairs? @mvijaikumar

SunYatong avatar Feb 11 '19 12:02 SunYatong

I want to predict rating for user and item that is part of training set, however, the exact pair is not a part of training set. That is, user is part of training set, itme is part of training set.

On Mon, Feb 11, 2019, 17:45 SunYatong <[email protected] wrote:

So you want to get the prediction of arbitrary user-item pairs?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/guoguibing/librec/issues/280#issuecomment-462307537, or mute the thread https://github.com/notifications/unsubscribe-auth/AeROdZSWIathgc6vjU4ZVqZ5Ud9tg48Oks5vMV74gaJpZM4XbJ9G .

mvijaikumar avatar Feb 11 '19 12:02 mvijaikumar

I want to predict rating for user and item that is part of training set, however, the exact pair is not a part of training set. That is, user is part of training set, item is part of training set.

On Mon, Feb 11, 2019, 17:45 SunYatong <[email protected] wrote:

So you want to get the prediction of arbitrary user-item pairs?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/guoguibing/librec/issues/280#issuecomment-462307537, or mute the thread https://github.com/notifications/unsubscribe-auth/AeROdZSWIathgc6vjU4ZVqZ5Ud9tg48Oks5vMV74gaJpZM4XbJ9G .

mvijaikumar avatar Feb 11 '19 12:02 mvijaikumar

So you do want to get the prediction of arbitrary user-item pairs... @mvijaikumar

Just use

 predict(userIdx, itemIdx)

SunYatong avatar Feb 12 '19 01:02 SunYatong