How would I create a subplot using a bunch of go.Figure objects that have multiple lines and data points themselves? To explain:
# Data Visualization
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import pandas as pd
class DataVis:
def __init__(self, history):
self.epoch_list = history['epoch']
self.accuracy_list = history['accuracy']
self.loss_list = history['loss']
self.recall = history['recall'] # true_positives
self.precision = history['precision']
self.false_positives = history['false_positives']
self.true_negatives = history['true_negatives']
self.false_negatives = history['false_negatives']
self.last_auc_score = history['auc'].iloc[-1]
self.val_accuracy_list = history['val_accuracy']
self.val_loss_list = history['val_loss']
self.val_recall = history['val_recall']
self.val_precision = history['val_precision']
self.val_false_positives = history['val_false_positives']
self.val_true_negatives = history['val_true_negatives']
self.val_false_negatives = history['val_false_negatives']
self.val_last_auc_score = history['val_auc'].iloc[-1]
def loss_graph(self):
loss_plots = [go.Scatter(x=self.epoch_list,
y=self.loss_list,
mode='lines',
name='Loss',
line=dict(width=4)),
go.Scatter(x=self.epoch_list,
y=self.val_loss_list,
mode='lines',
name='Validation Loss',
line=dict(width=4))]
self.loss_figure = go.Figure(data=loss_plots)
self.loss_figure.update_layout(
font_color='black',
title_font_color='black',
title=dict(text='Loss Graph',
font_size=30),
xaxis_title=dict(text='Epochs',
font_size=25),
yaxis_title=dict(text='Loss',
font_size=25),
legend=dict(font_size=15))
def error_rate_graph(self):
def error_rate_computation(accuracy):
error_rate_list = []
for accuracy_instance in accuracy:
error_rate_list.append(1 - accuracy_instance)
return error_rate_list
train_error_rate = error_rate_computation(self.accuracy_list)
valid_error_rate = error_rate_computation(self.val_accuracy_list)
error_rate_plots = [go.Scatter(x=self.epoch_list,
y=train_error_rate,
mode='lines',
name='Error Rate',
line=dict(width=4)),
go.Scatter(x=self.epoch_list,
y=valid_error_rate,
mode='lines',
name='Validation Error Rate',
line=dict(width=4))]
self.error_rate_figure = go.Figure(data=error_rate_plots)
self.error_rate_figure.update_layout(
font_color='black',
title_font_color='black',
title=dict(text='Error Rate Graph',
font_size=30),
xaxis_title=dict(text='Epochs',
font_size=25),
yaxis_title=dict(text='Error Rate',
font_size=25),
legend=dict(font_size=15))
def subplot_creation(self):
metric_figure = make_subplots(
rows=3, cols=2,
specs=[[{}, {}],
[{}, {}],
[{'colspan': 2}, {}]])
metric_figure.append_trace(self.loss_figure, row=1, col=1)
metric_figure.append_trace(self.error_rate_figure, row=1, col=2)
metric_figure.show()
csv = pd.read_csv(f'{dir}\\{csv_file}')
test = DataVis(csv)
test.loss_graph()
test.error_rate_graph()
test.subplot_creation()
The error I get when trying to create the subplot is โinvalid element(s) received for the โdataโ property of Invalid elements include: [Figureโ. I think I know why the error occurs, but is there a way around it? I still want to change the layout of each graph and have multiple lines on a single graph. I found Jupyter Notebook Viewer to not be of much helpโฆ