File size: 3,731 Bytes
b510d23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import pandas as pd

data = pd.DataFrame(columns=["Dataset", "Alpha", "Top K", "Recall", "Precision"])
data = pd.concat(
    [
        data,
        pd.DataFrame(
            [["ml-100k", 0.1, 20, 0.2, 0.2]],
            columns=["Dataset", "Alpha", "Top K", "Recall", "Precision"],
        ),
    ]
)

import os
import plotly.express as px
import pandas as pd
from dash import Dash, html, dcc, Input, Output, callback
import plotly.express as px
from dataclasses import dataclass
import json

data = pd.DataFrame(columns=["Dataset", "Alpha", "Top K", "Recall", "Precision"])
data = pd.concat(
    [
        data,
        pd.DataFrame(
            [["ml-100k", 0.1, 20, 0.2, 0.2]],
            columns=["Dataset", "Alpha", "Top K", "Recall", "Precision"],
        ),
    ]
)
debug = False


external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"]

app = Dash(__name__, external_stylesheets=external_stylesheets)

server = app.server


dataset_options = [
    {"label": entry, "value": entry} for entry in data["Dataset"].unique()
]
dataset_options_default_value = data["Dataset"].unique()[0]

alpha_options = [{"label": entry, "value": entry} for entry in data["Alpha"].unique()]
alpha_options_default_value = data["Alpha"].unique()[0]

top_k_options = [{"label": entry, "value": entry} for entry in data["Top K"].unique()]
top_k_options_default_value = data["Top K"].unique()[0]

app.layout = html.Div(
    [
        html.H1("System Evaluation"),
        html.Div(
            [
                html.Div(
                    [
                        html.H3("Dataset"),
                        dcc.Dropdown(
                            id="dataset-dropdown",
                            options=dataset_options,
                            value=dataset_options_default_value,
                        ),
                    ],
                    className="three columns",
                ),
                html.Div(
                    [
                        html.H3("Alpha"),
                        dcc.Dropdown(
                            id="alpha-dropdown",
                            options=alpha_options,
                            value=alpha_options_default_value,
                        ),
                    ],
                    className="three columns",
                ),
                html.Div(
                    [
                        html.H3("Top K"),
                        dcc.Dropdown(
                            id="top_k-dropdown",
                            options=top_k_options,
                            value=top_k_options_default_value,
                        ),
                    ],
                    className="three columns",
                ),
            ],
            className="row",
        ),
        html.Div(
            [
                html.Div([dcc.Graph(id="recall-graph")], className="six columns"),
                html.Div([dcc.Graph(id="precision-graph")], className="six columns"),
            ],
            className="row",
        ),
    ]
)


@app.callback(
    Output("recall-graph", "figure"),
    Output("precision-graph", "figure"),
    Input("alpha-dropdown", "value"),
    Input("dataset-dropdown", "value"),
    Input("top_k-dropdown", "value"),
)
def update_graph(alpha, dataset, top_k):
    filtered_data = data[
        (data["Alpha"] == alpha)
        & (data["Dataset"] == dataset)
        & (data["Top K"] == top_k)
    ]
    recall_fig = px.bar(filtered_data, x="Dataset", y="Recall")
    precision_fig = px.bar(filtered_data, x="Dataset", y="Precision")
    return recall_fig, precision_fig


# Run app and display result inline in the notebook
if __name__ == "__main__":
    app.run_server(debug=debug, port=8050)