Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def render_html(self, obj: ClassificationQualityByClass) -> List[BaseWidgetInfo]

if reference_metrics is not None:
cols = 2
subplot_titles = ["current", "reference"]
subplot_titles = [self.render_options.current_name, self.render_options.reference_name]
else:
cols = 1
subplot_titles = [""]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def render_html(self, obj: ClassificationQualityByFeatureTable) -> List[BaseWidg

if reference_data is not None:
cols = 2
subplot_titles = ["current", "reference"]
subplot_titles = [self.render_options.current_name, self.render_options.reference_name]
else:
cols = 1
subplot_titles = [""]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def _get_regression_fig(self, feature_name: str, main_column: str, curr_data: pd
x=curr_data[feature_name],
y=curr_data[main_column],
mode="markers",
name="current",
name=self.render_options.current_name,
marker=dict(size=6, color=self.color_options.primary_color),
),
row=1,
Expand All @@ -323,7 +323,7 @@ def _get_regression_fig(self, feature_name: str, main_column: str, curr_data: pd
x=ref_data[feature_name],
y=ref_data[main_column],
mode="markers",
name="reference",
name=self.render_options.reference_name,
marker=dict(size=6, color=self.color_options.secondary_color),
),
row=1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ def render_html(self, obj: ColumnSummaryMetric) -> List[BaseWidgetInfo]:
metrics_values_headers = [""]
if bins_for_hist.reference is not None:
hist_ref = bins_for_hist.reference
metrics_values_headers = ["current", "reference"]
metrics_values_headers = [self.render_options.current_name, self.render_options.reference_name]

if column_type == "cat":
fig = plot_distr(
Expand Down Expand Up @@ -608,7 +608,7 @@ def render_html(self, obj: ColumnSummaryMetric) -> List[BaseWidgetInfo]:
graph = {}
metrics_values_headers = [""]
if metric_result.reference_characteristics is not None:
metrics_values_headers = ["current", "reference"]
metrics_values_headers = [self.render_options.current_name, self.render_options.reference_name]

# additional plots
additional_graphs = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@ def render_html(self, obj: DatasetMissingValuesMetric) -> List[BaseWidgetInfo]:
result = [
header_text(label="Dataset Missing Values"),
self._get_overall_missing_values_info(metric_result),
self._get_table_stat(dataset_name="current", stats=metric_result.current),
self._get_table_stat(dataset_name=self.render_options.current_name, stats=metric_result.current),
]

if metric_result.reference is not None:
result.append(self._get_table_stat(dataset_name="reference", stats=metric_result.reference))
result.append(self._get_table_stat(dataset_name=self.render_options.reference_name, stats=metric_result.reference))

return result
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ def render_html(self, obj: ColumnCategoryMetric) -> List[BaseWidgetInfo]:
result = [header_text(label=f"Column '{metric_result.column_name}'. Сategory '{metric_result.category}'.")]
counters = [
CounterData.string(
label="current",
label=self.render_options.current_name,
value=self._get_count_info(metric_result.current),
),
]

if metric_result.reference is not None:
counters.append(
CounterData.string(
label="reference",
label=self.render_options.reference_name,
value=self._get_count_info(metric_result.reference),
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _get_histogram(self, metric_result: ColumnQuantileMetricResult) -> BaseWidge
if metric_result.reference is not None:
reference_histogram_data: Optional[HistogramData] = HistogramData.from_distribution(
metric_result.reference.distribution,
name="reference",
name=self.render_options.reference_name,
)

else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def _get_tabs(self, metric_result: ColumnValueRangeMetricResult) -> BaseWidgetIn
if metric_result.reference is not None:
reference_histogram: Optional[HistogramData] = HistogramData.from_distribution(
metric_result.reference.distribution,
name="reference",
name=self.render_options.reference_name,
)

else:
Expand Down
4 changes: 2 additions & 2 deletions src/evidently/legacy/metrics/recsys/base_top_k.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ def render_html(self, obj: TopKMetric) -> List[BaseWidgetInfo]:
metric_result = obj.get_result()
k = metric_result.k
index = (k - 1) if min(metric_result.current.index) == 0 else k
counters = [CounterData.float(label="current", value=metric_result.current[index], precision=3)]
counters = [CounterData.float(label=self.render_options.current_name, value=metric_result.current[index], precision=3)]
if metric_result.reference is not None:
counters.append(CounterData.float(label="reference", value=metric_result.reference[index], precision=3))
counters.append(CounterData.float(label=self.render_options.reference_name, value=metric_result.reference[index], precision=3))
fig = plot_metric_k(metric_result.current, metric_result.reference, self.yaxis_name)
header_part = " No feedback users included."
if not obj.no_feedback_users:
Expand Down
4 changes: 2 additions & 2 deletions src/evidently/legacy/metrics/recsys/diversity.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ def calculate(self, data: InputData) -> DiversityMetricResult:
class DiversityMetricRenderer(MetricRenderer):
def render_html(self, obj: DiversityMetric) -> List[BaseWidgetInfo]:
metric_result = obj.get_result()
counters = [CounterData.float(label="current", value=metric_result.current_value, precision=4)]
counters = [CounterData.float(label=self.render_options.current_name, value=metric_result.current_value, precision=4)]
if metric_result.reference_value is not None:
counters.append(CounterData.float(label="reference", value=metric_result.reference_value, precision=4))
counters.append(CounterData.float(label=self.render_options.reference_name, value=metric_result.reference_value, precision=4))

distr_fig = plot_distr_with_perc_button(
hist_curr=HistogramData.from_distribution(metric_result.current_distr),
Expand Down
4 changes: 2 additions & 2 deletions src/evidently/legacy/metrics/recsys/novelty.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def calculate(self, data: InputData) -> NoveltyMetricResult:
class NoveltyMetricRenderer(MetricRenderer):
def render_html(self, obj: NoveltyMetric) -> List[BaseWidgetInfo]:
metric_result = obj.get_result()
counters = [CounterData.float(label="current", value=metric_result.current_value, precision=4)]
counters = [CounterData.float(label=self.render_options.current_name, value=metric_result.current_value, precision=4)]
if metric_result.reference_value is not None:
counters.append(CounterData.float(label="reference", value=metric_result.reference_value, precision=4))
counters.append(CounterData.float(label=self.render_options.reference_name, value=metric_result.reference_value, precision=4))

distr_fig = plot_distr_with_perc_button(
hist_curr=HistogramData.from_distribution(metric_result.current_distr),
Expand Down
4 changes: 2 additions & 2 deletions src/evidently/legacy/metrics/recsys/personalisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ def _get_table_stat(dataset_name: str, curr_table: dict, ref_table: Optional[dic
def render_html(self, obj: PersonalizationMetric) -> List[BaseWidgetInfo]:
metric_result = obj.get_result()

counters = [CounterData.float(label="current", value=metric_result.current_value, precision=4)]
counters = [CounterData.float(label=self.render_options.current_name, value=metric_result.current_value, precision=4)]
if metric_result.reference_value is not None:
counters.append(CounterData.float(label="reference", value=metric_result.reference_value, precision=4))
counters.append(CounterData.float(label=self.render_options.reference_name, value=metric_result.reference_value, precision=4))

result = [
header_text(label=f"Personalization (top-{metric_result.k})"),
Expand Down
4 changes: 2 additions & 2 deletions src/evidently/legacy/metrics/recsys/serendipity.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def calculate(self, data: InputData) -> SerendipityMetricResult:
class SerendipityMetricRenderer(MetricRenderer):
def render_html(self, obj: SerendipityMetric) -> List[BaseWidgetInfo]:
metric_result = obj.get_result()
counters = [CounterData.float(label="current", value=metric_result.current_value, precision=4)]
counters = [CounterData.float(label=self.render_options.current_name, value=metric_result.current_value, precision=4)]
if metric_result.reference_value is not None:
counters.append(CounterData.float(label="reference", value=metric_result.reference_value, precision=4))
counters.append(CounterData.float(label=self.render_options.reference_name, value=metric_result.reference_value, precision=4))

distr_fig = plot_distr_with_perc_button(
hist_curr=HistogramData.from_distribution(metric_result.current_distr),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def render_html(self, obj: RegressionErrorNormality) -> List[BaseWidgetInfo]:

if reference_plot is not None:
cols = 2
subplot_titles = ["current", "reference"]
subplot_titles = [self.render_options.current_name, self.render_options.reference_name]

fig = make_subplots(rows=1, cols=cols, shared_yaxes=False, subplot_titles=subplot_titles)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ def plot_error_bias_colored_scatter(
curr_scatter_data: RegressionScatter,
ref_scatter_data: Optional[RegressionScatter],
color_options: ColorOptions,
current_name: str = "Current",
reference_name: str = "Reference",
):
cols = 1
subplot_titles: Union[list, str] = ""

if ref_scatter_data is not None:
cols = 2
subplot_titles = ["current", "reference"]
subplot_titles = [current_name, reference_name]

fig = make_subplots(rows=1, cols=cols, shared_yaxes=True, subplot_titles=subplot_titles)

Expand Down Expand Up @@ -79,6 +81,8 @@ def regression_perf_plot(
curr_metric: float,
ref_metric: float = None,
color_options: ColorOptions,
current_name: str = "Current",
reference_name: str = "Reference",
):
current_color = color_options.get_current_data_color()
reference_color = color_options.get_reference_data_color()
Expand All @@ -92,7 +96,7 @@ def regression_perf_plot(
df = hist_for_plot.current.to_df().sort_values("x")
x = [str(x) for x in df.x]
y = list(df["count"])
trace = go.Bar(name="current", x=x, y=y, marker_color=current_color)
trace = go.Bar(name=current_name, x=x, y=y, marker_color=current_color)
fig.add_trace(trace, 2, 1)

if hist_for_plot.reference is not None:
Expand All @@ -106,15 +110,15 @@ def regression_perf_plot(
df = hist_for_plot.reference.to_df().sort_values("x")
x = [str(x) for x in df.x]
y = list(df["count"])
trace = go.Bar(name="reference", x=x, y=y, marker_color=reference_color)
trace = go.Bar(name=reference_name, x=x, y=y, marker_color=reference_color)
fig.add_trace(trace, 2, 1)

fig.update_yaxes(title_text=name, row=1, col=1)
fig.update_yaxes(title_text="count", row=2, col=1)
title = f"current {name}: {np.round(curr_metric, 3)}"
title = f"{current_name} {name}: {np.round(curr_metric, 3)}"

if hist_for_plot.reference is not None:
title += f", reference {name}: {np.round(ref_metric, 3) if ref_metric is not None else '--'}"
title += f", {reference_name} {name}: {np.round(ref_metric, 3) if ref_metric is not None else '--'}"

fig.update_layout(title=title)
return fig
2 changes: 2 additions & 0 deletions src/evidently/legacy/options/agg_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

class RenderOptions(Option):
raw_data: bool = False
current_name: str = "Current"
reference_name: str = "Reference"


class DataDefinitionOptions(Option):
Expand Down
3 changes: 3 additions & 0 deletions src/evidently/legacy/renderers/base_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from evidently.legacy.model.widget import BaseWidgetInfo
from evidently.legacy.model.widget import PlotlyGraphInfo
from evidently.legacy.options import ColorOptions
from evidently.legacy.options.agg_data import RenderOptions

if TYPE_CHECKING:
from evidently.legacy.base_metric import Metric
Expand All @@ -29,13 +30,15 @@ class BaseRenderer:
"""Base class for all renderers"""

color_options: ColorOptions
render_options: RenderOptions

def __init__(self, color_options: Optional[ColorOptions] = None) -> None:
if color_options is None:
self.color_options = ColorOptions()

else:
self.color_options = color_options
self.render_options = RenderOptions()


TMetric = TypeVar("TMetric", bound="Metric")
Expand Down
39 changes: 29 additions & 10 deletions src/evidently/legacy/renderers/html_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,16 +579,18 @@ def get_histogram_for_distribution(
xaxis_title: Optional[str] = None,
yaxis_title: Optional[str] = None,
color_options: ColorOptions,
current_name: str = "Current",
reference_name: str = "Reference",
):
current_histogram = HistogramData(
name="current",
name=current_name,
x=pd.Series(current_distribution.x),
count=pd.Series(current_distribution.y),
)

if reference_distribution is not None:
reference_histogram: Optional[HistogramData] = HistogramData(
name="reference",
name=reference_name,
x=pd.Series(reference_distribution.x),
count=pd.Series(reference_distribution.y),
)
Expand Down Expand Up @@ -669,14 +671,18 @@ def get_heatmaps_widget(


def get_roc_auc_tab_data(
curr_roc_curve: ROCCurve, ref_roc_curve: Optional[ROCCurve], color_options: ColorOptions
curr_roc_curve: ROCCurve,
ref_roc_curve: Optional[ROCCurve],
color_options: ColorOptions,
current_name: str = "Current",
reference_name: str = "Reference",
) -> List[Tuple[str, BaseWidgetInfo]]:
additional_plots = []
cols = 1
subplot_titles = [""]
if ref_roc_curve is not None:
cols = 2
subplot_titles = ["current", "reference"]
subplot_titles = [current_name, reference_name]
for label in curr_roc_curve.keys():
fig = make_subplots(rows=1, cols=cols, subplot_titles=subplot_titles, shared_yaxes=True)
trace = go.Scatter(
Expand Down Expand Up @@ -714,14 +720,18 @@ def get_roc_auc_tab_data(


def get_pr_rec_plot_data(
current_pr_curve: PRCurve, reference_pr_curve: Optional[PRCurve], color_options: ColorOptions
current_pr_curve: PRCurve,
reference_pr_curve: Optional[PRCurve],
color_options: ColorOptions,
current_name: str = "Current",
reference_name: str = "Reference",
) -> List[Tuple[str, BaseWidgetInfo]]:
additional_plots = []
cols = 1
subplot_titles = [""]
if reference_pr_curve is not None:
cols = 2
subplot_titles = ["current", "reference"]
subplot_titles = [current_name, reference_name]
for label in current_pr_curve.keys():
fig = make_subplots(rows=1, cols=cols, subplot_titles=subplot_titles, shared_yaxes=True)
trace = go.Scatter(
Expand Down Expand Up @@ -762,6 +772,8 @@ def get_lift_plot_data(
current_lift_curve: LiftCurve,
reference_lift_curve: Optional[LiftCurve],
color_options: ColorOptions,
current_name: str = "Current",
reference_name: str = "Reference",
) -> List[Tuple[str, BaseWidgetInfo]]:
"""
Forms plot data for lift metric visualization
Expand All @@ -785,7 +797,7 @@ def get_lift_plot_data(
subplot_titles = [""]
if reference_lift_curve is not None:
cols = 2
subplot_titles = ["current", "reference"]
subplot_titles = [current_name, reference_name]
for label in current_lift_curve.keys():
fig = make_subplots(rows=1, cols=cols, subplot_titles=subplot_titles, shared_yaxes=True)
trace = go.Scatter(
Expand Down Expand Up @@ -888,14 +900,19 @@ def class_separation_traces_agg(df, label, color_options):


def get_class_separation_plot_data(
current_plot: pd.DataFrame, reference_plot: Optional[pd.DataFrame], target_name: str, color_options: ColorOptions
current_plot: pd.DataFrame,
reference_plot: Optional[pd.DataFrame],
target_name: str,
color_options: ColorOptions,
current_name: str = "Current",
reference_name: str = "Reference",
) -> List[Tuple[str, BaseWidgetInfo]]:
additional_plots = []
cols = 1
subplot_titles = [""]
if reference_plot is not None:
cols = 2
subplot_titles = ["current", "reference"]
subplot_titles = [current_name, reference_name]
for label in current_plot.columns.drop(target_name):
fig = make_subplots(rows=1, cols=cols, subplot_titles=subplot_titles, shared_yaxes=True)
traces = class_separation_traces_raw(current_plot, label, target_name, color_options)
Expand All @@ -920,13 +937,15 @@ def get_class_separation_plot_data_agg(
reference_plot: Optional[Dict[Label, pd.DataFrame]],
target_name: str,
color_options: ColorOptions,
current_name: str = "Current",
reference_name: str = "Reference",
) -> List[Tuple[str, BaseWidgetInfo]]:
additional_plots = []
cols = 1
subplot_titles = [""]
if reference_plot is not None:
cols = 2
subplot_titles = ["current", "reference"]
subplot_titles = [current_name, reference_name]
for label in current_plot.keys():
fig = make_subplots(rows=1, cols=cols, subplot_titles=subplot_titles, shared_yaxes=True)
traces = class_separation_traces_agg(current_plot[label], label, color_options)
Expand Down
Loading