<p dir="auto">I'm trying to calculate the NDCG score for binary relevance:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from sklearn import metrics

# test 1
y_true = [[3]]
y_score = [[5]]
metrics.ndcg_score(y_true, y_score)"><pre class="notranslate"><code class="notranslate">from sklearn import metrics

# test 1
y_true = [[3]]
y_score = [[5]]
metrics.ndcg_score(y_true, y_score)
</code></pre></div>
<p dir="auto">And getting error</p>
<p dir="auto"><code class="notranslate">ValueError: Only ('multilabel-indicator', 'continuous-multioutput', 'multiclass-multioutput') formats are supported. Got binary instead </code></p>
<p dir="auto">Below code snippet is working which has more than 1 item. Please suggest why single item array is not working.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from sklearn import metrics

# test 1
y_true = [[6 ,5, 4, 3, 2, 1]]
y_score = [[120, -2, -6, -3,  2, 12]]
metrics.ndcg_score(y_true, y_score)"><pre class="notranslate"><code class="notranslate">from sklearn import metrics

# test 1
y_true = [[6 ,5, 4, 3, 2, 1]]
y_score = [[120, -2, -6, -3,  2, 12]]
metrics.ndcg_score(y_true, y_score)
</code></pre></div>
<p dir="auto">See this code example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; t = [[1]]
&gt;&gt;&gt; p = [[0]]
&gt;&gt;&gt; metrics.ndcg_score(t, p)
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/Users/cbournhonesque/.pyenv/versions/bento/lib/python3.8/site-packages/sklearn/utils/validation.py&quot;, line 63, in inner_f
    return f(*args, **kwargs)
  File &quot;/Users/cbournhonesque/.pyenv/versions/bento/lib/python3.8/site-packages/sklearn/metrics/_ranking.py&quot;, line 1567, in ndcg_score
    _check_dcg_target_type(y_true)
  File &quot;/Users/cbournhonesque/.pyenv/versions/bento/lib/python3.8/site-packages/sklearn/metrics/_ranking.py&quot;, line 1307, in _check_dcg_target_type
    raise ValueError(
ValueError: Only ('multilabel-indicator', 'continuous-multioutput', 'multiclass-multioutput') formats are supported. Got binary instead"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; t = [[1]]
&gt;&gt;&gt; p = [[0]]
&gt;&gt;&gt; metrics.ndcg_score(t, p)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/Users/cbournhonesque/.pyenv/versions/bento/lib/python3.8/site-packages/sklearn/utils/validation.py", line 63, in inner_f
    return f(*args, **kwargs)
  File "/Users/cbournhonesque/.pyenv/versions/bento/lib/python3.8/site-packages/sklearn/metrics/_ranking.py", line 1567, in ndcg_score
    _check_dcg_target_type(y_true)
  File "/Users/cbournhonesque/.pyenv/versions/bento/lib/python3.8/site-packages/sklearn/metrics/_ranking.py", line 1307, in _check_dcg_target_type
    raise ValueError(
ValueError: Only ('multilabel-indicator', 'continuous-multioutput', 'multiclass-multioutput') formats are supported. Got binary instead
</code></pre></div>
<p dir="auto">It works correctly when the number of elements is bigger than 1: <a href="https://stackoverflow.com/questions/64303839/how-to-calculate-ndcg-with-binary-relevances-using-sklearn" rel="nofollow">https://stackoverflow.com/questions/64303839/how-to-calculate-ndcg-with-binary-relevances-using-sklearn</a></p>