Ejemplo n.º 1
0
clustering_tab = dcc.Tab(
    label="Clustering", children=[
        html.Div(id="clustering_area", children=[
            clustering_dropdown.generate_dash_element(),
        ]),
        html.P(children=None, id="cluster_info_text", style={"padding": "5px", "margin": "5px"})
    ], className="custom-tab", selected_className="custom-tab--selected"
)

clusters_tab = dcc.Tab(
    label="Clusters", children=[html.Div(id="cluster_info_table")],
    className="custom-tab", selected_className="custom-tab--selected"
)

arguments = {
    "clustering_method": misc.HtmlElement(*clustering_dropdown.dropdown_args),
    "clustering_options": misc.HtmlElement(*clustering_dropdown.options_args),
    "clustering_refresh": misc.HtmlElement(*clustering_dropdown.refresh_args),
    "cluster_info_table": misc.HtmlElement("cluster_info_table", "children"),
}
outputs = [Output("cluster_info_table", "children"), Output("cluster_info_text", "children")]


@cache.memoize()
def get_clusters(to_cluster, clustering, clustering_options):
    if clustering_options:
        clusters = clustering_dropdown.apply(clustering, clustering_options, to_cluster)
    elif to_cluster is not None:
        clusters = np.zeros(to_cluster.shape[0])
    else:
        clusters = None
Ejemplo n.º 2
0
            # Choose preprocessing
            html.Div([
                html.H5("Text preprocessing:"),
                dcc.Checklist(id="text_preprocess_checklist",
                              options=[{"label": name, "value": name} for name, cls in data_preprocessing_options.items()], value=[],
                              style={"padding": "5px", "margin": "5px"})
            ], id="text_preprocess_checklist_div"),
            # Display preprocessed text
            html.H5("Text used for clustering:"),
            html.Div(dash_table.DataTable(id="text_preprocess"), id="text_preprocess_div"),
        ]),
    ], className="custom-tab", selected_className="custom-tab--selected"
)

arguments = {
    "preprocessing_method": misc.HtmlElement("text_preprocess_checklist", "value"),
    "preprocessing_output": misc.HtmlElement("text_preprocess_div", "children"),
}
outputs = Output("text_preprocess_div", "children")


@cache.memoize()
def get_preprocessed_data(df, preprocessing_method):
    if df is not None and preprocessing_method:
        for method in preprocessing_method:
            df = data_preprocessing_options[method]().apply(df)

    return df


def get_data_preprocessing_output(df, preprocessing_method):
Ejemplo n.º 3
0
            children=[
                # Choose data_to_array method
                dim_reduction_dropdown.generate_dash_element(),
                # Display array
                html.H5("Dimensionality Reduced Array:",
                        id="dim_red_table_header"),
                html.Div(dash_table.DataTable(id="dim_red_table"),
                         id="dim_red_table_div"),
            ]),
    ],
    className="custom-tab",
    selected_className="custom-tab--selected")

arguments = {
    "dim_reduction_method":
    misc.HtmlElement(*dim_reduction_dropdown.dropdown_args),
    "dim_reduction_options":
    misc.HtmlElement(*dim_reduction_dropdown.options_args),
    "dim_reduction_refresh":
    misc.HtmlElement(*dim_reduction_dropdown.refresh_args),
}
outputs = Output("dim_red_table_div", "children")


@cache.memoize()
def get_dim_reduction(df_arr, dim_reduction_method, dim_reduction_options):
    if df_arr is not None and dim_reduction_method and dim_reduction_options:
        return pd.DataFrame(
            dim_reduction_dropdown.apply(dim_reduction_method,
                                         dim_reduction_options, df_arr))
Ejemplo n.º 4
0
                                          max=100)),
                # Choose columns
                html.H5("Select columns to use:"),
                html.Div(dcc.Dropdown(id="data_column_selector"),
                         id="data_column_selector_div"),
                # Display top rows
                html.H5("Top rows:", id="data_top_rows"),
                html.Div(dash_table.DataTable(id="data_top_rows_table"),
                         id="data_top_rows_div")
            ]),
    ],
    className="custom-tab",
    selected_className="custom-tab--selected")

