shiba24 / learning2rank

Learning to rank with neuralnet - RankNet and ListNet
481 stars 141 forks source link

IndexError: list index out of range #19

Open Pryanic opened 5 years ago

Pryanic commented 5 years ago

I wrote the following code

import numpy as np

import utils, rank, regression

from rank import RankNet

Model = RankNet.RankNet()

X = np.array([[1, 2], [2, 3], [4, 5], [1, 3], [0, 0]]);
y = np.array([1, 2, 3, 4, 5]);
Model.fit(X, y);
Model.predict(X);

and got the next error, could you please help me with it

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/Users/igladush/opensource-projects/learning2rank/__init__.py", line 3, in <module>
    import utils, rank, regression
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/igladush/opensource-projects/learning2rank/rank/__init__.py", line 1, in <module>
    import ListNet, RankNet
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/igladush/opensource-projects/learning2rank/rank/ListNet.py", line 18, in <module>
    from learning2rank.utils import plot_result
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Users/igladush/opensource-projects/learning2rank/rank/../../learning2rank/__init__.py", line 11, in <module>
    Model.fit(X, y);
  File "/Users/igladush/opensource-projects/learning2rank/rank/../../learning2rank/rank/RankNet.py", line 123, in fit
    self.trainModel(train_X, train_y, validate_X, validate_y, n_iter)
  File "/Users/igladush/opensource-projects/learning2rank/rank/../../learning2rank/rank/RankNet.py", line 108, in trainModel
    train_ndcg = self.ndcg(y_train, train_score)
  File "/Users/igladush/opensource-projects/learning2rank/rank/../../learning2rank/rank/RankNet.py", line 84, in ndcg
    ideal_dcg += (2 ** y_true_sorted[i] - 1.) / np.log2(i + 2)
jaysinghr commented 5 years ago

@Pryanic did you found any solution of above error?

hi-kubo commented 5 years ago

@Anticsss This problem is due to the difference between the length of list and k. The k value must be less than or equal to the length of the list. (k<= len(list)) You need fix RankNet.py like this. line 110 train_ndcg = self.ndcg(y_train, train_score) line 111 test_ndcg = self.ndcg(y_test, test_score) ↓ line 110 train_ndcg = self.ndcg(y_train, train_score, len(y_train)) line 111 test_ndcg = self.ndcg(y_test, test_score, len(y_test))

jeongwhanchoi commented 3 years ago

@Anticsss This problem is due to the difference between the length of list and k. The k value must be less than or equal to the length of the list. (k<= len(list)) You need fix RankNet.py like this. line 110 train_ndcg = self.ndcg(y_train, train_score) line 111 test_ndcg = self.ndcg(y_test, test_score) ↓ line 110 train_ndcg = self.ndcg(y_train, train_score, len(y_train)) line 111 test_ndcg = self.ndcg(y_test, test_score, len(y_test))

is this right? this is not solution of above error...