implicit icon indicating copy to clipboard operation
implicit copied to clipboard

Index error during evaluation

Open nicolaneo opened this issue 6 years ago • 2 comments

Hello! I am trying to run evaluation for parameter optimisation using mean average precision at k. I'm using a smaller version of the lastfm dataset, with 88,212 artists and 46,150 users. (m, n) = (88212, 46150). The train and test are csr matrices of size (88212, 46150), both with zeros eliminated. I run the following:

grid = ParameterGrid({"factors": [10, 20, 30, 40, 50, 60, 70],
                      "regularization":[0.01, 0.1, 1, 10, 20, 30, 40],
                      "iterations":[10, 20, 30, 40]})

 for params in grid:
     model = implicit.als.AlternatingLeastSquares(**params)
     model.fit(train)
     map_= implicit.evaluation.mean_average_precision_at_k(model, train_user_items=train, test_user_items=test, K=10, show_progress = True, num_threads=0)
     print(str(map_) + " for params " + str(params))

And get the following IndexError:

    map_= implicit.evaluation.mean_average_precision_at_k(model, train_user_items=train, test_user_items=test, K=10, show_progress = True, num_threads=0)

  File "implicit/evaluation.pyx", line 113, in implicit.evaluation.mean_average_precision_at_k

  File "implicit/evaluation.pyx", line 251, in implicit.evaluation.ranking_metrics_at_k

  File "implicit/recommender_base.pyx", line 162, in implicit.recommender_base.MatrixFactorizationBase.recommend

  File "implicit/recommender_base.pyx", line 309, in implicit.recommender_base.MatrixFactorizationBase._user_factor

IndexError: index 46153 is out of bounds for axis 0 with size 46150

I'm just not sure why there is an index error when the test and train matrices are the same size?

Thanks in advance

nicolaneo avatar Nov 19 '20 11:11 nicolaneo

Duplicate of #425

Looks like the same dimensions inconsistency issue

LorenzoMinto avatar Jan 29 '21 14:01 LorenzoMinto

For some reason all the evaluation metrics functions take "user by item" sparse matrices, you only need to .transpose() the matrices you already have.

map_= implicit.evaluation.mean_average_precision_at_k(model, train_user_items=train.transpose(), test_user_items=test.transpose(), K=10, show_progress = True, num_threads=0)

This should do it.

LorenzoMinto avatar Jan 29 '21 14:01 LorenzoMinto