Skip to content

Commit

Permalink
Make confusion matrix work with evaluate module (#1444)
Browse files Browse the repository at this point in the history
* make cm work with evaluate

* Update test_confusion.py
  • Loading branch information
MaxHalford authored Nov 8, 2023
1 parent 3f5ee1c commit 6e29611
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/releases/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ River's mini-batch methods now support pandas v2. In particular, River conforms

- Simplify inner the structures of `forest.ARFClassifier` and `forest.ARFRegressor` by removing redundant class hierarchy. Simplify how concept drift logging can be accessed in individual trees and in the forest as a whole.

## metrics

- `metrics.ConfusionMatrix` may now be used with `evaluate.progressive_val_score` and `evaluate.iter_progressive_val_score`.

## proba

- Added `_from_state` method to `proba.MultivariateGaussian` to warm start from previous knowledge.
Expand Down
7 changes: 7 additions & 0 deletions river/metrics/confusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,10 @@ def total_false_positives(self):
@property
def total_false_negatives(self):
return sum(self.false_negatives(label) for label in self.classes)

def works_with(self, model) -> bool:
return utils.inspect.isclassifier(model)

@property
def requires_labels(self):
return True
16 changes: 16 additions & 0 deletions river/metrics/test_confusion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from __future__ import annotations

from river import datasets, evaluate, linear_model, metrics, optim, preprocessing


def test_issue_1443():
dataset = datasets.Phishing()

model = preprocessing.StandardScaler() | linear_model.LogisticRegression(
optimizer=optim.SGD(0.1)
)

metric = metrics.ConfusionMatrix()

for _ in evaluate.iter_progressive_val_score(dataset, model, metric):
pass

0 comments on commit 6e29611

Please sign in to comment.