コード例 #1
0
def build_and_dump_explainer(explainer_config, dashboard_config=None):
    explainer = build_explainer(explainer_config)

    click.echo(
        f"explainerdashboard ===> Calculating properties by building Dashboard..."
    )
    if dashboard_config is not None:
        ExplainerDashboard.from_config(explainer, dashboard_config)
    elif Path(explainer_config['explainer']['dashboard_yaml']).exists():
        click.echo(
            f"explainerdashboard ===> Calculating properties by building Dashboard from {explainer_config['explainer']['dashboard_yaml']}..."
        )
        dashboard_config = yaml.safe_load(
            open(str(explainer_config['explainer']['dashboard_yaml']), "r"))
        ExplainerDashboard.from_config(explainer, dashboard_config)
    else:
        click.echo(f"explainerdashboard ===> Calculating all properties")
        explainer.calculate_properties()

    click.echo(
        f"explainerdashboard ===> Saving explainer to {explainer_config['explainer']['explainerfile']}..."
    )
    if (dashboard_config is not None
            and explainer_config['explainer']['explainerfile'] !=
            dashboard_config['dashboard']['explainerfile']):
        click.echo(
            f"explainerdashboard ===> Warning explainerfile in explainer config and dashboard config do not match!"
        )
    explainer.dump(explainer_config['explainer']['explainerfile'])
    return
コード例 #2
0
def launch_dashboard_from_pkl(explainer_filepath,
                              no_browser,
                              port,
                              no_dashboard=False):
    explainer = BaseExplainer.from_file(explainer_filepath)

    if port is None:
        click.echo(
            f"explainerdashboard ===> Setting port to 8050, override with e.g. --port 8051"
        )
        port = 8050

    db = ExplainerDashboard(explainer, port=port)

    if not no_browser and not os.environ.get("WERKZEUG_RUN_MAIN"):
        webbrowser.open_new(f"http://127.0.0.1:{port}/")

    if not no_dashboard:
        db.run(port)
    return
コード例 #3
0
def test_simple_regression_dashboard(dash_duo):
    explainer = get_regression_explainer()
    db = ExplainerDashboard(explainer,
                            title="testing",
                            responsive=False,
                            simple=True)
    dash_duo.start_server(db.app)
    dash_duo.wait_for_text_to_equal("#simple-regression-composite-title",
                                    "testing",
                                    timeout=20)
    assert dash_duo.get_logs() == [], "browser console should contain no error"
コード例 #4
0
def launch_dashboard_from_yaml(dashboard_config,
                               no_browser,
                               port,
                               no_dashboard=False):
    if isinstance(dashboard_config,
                  (Path, str)) and str(dashboard_config).endswith(".yaml"):
        config = yaml.safe_load(open(str(dashboard_config), "r"))
    elif isinstance(dashboard_config, dict):
        config = dashboard_config
    else:
        raise ValueError(
            f"dashboard_config should either be a .yaml filepath or a dict!")

    if not Path(config['dashboard']['explainerfile']).exists():
        click.echo(
            f"explainerdashboard ===> {config['dashboard']['explainerfile']} does not exist!"
        )
        click.echo(
            f"explainerdashboard ===> first generate {config['dashboard']['explainerfile']} with explainerdashboard build"
        )
        return

    click.echo(
        f"explainerdashboard ===> Building dashboard from {config['dashboard']['explainerfile']}"
    )

    db = ExplainerDashboard.from_config(config)

    if port is None:
        port = config['dashboard']['params']['port']
        if port is None:
            port = 8050
        click.echo(
            f"explainerdashboard ===> Setting port to {port}, override with e.g. --port 8051"
        )

    if not no_browser and not os.environ.get("WERKZEUG_RUN_MAIN"):
        click.echo(
            f"explainerdashboard ===> launching browser at {f'http://localhost:{port}/'}"
        )
        webbrowser.open_new(f"http://localhost:{port}/")

    click.echo(f"explainerdashboard ===> Starting dashboard:")
    if not no_dashboard:
        db.run(port)
    return
コード例 #5
0
def test_classification_dashboard_no_y(dash_duo):
    explainer = get_classification_explainer(include_y=False)
    db = ExplainerDashboard(explainer, title="testing", responsive=False)
    dash_duo.start_server(db.app)
    dash_duo.wait_for_text_to_equal("h1", "testing", timeout=30)
    assert dash_duo.get_logs() == [], "browser console should contain no error"
コード例 #6
0
def test_cat_boost_regression_dashboard(dash_duo):
    explainer = get_catboost_regressor()
    db = ExplainerDashboard(explainer, title="testing", responsive=False)
    dash_duo.start_server(db.app)
    dash_duo.wait_for_text_to_equal("h1", "testing", timeout=30)
    assert dash_duo.get_logs() == [], "browser console should contain no error"