Skip to content

Conversation

@Gordon119
Copy link
Contributor

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
Contributor 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
Contributor 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 Gordon119 force-pushed the Linear-make-prediction branch from c59d9d5 to fc74eb0 Compare February 28, 2023 11:49
@Eleven1Liu
Copy link
Contributor

@Sinacam review

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
Contributor

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.

5 participants