-
Notifications
You must be signed in to change notification settings - Fork 28
Linear make prediction #256
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
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5f4aa46
Add api to make prediction
Gordon119 b46e73b
Add api description
Gordon119 75e472f
update function name
Gordon119 30bde59
remove redundant and rename
Gordon119 c59d9d5
Update libmultilabel/linear/linear.py
Gordon119 fc74eb0
update input and return type
Gordon119 0f9437b
Merge branch 'Linear-make-prediction' of github.com:ASUS-AICS/LibMult…
Gordon119 0a60f7f
update label mapping
Gordon119 96a6dc6
remove file
Gordon119 44563df
update type
Gordon119 1de941b
formatting
Gordon119 687b58d
sort import
Gordon119 f3859a6
update
Gordon119 ff97bee
format
Gordon119 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -540,3 +540,20 @@ def predict_values(model, x: sparse.csr_matrix) -> np.ndarray: | |
| ], 'csr') | ||
|
|
||
| return (x * model['weights']).A + model['threshold'] | ||
|
|
||
|
|
||
| def get_topk_labels(label_mapping: np.ndarray, preds: np.ndarray, top_k: int = 5) -> 'list[list[str]]': | ||
| """Get top k predictions from decision values. | ||
|
|
||
| Args: | ||
| label_mapping (np.ndarray): A ndarray of class labels that maps each label to its index. | ||
| preds (np.ndarray): A matrix of decision values with dimension number of instances * number of classes. | ||
| top_k (int): Determine how many classes per instance should be predicted. | ||
|
|
||
| Returns: | ||
| list of lists which contain top k labels. | ||
| """ | ||
| 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 [list(label_mapping.compress(row)) for row in pred_result] | ||
Eleven1Liu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.