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

Linear make prediction #256

Merged
merged 14 commits into from
Mar 3, 2023
Merged

Linear make prediction #256

merged 14 commits into from
Mar 3, 2023

Conversation

Gordon119
Copy link
Collaborator

What does this PR do?

as title.

Test CLI & API (bash tests/autotest.sh)

  • Test Pass
    • (Copy and paste the last outputted line here.)
  • Not Applicable (i.e., the PR does not include API changes.)

Test quickstart & API (bash tests/docs/test_examples.sh)

  • Test Pass
    • (Copy and paste the last outputted line here.)
  • Not Applicable (i.e., the PR does not include API changes.)

Check API Document

  • API document is updated (linear, nn)
  • Not Applicable (i.e., the PR does not include API changes.)

top_k_ind = np.argpartition(x, -top_k)[:, -top_k:]
pred_result = np.zeros(x.shape)
np.put_along_axis(pred_result, top_k_ind, 1, -1)
pred_result[pred_result != 1] = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

why line 588 as pred_result is initialized as the zero matrix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

inverse_transform has to take predictions in binary labels, so I first set pred_result to zero matrix and set the top k labels to 1. I realized that line 558 is redundant and removed it.

top_k_ind = np.argpartition(preds, -top_k)[:, -top_k:]
pred_result = np.zeros(preds.shape)
np.put_along_axis(pred_result, top_k_ind, 1, -1)
return preprocessor.binarizer.inverse_transform(pred_result)
Copy link
Collaborator

Choose a reason for hiding this comment

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

where do we have this binarizer.inverse_transform defined??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since we’re using sklearn’s MultiLabelBinarizer, I used this:
https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MultiLabelBinarizer.html

Gordon119 and others added 2 commits February 26, 2023 22:00
Co-authored-by: Jie-Jyun Liu <jiejyunliu@gmail.com>
@Eleven1Liu
Copy link
Collaborator

@Sinacam review

libmultilabel/linear/linear.py Outdated Show resolved Hide resolved
Returns:
list of lists which contain top k labels.
"""
top_k_ind = np.argpartition(preds, -top_k)[:, -top_k:]
Copy link
Contributor

Choose a reason for hiding this comment

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

top_k_ind is sorted ascending this way. top_k_ind = np.argpartition(preds, -top_k)[:, :top_k:-1] sorts descending.

@Eleven1Liu
Copy link
Collaborator

LGTM

@Eleven1Liu Eleven1Liu requested a review from Sinacam March 2, 2023 14:33
@Eleven1Liu Eleven1Liu mentioned this pull request Mar 2, 2023
6 tasks
@Gordon119 Gordon119 merged commit 603edf4 into master Mar 3, 2023
@Gordon119 Gordon119 deleted the Linear-make-prediction branch March 3, 2023 03:22
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.

4 participants