Skip to content

Disallow 0 on Triplets predictions #331

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

Merged
merged 7 commits into from
Oct 12, 2021

Conversation

mvargas33
Copy link
Contributor

Right now, the zero value is allowed when predicting triplets, because of np.sign wich returns -1 if the input is below zero, +1 if the input is higher than zero, and 0 if the input is zero.

Triplets of the form: (x, y, y), (x, x, x) and (x, u, v), with u and v orthogonal to x with the same norm, cause trouble.

This is because the distance between x and the second point, x and third point is the same, causing decision_function to be zero, and then causing predict to be zero in the _TripletsClassifierMixin.

For bilinear similarity it's even more relaxed, as the norm of u and v does not need to be the same.

By definition, the semantic of a triplet says that the distance between the first and the second point should be strictly higher than the distance between the first and the third point, then any zero prediction is invalid.

I propose to force zero predictions to be -1 instead, as the definition of a triplet is not satisfied.

In practice, there should not be that many border cases.

Finally, I also made a test to show this problem.

Copy link
Member

@bellet bellet left a comment

Choose a reason for hiding this comment

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

Thanks @mvargas33. I have not looked at the tests yet (some tests are failing)

@mvargas33
Copy link
Contributor Author

This PR is ready to be merged

@mvargas33 mvargas33 requested a review from bellet October 6, 2021 11:54
Copy link
Member

@bellet bellet left a comment

Choose a reason for hiding this comment

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

See minor comments above.
If you don't merge the new test with test_predict_only_one_or_minus_one, please move it right after it as they are quite related.

@mvargas33
Copy link
Contributor Author

Resolved all the small comments

@mvargas33 mvargas33 requested a review from bellet October 11, 2021 12:25
Copy link
Member

@bellet bellet left a comment

Choose a reason for hiding this comment

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

LGTM!

@bellet bellet merged commit 44be909 into scikit-learn-contrib:master Oct 12, 2021
@mvargas33 mvargas33 deleted the feat-tclassifier branch October 18, 2021 09:38
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.

2 participants