-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathplot_each_model.py
More file actions
128 lines (111 loc) · 4.3 KB
/
plot_each_model.py
File metadata and controls
128 lines (111 loc) · 4.3 KB
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
"""
Takes a Simulation's CSV data and plots each model by calibration.
"""
import os
import pandas as pd
import plotly.graph_objects as go # type: ignore
# Example file path
FILE_PATH = "/Users/abc/Dev/ClassifLinearElasticNet Balanced_50kIterations_Summary.csv"
def load_data_from_csv(file_path):
"""
Loads Sim data from a CSV file into 2 dataframes.
Returns:
Two dataframes, one with ETH data and one without.
"""
# Function body
df = pd.read_csv(file_path, na_values=[""])
df["Calibration"] = df["Calibration"].fillna("None")
model_name = os.path.basename(file_path).split("_")[0]
df["Model"] = model_name
df_without_eth = df[
~df["predictoor_ss.predict_train_feedsets"].str.contains("ETH")
].copy()
df_with_eth = df[
df["predictoor_ss.predict_train_feedsets"].str.contains("ETH")
].copy()
color_mapping = {"Sigmoid": "orange", "Isotonic": "blue", "None": "fuchsia"}
df_without_eth["Color"] = df_without_eth["Calibration"].map(color_mapping)
df_with_eth["Color"] = df_with_eth["Calibration"].map(color_mapping)
print(
f"Data Types:\n{df.dtypes}"
) # Check the data types to ensure they are read correctly
return df_without_eth, df_with_eth
def generate_traces(df, calibrations, autoregressive_n, y_column):
"""
Generates traces for the given dataframes to be plotted.
Returns:
List of traces.
"""
traces = []
for calibration in calibrations:
for autoregressive in autoregressive_n:
filtered_df = df[
(df["Calibration"] == calibration)
& (
df["predictoor_ss.aimodel_data_ss.autoregressive_n"]
== int(autoregressive)
)
]
if not filtered_df.empty:
traces.append(
go.Scatter(
x=filtered_df["predictoor_ss.aimodel_data_ss.max_n_train"],
y=filtered_df[y_column],
name=f"{calibration} & Autoregressive_n = {autoregressive}",
marker={"color": filtered_df["Color"].iloc[0]},
customdata=[calibration, autoregressive],
)
)
else:
print(
f"No data for {calibration} with Autoregressive_n = {autoregressive}"
)
return traces
layout = {
"title": {"text": "Traces Sorted by Ascending Predictoor Profit"},
"xaxis": {
"title": "Max_N_Train",
"tickvals": [1000, 2000, 5000],
"ticktext": ["1000", "2000", "5000"],
},
"margin": {"l": 70, "r": 20, "t": 60, "b": 40},
"showlegend": True,
"legend": {"title": {"text": "Traces Sorted by Ascending Predictoor Profit"}},
"hovermode": "closest",
}
def plot_data(filename, calibration, autoregressive_n, y_column):
"""
Plots the data from the given CSV file.
Returns:
Two plots, one with ETH data and one without.
"""
df_without_eth, df_with_eth = load_data_from_csv(filename)
traces_without_eth = generate_traces(
df_without_eth, calibration, autoregressive_n, y_column
)
yaxis_title = (
"Predictoor Profit (OCEAN)"
if y_column == "pdr_profit_OCEAN"
else "Trader Profit (USD)"
)
fig_without_eth = go.Figure(data=traces_without_eth, layout=layout)
fig_without_eth.update_layout(
title=f"{df_without_eth['Model'].iloc[0]} - "
+ f"Predictoor Profit Benchmarks (Trained with BTC-USDT Data) - {y_column}",
yaxis_title=yaxis_title,
)
fig_without_eth.show()
traces_with_eth = generate_traces(
df_with_eth, selected_calibrations, selected_autoregressives, y_column
)
fig_with_eth = go.Figure(data=traces_with_eth, layout=layout)
fig_with_eth.update_layout(
title=f"{df_with_eth['Model'].iloc[0]} - "
+ f"Predictoor Profit Benchmarks (Trained with BTC-USDT & ETH-USDT Data) - {y_column}",
yaxis_title=yaxis_title,
)
fig_with_eth.show()
selected_calibrations = ["None", "Isotonic", "Sigmoid"]
selected_autoregressives = ["1", "2"]
Y_COLUMN = "pdr_profit_OCEAN" # Example Column to plot: 'pdr_profit_OCEAN' or 'trader_profit_USD'
plot_data(FILE_PATH, selected_calibrations, selected_autoregressives, Y_COLUMN)