From 58fc09eab2db1fb678522a807a8a20ed519627fd Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Fri, 23 Jun 2023 15:13:44 +0200 Subject: [PATCH 1/4] fix: remove default value of `positive_class` parameter of classifier metrics (#382) ### Summary of Changes Remove default value of `positive_class` parameter of classifier metrics since there is no generally applicable choice. --- src/safeds/ml/classical/classification/_classifier.py | 6 +++--- tests/safeds/ml/classical/classification/test_classifier.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/safeds/ml/classical/classification/_classifier.py b/src/safeds/ml/classical/classification/_classifier.py index 71066128a..915ab8f3c 100644 --- a/src/safeds/ml/classical/classification/_classifier.py +++ b/src/safeds/ml/classical/classification/_classifier.py @@ -117,7 +117,7 @@ def accuracy(self, validation_or_test_set: TaggedTable) -> float: return sk_accuracy_score(expected_values._data, predicted_values._data) - def precision(self, validation_or_test_set: TaggedTable, positive_class: Any = 1) -> float: + def precision(self, validation_or_test_set: TaggedTable, positive_class: Any) -> float: """ Compute the classifier's precision on the given data. @@ -154,7 +154,7 @@ def precision(self, validation_or_test_set: TaggedTable, positive_class: Any = 1 return 1.0 return n_true_positives / (n_true_positives + n_false_positives) - def recall(self, validation_or_test_set: TaggedTable, positive_class: Any = 1) -> float: + def recall(self, validation_or_test_set: TaggedTable, positive_class: Any) -> float: """ Compute the classifier's recall on the given data. @@ -191,7 +191,7 @@ def recall(self, validation_or_test_set: TaggedTable, positive_class: Any = 1) - return 1.0 return n_true_positives / (n_true_positives + n_false_negatives) - def f1_score(self, validation_or_test_set: TaggedTable, positive_class: Any = 1) -> float: + def f1_score(self, validation_or_test_set: TaggedTable, positive_class: Any) -> float: """ Compute the classifier's $F_1$-score on the given data. diff --git a/tests/safeds/ml/classical/classification/test_classifier.py b/tests/safeds/ml/classical/classification/test_classifier.py index 311cc5292..d568c8cfd 100644 --- a/tests/safeds/ml/classical/classification/test_classifier.py +++ b/tests/safeds/ml/classical/classification/test_classifier.py @@ -375,7 +375,7 @@ def test_should_return_1_if_never_expected_to_be_positive(self) -> None: ) def test_should_raise_if_table_is_not_tagged(self, table: Table) -> None: with pytest.raises(UntaggedTableError): - DummyClassifier().precision(table) # type: ignore[arg-type] + DummyClassifier().precision(table, 1) # type: ignore[arg-type] class TestRecall: @@ -424,7 +424,7 @@ def test_should_return_1_if_never_expected_to_be_positive(self) -> None: ) def test_should_raise_if_table_is_not_tagged(self, table: Table) -> None: with pytest.raises(UntaggedTableError): - DummyClassifier().recall(table) # type: ignore[arg-type] + DummyClassifier().recall(table, 1) # type: ignore[arg-type] class TestF1Score: @@ -473,4 +473,4 @@ def test_should_return_1_if_never_expected_or_predicted_to_be_positive(self) -> ) def test_should_raise_if_table_is_not_tagged(self, table: Table) -> None: with pytest.raises(UntaggedTableError): - DummyClassifier().f1_score(table) # type: ignore[arg-type] + DummyClassifier().f1_score(table, 1) # type: ignore[arg-type] From 1a9e08b0e95d63f3233b53e73970b2018126f27c Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Fri, 23 Jun 2023 15:45:25 +0200 Subject: [PATCH 2/4] revert: "ci: use `GITHUB_TOKEN` instead of `PAT`" This reverts commit 3520ce2218c74706490220101f93d1d9eedcd895. --- .github/workflows/megalinter.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/megalinter.yml b/.github/workflows/megalinter.yml index 56cf96bda..06d8f0f73 100644 --- a/.github/workflows/megalinter.yml +++ b/.github/workflows/megalinter.yml @@ -7,7 +7,5 @@ on: jobs: megalinter: uses: lars-reimann/.github/.github/workflows/megalinter-reusable.yml@main - permissions: - contents: write - issues: write - pull-requests: write + secrets: + PAT: ${{ secrets.PAT }} From 6f5c95eac7e23ef443c7fdd41c42a80ac0f361cb Mon Sep 17 00:00:00 2001 From: Alex Senger <91055000+alex-senger@users.noreply.github.com> Date: Fri, 23 Jun 2023 16:00:36 +0200 Subject: [PATCH 3/4] docs: Add that the `number_of_rows` will be set to 0 when removing the last column (#384) Closes #276 ### Summary of Changes When removing the only column in a 1-column-table, the number_of_rows property is set to 0. This behaviour should be documented in the Table class docstring as well as in the following methods: Table.keep_only_columns, Table.remove_columns, Table.remove_columns_with_missing_values and Table.remove_columns_with_non_numerical_values. --------- Co-authored-by: patrikguempel <128832338+patrikguempel@users.noreply.github.com> --- src/safeds/data/tabular/containers/_table.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 12fbb757c..b62423cab 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -54,6 +54,8 @@ class Table: | [from_columns][safeds.data.tabular.containers._table.Table.from_columns] | Create a table from a list of columns. | | [from_rows][safeds.data.tabular.containers._table.Table.from_rows] | Create a table from a list of rows. | + Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. + Parameters ---------- data : Mapping[str, Sequence[Any]] | None @@ -825,6 +827,8 @@ def keep_only_columns(self, column_names: list[str]) -> Table: This table is not modified. + Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. + Parameters ---------- column_names : list[str] @@ -857,6 +861,8 @@ def remove_columns(self, column_names: list[str]) -> Table: This table is not modified. + Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. + Parameters ---------- column_names : list[str] @@ -889,6 +895,8 @@ def remove_columns_with_missing_values(self) -> Table: This table is not modified. + Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. + Returns ------- table : Table @@ -902,6 +910,8 @@ def remove_columns_with_non_numerical_values(self) -> Table: This table is not modified. + Note: When removing the last column of the table, the `number_of_columns` property will be set to 0. + Returns ------- table : Table From d97d32a545bb87400d52cbc38d1ebbdfdb50b6fb Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Fri, 23 Jun 2023 15:59:29 +0200 Subject: [PATCH 4/4] ci: set permissions of `GITHUB_TOKEN` --- .github/workflows/megalinter.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/megalinter.yml b/.github/workflows/megalinter.yml index 06d8f0f73..599a7e878 100644 --- a/.github/workflows/megalinter.yml +++ b/.github/workflows/megalinter.yml @@ -7,5 +7,9 @@ on: jobs: megalinter: uses: lars-reimann/.github/.github/workflows/megalinter-reusable.yml@main + permissions: + contents: write + issues: write + pull-requests: write secrets: PAT: ${{ secrets.PAT }}