arguments = {
    "selected_data": misc.HtmlElement("data", "value"),
    "selected_data_percent": misc.HtmlElement("data_sample_percent", "value"),
    "selected_columns": misc.HtmlElement("data_column_selector", "value"),
}

outputs = [
    Output("data_top_rows_div", "children"),
    Output("data_column_selector_div", "children"),
    Output("data_top_rows", "children")
]


@cache.memoize()
def get_data(data_source, data_sample_percent=100):
    df = data_sources[data_source]() if data_source is not None else None
Ejemplo n.º 5
0
    label="Recommendation", children=[
        html.Div(id="recommendation_area", children=[
            html.P("Pairwise Distance:", style={"padding": "5px"}),
            dcc.Dropdown(id="recommendation_metric", options=[
                {"label": name, "value": name} for name in ("cosine", "euclidean", "manhattan")
            ], value="cosine"),
            html.P("Recommendations for:", style={"padding": "5px"}),
            dcc.Dropdown(id="recommendation_picker"),
            html.P("Recommendations:", style={"padding": "5px"}),
            html.Div(id="recommendations")
        ]),
    ], className="custom-tab", selected_className="custom-tab--selected"
)

arguments = {
    "recommendation_title": misc.HtmlElement("recommendation_picker", "value"),
    "recommendation_metric": misc.HtmlElement("recommendation_metric", "value"),
}
outputs = [Output("recommendations", "children"), Output("recommendation_picker", "options")]


def get_recommendations(n, title, metric, data_df, clusters, titles):
    title_idx = np.argwhere(titles.values == title).ravel()[0]
    title_cluster = clusters[title_idx]
    dists = pairwise_distances(data_df.values[title_idx, :][None, :], data_df.values, metric=metric)
    dists_in_cluster = pairwise_distances(data_df.values[title_idx, :][None, :],
                                          data_df.values[clusters == title_cluster],
                                          metric=metric)

    top = np.argsort(dists).ravel()[:n]
    top_cluster = np.argsort(dists_in_cluster).ravel()[:n]
Ejemplo n.º 6
0
            id="data_to_array_area",
            children=[
                # Choose data_to_array_method
                data_to_array_dropdown.generate_dash_element(),
                # Display array
                html.H5("Data array:", id="data_to_array_header"),
                html.Div(dash_table.DataTable(id="data_to_array_table"),
                         id="data_to_array_div"),
            ]),
    ],
    className="custom-tab",
    selected_className="custom-tab--selected")

arguments = {
    "data_to_array_method":
    misc.HtmlElement(*data_to_array_dropdown.dropdown_args),
    "data_to_array_options":
    misc.HtmlElement(*data_to_array_dropdown.options_args),
    "data_to_array_refresh":
    misc.HtmlElement(*data_to_array_dropdown.refresh_args),
    "data_to_array_table": misc.HtmlElement("data_to_array_div", "children"),
}
outputs = [
    Output("data_to_array_div", "children"),
    Output("data_to_array_header", "children")
]


@cache.memoize()
def get_data_as_array(df, data_to_array_method, data_to_array_options):
    df_arr = None
Ejemplo n.º 7
0
plotting_options_tab = dcc.Tab(
    label="Plotting Options", children=[
        html.Div(id="plotting_dim_red_area", children=[
            plotting_options_dropdown.generate_dash_element(),
        ]),
    ], className="custom-tab", selected_className="custom-tab--selected"
)

plot_tab = dcc.Tab(
    label="Plot", children=[dcc.Graph(id="scatter-plot")],
    className="custom-tab", selected_className="custom-tab--selected"
)

arguments = {
    "plot_dim_reduction_method": misc.HtmlElement(*plotting_options_dropdown.dropdown_args),
    "plot_dim_reduction_options": misc.HtmlElement(*plotting_options_dropdown.options_args),
    "plot_dim_reduction_refresh": misc.HtmlElement(*plotting_options_dropdown.refresh_args),
}
outputs = Output("scatter-plot", "figure")


@cache.memoize()
def get_dim_reduction(df_arr, plot_dim_reduction_method, plot_dim_reduction_options):
    if plot_dim_reduction_method and plot_dim_reduction_options:
        return pd.DataFrame(plotting_options_dropdown.apply(plot_dim_reduction_method, plot_dim_reduction_options,
                                                            df_arr))

    return None