Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot log loss #984

Merged
merged 2 commits into from
May 3, 2024
Merged
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
53 changes: 16 additions & 37 deletions pdr_backend/sim/dash_plots/view_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"aimodel_varimps",
"aimodel_response",
"f1_precision_recall_vs_time",
"log_loss_vs_time",
]

empty_slider = dcc.Slider(
Expand Down Expand Up @@ -59,49 +60,27 @@ def get_header_elements(run_id, st, ts):
]


def side_by_side_graphs(figures, name1, name2):
return html.Div(
[
dcc.Graph(figure=figures[name1], id=name1, style={"width": "50%"}),
dcc.Graph(figure=figures[name2], id=name2, style={"width": "50%"}),
],
style={"display": "flex", "justifyContent": "space-between"},
)


def arrange_figures(figures):
return [
side_by_side_graphs(figures, "pdr_profit_vs_time", "trader_profit_vs_time"),
html.Div(
[
dcc.Graph(figure=figures["pdr_profit_vs_time"], style={"width": "50%"}),
dcc.Graph(
figure=figures["trader_profit_vs_time"], style={"width": "50%"}
),
],
style={"display": "flex", "justifyContent": "space-between"},
),
html.Div(
[
dcc.Graph(figure=figures["accuracy_vs_time"]),
]
),
html.Div(
[
dcc.Graph(
figure=figures["pdr_profit_vs_ptrue"], style={"width": "50%"}
),
dcc.Graph(
figure=figures["trader_profit_vs_ptrue"], style={"width": "50%"}
),
],
style={"display": "flex", "justifyContent": "space-between"},
),
html.Div(
[
dcc.Graph(
figure=figures["aimodel_varimps"],
id="aimodel_varimps",
style={"width": "50%"},
),
dcc.Graph(figure=figures["aimodel_response"], style={"width": "50%"}),
],
style={"display": "flex", "justifyContent": "space-between"},
),
html.Div(
[
dcc.Graph(figure=figures["f1_precision_recall_vs_time"]),
dcc.Graph(figure=figures["accuracy_vs_time"], id="accuracy_vs_time"),
]
),
side_by_side_graphs(figures, "pdr_profit_vs_ptrue", "trader_profit_vs_ptrue"),
side_by_side_graphs(figures, "aimodel_varimps", "aimodel_response"),
side_by_side_graphs(figures, "f1_precision_recall_vs_time", "log_loss_vs_time"),
]


Expand Down
19 changes: 19 additions & 0 deletions pdr_backend/sim/sim_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,25 @@ def plot_trader_profit_vs_ptrue(self):

return fig

@enforce_types
def plot_log_loss_vs_time(self):
clm = self.st.clm
s = f"log loss = {clm.losses[-1]:.4f}"

y = "log loss"
df = pd.DataFrame(clm.losses, columns=[y])
df["time"] = range(len(clm.losses))

fig = go.Figure(
go.Scatter(x=df["time"], y=df[y], mode="lines", name="log loss")
)

fig.update_layout(title=s)
fig.update_xaxes(title="time")
fig.update_yaxes(title=y)

return fig


def file_age_in_seconds(pathname):
stat_result = os.stat(pathname)
Expand Down
9 changes: 4 additions & 5 deletions pdr_backend/sim/test/test_dash_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,12 @@ def test_arrange_figures():
figures = {key: Figure() for key in figure_names}
result = arrange_figures(figures)
seen = set()
count = 0
for div in result:
for graph in div.children:
count += 1
if hasattr(graph, "id"):
seen.add(graph.id)

assert count == len(figure_names)
assert seen == {"aimodel_varimps"} # only one with id present for now
set(figure_names)
assert len(seen) == len(figure_names)


def test_snapshot_slider():
Expand Down Expand Up @@ -91,8 +87,11 @@ def test_get_figures_by_state():
mock_sim_plotter.plot_pdr_profit_vs_ptrue.return_value = Figure()
mock_sim_plotter.plot_trader_profit_vs_ptrue.return_value = Figure()
mock_sim_plotter.plot_f1_precision_recall_vs_time.return_value = Figure()
mock_sim_plotter.plot_log_loss_vs_time.return_value = Figure()

plotdata = Mock()
plotdata.colnames = ["var1", "var2"]

mock_sim_plotter.aimodel_plotdata = plotdata

with patch(
Expand Down
Loading