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

explicitly assign arguments to avoid incorrect argument assignments #389

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions libmultilabel/linear/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,18 @@ class MultiLabelEstimator(sklearn.base.BaseEstimator):
scoring_metric (str, optional): The scoring metric. Defaults to 'P@1'.
"""

def __init__(self, options: str = "", linear_technique: str = "1vsrest", scoring_metric: str = "P@1"):
def __init__(self, options: str = "", linear_technique: str = "1vsrest", scoring_metric: str = "P@1", multiclass: bool = False):
super().__init__()
self.options = options
self.linear_technique = linear_technique
self.scoring_metric = scoring_metric
self._is_fitted = False
self.multiclass = multiclass

def fit(self, X: sparse.csr_matrix, y: sparse.csr_matrix):
X, y = sklearn.utils.validation.check_X_y(X, y, accept_sparse=True, multi_output=True)
self._is_fitted = True
self.model = LINEAR_TECHNIQUES[self.linear_technique](y, X, self.options)
self.model = LINEAR_TECHNIQUES[self.linear_technique](y, X, options=self.options)
return self

def predict(self, X: sparse.csr_matrix) -> np.ndarray:
Expand All @@ -96,8 +97,9 @@ def predict(self, X: sparse.csr_matrix) -> np.ndarray:

def score(self, X: sparse.csr_matrix, y: sparse.csr_matrix) -> float:
metrics = linear.get_metrics(
[self.scoring_metric],
y.shape[1],
monitor_metrics=[self.scoring_metric],
num_classes=y.shape[1],
multiclass=self.multiclass
)
preds = self.predict(X)
metrics.update(preds, y.toarray())
Expand Down
6 changes: 3 additions & 3 deletions linear_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def linear_train(datasets, config):
model = LINEAR_TECHNIQUES[config.linear_technique](
datasets["train"]["y"],
datasets["train"]["x"],
config.liblinear_options,
config.tree_degree,
config.tree_max_depth,
options=config.liblinear_options,
K=config.tree_degree,
dmax=config.tree_max_depth,
)
else:
model = LINEAR_TECHNIQUES[config.linear_technique](
Expand Down
Loading