Skip to content

keep the output of linear tree-based model as probability estimates #2

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 1 commit into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions libmultilabel/linear/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def predict_values(
x: sparse.csr_matrix,
beam_width: int = 10,
) -> np.ndarray:
"""Calculates the decision values associated with x.
"""Calculates the probability estimates associated with x.

Args:
x (sparse.csr_matrix): A matrix with dimension number of instances * number of features.
Expand All @@ -72,10 +72,10 @@ def predict_values(
return np.vstack([self._beam_search(all_preds[i], beam_width) for i in range(all_preds.shape[0])])

def _beam_search(self, instance_preds: np.ndarray, beam_width: int) -> np.ndarray:
"""Predict with beam search using cached decision values for a single instance.
"""Predict with beam search using cached probability estimates for a single instance.

Args:
instance_preds (np.ndarray): A vector of cached decision values of each node, has dimension number of labels + total number of metalabels.
instance_preds (np.ndarray): A vector of cached probability estimates of each node, has dimension number of labels + total number of metalabels.
beam_width (int): Number of candidates considered.

Returns:
Expand All @@ -101,7 +101,7 @@ def _beam_search(self, instance_preds: np.ndarray, beam_width: int) -> np.ndarra
next_level = []

num_labels = len(self.root.label_map)
scores = np.full(num_labels, -np.inf)
scores = np.full(num_labels, 0)
for node, score in cur_level:
slice = np.s_[self.weight_map[node.index] : self.weight_map[node.index + 1]]
pred = instance_preds[slice]
Expand Down
Loading