Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG+1] fix P/R/F for truncated range(n_labels) #10377

Merged
merged 4 commits into from
Jan 11, 2018

Conversation

gxyd
Copy link
Contributor

@gxyd gxyd commented Dec 27, 2017

What does this implement/fix? Explain your changes.

Fixes #10307

for ex. if n_labels = 5, then passing labels = [0, 1, 2]
will give results similar to labels = [0, 1, 2, 3, 4], neglecting
the value of labels.

Currently in master branch:

>>> y_true = np.array([[0, 1, 1], [1, 0, 0]])
>>> y_pred = np.array([[1, 1, 1], [1, 0, 1]])
>>> precision_recall_fscore_support(y_true, y_pred, average='samples', labels=[0, 1])
(0.58333333333333326, 1.0, 0.73333333333333339, None)
>>> precision_recall_fscore_support(y_true, y_pred, average='samples', labels=[1, 0])
(0.75, 1.0, 0.83333333333333326, None)

I'm not sure if this will require any changes to test_common, since labels=[0, 1] and labels=[1, 0] should give the same result for average='samples' (atleast for average='samples', haven't thought about other averages), this is similar to commutative property w.r.t. labels.

for ex. if n_labels = 5, then passing labels = [0, 1, 2]
will give results similar to labels = [0, 1, 2, 3, 4], neglecting
the value of labels
@gxyd gxyd changed the title fix P/R/F for truncated range(n_labels) [WIP] fix P/R/F for truncated range(n_labels) Dec 27, 2017
@gxyd gxyd changed the title [WIP] fix P/R/F for truncated range(n_labels) [MRG] fix P/R/F for truncated range(n_labels) Dec 27, 2017
Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise LGTM

@@ -197,6 +197,13 @@ def test_precision_recall_f_extra_labels():
assert_raises(ValueError, recall_score, y_true_bin, y_pred_bin,
labels=np.arange(-1, 4), average=average)

y_true = np.array([[0, 1, 1], [1, 0, 0]])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's hard to see what this is testing, it would be good to add a comment saying that it tests non-regression on issue #xxx.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't any issue for this, should I instead refer this PR itself?

@jnothman
Copy link
Member

Please add an entry to the change log at doc/whats_new/v0.20.rst. Like the other entries there, please reference this pull request with :issue: and credit yourself (and other contributors if applicable) with :user:

@jnothman jnothman changed the title [MRG] fix P/R/F for truncated range(n_labels) [MRG+1] fix P/R/F for truncated range(n_labels) Dec 31, 2017
@gxyd
Copy link
Contributor Author

gxyd commented Dec 31, 2017

I've made the asked change, though I've commented #PR number instead of #issue_number. I think that is fine as well.

@gxyd
Copy link
Contributor Author

gxyd commented Dec 31, 2017

Fixes #10307

@jnothman
Copy link
Member

Flake8 errors?

@gxyd
Copy link
Contributor Author

gxyd commented Jan 1, 2018

Doesn't it seem like so to me. It says:

 l.append(self.Function(name, self, args=args, callobj=call))
/home/travis/miniconda/envs/testenv/lib/python3.4/site-packages/_pytest/python.py:625: PendingDeprecationWarning: This usage is deprecated, please use pytest.Function instead
  l.append(self.Function(name, self, args=args, callobj=call))
/home/travis/miniconda/envs/testenv/lib/python3.4/site-packages/_pytest/python.py:625: PendingDeprecationWarning: This usage is deprecated, please use pytest.Function instead
  l.append(self.Function(name, self, args=args, callobj=call))
/home/travis/miniconda/envs/testenv/lib/python3.4/site-packages/_pytest/python.py:625: PendingDeprecationWarning: This usage is deprecated, please use pytest.Function instead
  l.append(self.Function(name, self, args=args, callobj=call))
/home/travis/miniconda/envs/testenv/lib/python3.4/site-packages/_pytest/python.py:625: PendingDeprecationWarning: This usage is deprecated, please use pytest.Function instead
  l.append(self.Function(name, self, args=args, callobj=call))
/home/travis/miniconda/envs/testenv/lib/python3.4/site-packages/_pytest/python.py:625: PendingDeprecationWarning: This usage is deprecated, please use pytest.Function instead
  l.append(self.Function(name, self, args=args, callobj=call))
/home/travis/miniconda/envs/testenv/lib/python3.4/site-packages/_pytest/python.py:625: PendingDeprecationWarning: This usage is deprecated, please use pytest.Function instead
  l.append(self.Function(name, self, args=args, callobj=call))
/home/travis/build/scikit-learn/scikit-learn/sklearn/utils/deprecation.py:58: DeprecationWarning: Class VBGMM is deprecated; The `VBGMM` class is not working correctly and it's better to use `sklearn.mixture.BayesianGaussianMixture` class with parameter `weight_concentration_prior_type='dirichlet_distribution'` instead. VBGMM is deprecated in 0.18 and will be removed in 0.20.
  warnings.warn(msg, category=DeprecationWarning)
collecting 7727 items/home/travis/miniconda/envs/testenv/lib/python3.4/site-packages/_pytest/python.py:625: PendingDeprecationWarning: This usage is deprecated, please use pytest.Function instead
  l.append(self.Function(name, self, args=args, callobj=call))
collecting 7999 items/home/travis/miniconda/envs/testenv/lib/python3.4/site-packages/_pytest/python.py:625: PendingDeprecationWarning: This usage is deprecated, please use pytest.Function instead
  l.append(self.Function(name, self, args=args, callobj=call))
collected 8423 items 

....repeated lines

The job exceeded the maximum time limit for jobs, and has been terminated.

Here is the link to failing travis job https://travis-ci.org/scikit-learn/scikit-learn/jobs/323659077 . Some random failure?

@jnothman
Copy link
Member

jnothman commented Jan 1, 2018 via email

p, r, f, _ = precision_recall_fscore_support(y_true, y_pred,
average='samples',
labels=[0, 1])
assert_almost_equal(np.array([p, r, f]), np.array([3. / 4, 1., 5. / 6]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have imported division from future on the top so let's remove the useless . for the float.

@glemaitre glemaitre merged commit 60b0cf8 into scikit-learn:master Jan 11, 2018
@glemaitre
Copy link
Member

@gxyd Thanks!!!

@gxyd
Copy link
Contributor Author

gxyd commented Jan 11, 2018

@glemaitre was it necessary the changes in commit that you added?

@gxyd
Copy link
Contributor Author

gxyd commented Jan 11, 2018

@glemaitre never mind. I just saw your comment here #10377 (comment) .

Thanks @jnothman @glemaitre for review.

@glemaitre
Copy link
Member

@gxyd I decided that it was not worth to make a round of change/review for such a nitpick :)
Regarding the change itself, I would think that we should try writing python 3 code which is back-compatible but this is just a detail.

@jnothman
Copy link
Member

jnothman commented Jan 11, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG Inconsistent f1_score behavior when combining label indicator input with labels attribute
3 participants