scikit-learn/scikit-learn — pull request #1244 by kuantkid (2012-10-16 13:07:37+00:00)
Title: Fix issue# 1239 confusion matrix fails when y_pred,y_true contains unexpected labels(not-exist in labels)

The issue is from when ``y_pred`` or ``y_true`` contains unexpected labels not present in ``labels``. The problem comes occurs labels is explicitly given rather than calculated from ``y_pred`` and ``y_true``.

As the docstring says, the returned matrix should be ``[n_classes, n_classes]`` where ``n_classes`` is equal to shape of ``labels``, so the fix is just eliminate the labels not exist in ``labels``. A test is added to address this issue.