-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
227 additions
and
41 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,9 @@ | ||
from ._custom_scorers import CustomColumnScorer | ||
from ._custom_scorers import CustomScorer | ||
from ._text_length import TextLength | ||
|
||
__all__ = [ | ||
"CustomColumnScorer", | ||
"CustomScorer", | ||
"TextLength", | ||
] |
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,30 @@ | ||
from typing import Callable | ||
from typing import Dict | ||
from typing import Optional | ||
from typing import Union | ||
|
||
from evidently.v2.datasets import Dataset | ||
from evidently.v2.datasets import DatasetColumn | ||
from evidently.v2.datasets import Scorer | ||
|
||
|
||
class CustomColumnScorer(Scorer): | ||
def __init__(self, column_name: str, func: Callable[[DatasetColumn], DatasetColumn], alias: Optional[str] = None): | ||
super().__init__(alias) | ||
self._column_name = column_name | ||
self._func = func | ||
|
||
def generate_data(self, dataset: Dataset) -> Union[DatasetColumn, Dict[str, DatasetColumn]]: | ||
column_data = dataset.column(self._column_name) | ||
return self._func(column_data) | ||
|
||
|
||
class CustomScorer(Scorer): | ||
def __init__( | ||
self, func: Callable[[Dataset], Union[DatasetColumn, Dict[str, DatasetColumn]]], alias: Optional[str] = None | ||
): | ||
super().__init__(alias) | ||
self._func = func | ||
|
||
def generate_data(self, dataset: "Dataset") -> Union[DatasetColumn, Dict[str, DatasetColumn]]: | ||
return self._func(dataset) |
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,18 @@ | ||
from typing import Dict | ||
from typing import Optional | ||
from typing import Union | ||
|
||
from evidently import ColumnType | ||
from evidently.v2.datasets import Dataset | ||
from evidently.v2.datasets import DatasetColumn | ||
from evidently.v2.datasets import Scorer | ||
|
||
|
||
class TextLength(Scorer): | ||
def __init__(self, column_name: str, alias: Optional[str] = None): | ||
super().__init__(alias) | ||
self._column_name: str = column_name | ||
|
||
def generate_data(self, dataset: "Dataset") -> Union[DatasetColumn, Dict[str, DatasetColumn]]: | ||
column_items_lengths = dataset.as_dataframe()[self._column_name].apply(len) | ||
return DatasetColumn(type=ColumnType.Numerical, data=column_items_lengths) |