-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarimo-prototype.py
216 lines (177 loc) · 5.72 KB
/
marimo-prototype.py
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import marimo
__generated_with = "0.1.18"
app = marimo.App()
@app.cell
def __(mo):
mo.md("# Private Report: Time Shift Data Results")
return
@app.cell
def __(pd, generatePlots):
results_df = pd.read_csv("time_shifts_full_results.csv")
plotting = generatePlots(results_df)
return results_df, plotting
@app.cell
def __(plotting, mo):
if plotting is not None:
median_run_time = round(plotting.results_df.run_time.median(), 2)
mean_run_time = round(plotting.results_df.run_time.mean(), 2)
max_run_time = round(plotting.results_df.run_time.max(), 2)
min_run_time = round(plotting.results_df.run_time.min(), 2)
_fig = mo.md(f"""
First, we visualize the distribution of run times.
Median run time: """ + str(median_run_time) + """ seconds
Mean run time: """ + str(mean_run_time) + """ seconds
Max run time: """ + str(max_run_time) + """ seconds
Min run time: """ + str(min_run_time) + """ seconds
"""
)
else:
_fig = None
_fig
return
@app.cell
def __(plotting):
if plotting is not None:
_fig = plotting.plot_run_times()
else:
_fig = None
_fig
return
@app.cell
def __(plotting, mo):
if plotting is not None:
median_mae = round(plotting.results_df["Time Series-Level MAE"].median(), 2)
mean_mae = round(plotting.results_df["Time Series-Level MAE"].mean(), 2)
_fig = mo.md(f"""
Next, we visualize the mean absolute error distribution, color-coded by issues present in the time series.
Median time series MAE: """ + str(median_mae) + """ minutes
Mean time series MAE: """ + str(mean_mae) + """ minutes
"""
)
else:
_fig = None
_fig
return
@app.cell
def __(plotting):
if plotting is not None:
_fig = plotting.plot_mae_by_issue()
else:
_fig = None
_fig
return
@app.cell
def __(plotting, mo):
if plotting is not None:
_fig = mo.md(f"""
Mean of Time Series-Level MAE, by Issue Type
"""
)
else:
_fig = None
_fig
return
@app.cell
def __(plotting, mo):
if plotting is not None:
_fig = plotting.dataframe_mae_by_issue_type()
else:
_fig = None
_fig
return
@app.cell
def __(plotting, mo):
if plotting is not None:
_fig = mo.md(f"""
We then visualize the mean absolute error distribution, color-coded by data sampling frequency.
"""
)
else:
_fig = None
_fig
return
@app.cell
def __(plotting):
if plotting is not None:
_fig = plotting.plot_mae_by_sampling_frequency()
else:
_fig = None
_fig
return
@app.cell
def __(plotting, mo):
if plotting is not None:
_fig = mo.md(f"""
Mean of Time Series-Level MAE, by Data Sampling Frequency
"""
)
else:
_fig = None
_fig
return
@app.cell
def __(plotting, mo, pd):
if plotting is not None:
_fig = plotting.dataframe_mae_by_sampling()
else:
_fig = None
_fig
return
@app.cell
def __(mo,
np,
sns,
pd,
plt,):
class generatePlots:
def __init__(self, results_df):
'''Create plotting class.'''
self.results_df = results_df
self.results_df = self.results_df.rename(columns={"issue": "Data Issue Type",
"mean_absolute_error_time_series": "Time Series-Level MAE",
"data_sampling_frequency": 'Data Sampling Frequency (minutes)'})
def plot_run_times(self):
fig = sns.histplot(self.results_df, x="run_time", bins=40)
fig.set(xlabel='Run Time (seconds)', ylabel='Number Instances')
return fig
def plot_mae_by_issue(self):
fig = sns.histplot(self.results_df,
x="Time Series-Level MAE",
hue="Data Issue Type",
bins=30)
fig.set(xlabel='Time Series-Level MAE (minutes)', ylabel='Number Instances')
return fig
def plot_mae_by_sampling_frequency(self):
fig = sns.histplot(self.results_df,
x="Time Series-Level MAE",
hue='Data Sampling Frequency (minutes)',
bins=30)
fig.set(xlabel='Time Series-Level MAE (minutes)', ylabel='Number Instances')
return fig
def dataframe_mae_by_issue_type(self):
df = self.results_df.groupby(
"Data Issue Type")["Time Series-Level MAE"].mean()
df = pd.DataFrame(df.reset_index())
return df
def dataframe_mae_by_sampling(self):
df = self.results_df.groupby(
'Data Sampling Frequency (minutes)')["Time Series-Level MAE"].mean()
df = pd.DataFrame(df.reset_index())
return df
return generatePlots,
@app.cell
def __():
import marimo as mo
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
return (
mo,
np,
sns,
pd,
plt,
)
if __name__ == "__main__":
app.run()