-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add implementations for column_max, column_mean, column_min and colum…
…n_quantile.
- Loading branch information
Showing
6 changed files
with
108 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from typing import List | ||
from typing import Optional | ||
|
||
from evidently.v2.datasets import Dataset | ||
from evidently.v2.metrics import Metric | ||
from evidently.v2.metrics import SingleValue | ||
from evidently.v2.metrics import SingleValueCheck | ||
|
||
|
||
class ColumnMax(Metric[SingleValue]): | ||
def __init__(self, column: str, checks: Optional[List[SingleValueCheck]] = None): | ||
super().__init__(f"max:{column}", checks) | ||
self._column = column | ||
|
||
def calculate(self, current_data: Dataset, reference_data: Optional[Dataset]) -> SingleValue: | ||
data = current_data.column(self._column) | ||
value = data.data.max() | ||
return SingleValue(value) | ||
|
||
def display_name(self) -> str: | ||
return f"Maximum value of {self._column}" | ||
|
||
|
||
def column_max(column_name: str, checks: Optional[List[SingleValueCheck]] = None) -> ColumnMax: | ||
return ColumnMax(column_name, checks) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import List | ||
from typing import Optional | ||
|
||
from evidently.v2.datasets import Dataset | ||
from evidently.v2.metrics import Metric | ||
from evidently.v2.metrics import SingleValue | ||
from evidently.v2.metrics import SingleValueCheck | ||
|
||
|
||
class ColumnMean(Metric[SingleValue]): | ||
def __init__(self, column: str, checks: Optional[List[SingleValueCheck]] = None): | ||
super().__init__(f"mean:{column}", checks) | ||
self._column = column | ||
|
||
def calculate(self, current_data: Dataset, reference_data: Optional[Dataset]) -> SingleValue: | ||
value = current_data.column(self._column).data.mean() | ||
return SingleValue(value) | ||
|
||
def display_name(self) -> str: | ||
return f"Mean value of '{self._column}'" | ||
|
||
|
||
def column_mean(column: str, checks: Optional[List[SingleValueCheck]] = None): | ||
return ColumnMean(column, checks) |
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import List | ||
from typing import Optional | ||
|
||
from evidently.v2.datasets import Dataset | ||
from evidently.v2.metrics import Metric | ||
from evidently.v2.metrics import SingleValue | ||
from evidently.v2.metrics import SingleValueCheck | ||
|
||
|
||
class ColumnQuantile(Metric[SingleValue]): | ||
def __init__(self, column: str, quantile: float, checks: Optional[List[SingleValueCheck]] = None): | ||
super().__init__(f"quantile:{quantile}:{column}", checks) | ||
self._quantile = quantile | ||
self._column = column | ||
|
||
def calculate(self, current_data: Dataset, reference_data: Optional[Dataset]) -> SingleValue: | ||
data = current_data.column(self._column) | ||
value = data.data.quantile(self._quantile) | ||
return SingleValue(value) | ||
|
||
def display_name(self) -> str: | ||
return f"Quantile {self._quantile} of {self._column}" | ||
|
||
|
||
def column_quantile( | ||
column_name: str, quantile: float, checks: Optional[List[SingleValueCheck]] = None | ||
) -> ColumnQuantile: | ||
return ColumnQuantile(column_name, quantile, checks) |