示例#1
0
def get_metric_bubble_chart_components(
    plot_table,
    metrics,
    ref_group,
    global_scales,
    selection,
    fairness_threshold,
    chart_height,
    chart_width,
    accessibility_mode=False,
    concat_chart=False,
):
    """Creates the components necessary to plot the metric chart."""

    # COMPUTE SCALED DISPARITIES
    for metric in metrics:
        plot_table[f"{metric}_disparity_scaled"] = plot_table.apply(
            lambda row: transform_ratio(row[f"{metric}_disparity"]), axis=1)

    # POSITION SCALES
    position_scales = __get_position_scales(metrics, chart_height, chart_width,
                                            concat_chart)
    scales = dict(global_scales, **position_scales)

    # RULES
    horizontal_rules = __draw_metrics_rules(metrics, scales, concat_chart)
    vertical_domain_rules = __draw_domain_rules(scales)

    # LABELS
    x_ticks_labels = __draw_x_ticks_labels(scales, chart_height)

    # BUBBLES - CENTERS & AREAS
    bubbles = __draw_bubbles(
        plot_table,
        metrics,
        ref_group,
        scales,
        selection,
    )

    # THRESHOLD, BANDS & ANNOTATION
    if fairness_threshold is not None:
        threshold_elements = __get_threshold_elements(
            plot_table,
            metrics,
            fairness_threshold,
            ref_group,
            scales,
            chart_height,
            concat_chart,
            accessibility_mode,
        )
        # ASSEMBLE CHART WITH THRESHOLD
        main_chart = (horizontal_rules + vertical_domain_rules +
                      x_ticks_labels + threshold_elements + bubbles)
    # ASSEMBLE CHART WITHOUT THRESHOLD
    else:
        main_chart = horizontal_rules + vertical_domain_rules + x_ticks_labels + bubbles

    return main_chart
示例#2
0
def __create_disparity_variables(attribute_df, metric, fairness_threshold):
    """ Creates scaled disparity, parity test result & disparity explanation tooltip variables. """

    # SCALED DISPARITY VALUE
    attribute_df[f"{metric}_disparity_scaled"] = attribute_df.apply(
        lambda row: transform_ratio(row[f"{metric}_disparity"]), axis=1)

    # PARITY RESULT
    attribute_df[f"{metric}_parity_result"] = attribute_df.apply(
        __get_parity_result_variable,
        metric=metric,
        fairness_threshold=fairness_threshold,
        axis=1,
    )