Skip to content

Commit

Permalink
Fix ranking normalization for 0-based rankings
Browse files Browse the repository at this point in the history
This would previously fail due to a division by 0 if the ranking is
0-based and consists of only one object.
  • Loading branch information
timokau committed Sep 22, 2020
1 parent 50a662b commit 0f4ae0d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion csrank/dataset_reader/objectranking/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def complete_linear_regression_dataset(X, rankings):
Y_single = []
for features, rank in zip(X, rankings):
X1.extend(features)
norm_ranks = rank / np.max(rank, axis=0)
min_rank = np.min(rank, axis=0)
max_rank = np.max(rank, axis=0)
norm_ranks = (rank - min_rank + 1) / (max_rank - min_rank + 1)
Y_single.extend(norm_ranks)
X1 = np.array(X1)
Y_single = np.array(Y_single)
Expand Down

0 comments on commit 0f4ae0d

Please sign in to comment.