- Best AI Text Generators for High Quality Content Writing
- Tensorflow Error on Macbook M1 Pro - NotFoundError: Graph execution error
- How does GPT-like transformers utilize only the decoder to do sequence generation?
- How to set all tensors to cuda device?
- How should I use torch.compile properly?
- How do I check if PyTorch is using the GPU?
- WARNING:tensorflow:Using a while_loop for converting cause there is no registered converter for this op
- How to use OneCycleLR?
- Error in Python script "Expected 2D array, got 1D array instead:"?
- How to save model in .pb format and then load it for inference in Tensorflow?
- Top 6 AI Logo Generator Up Until Now- Smarter Than Midjourney
- Best 9 AI Story Generator Tools
- The Top 6 AI Voice Generator Tools
- Best AI Low Code/No Code Tools for Rapid Application Development
- YOLOV8 how does it handle different image sizes
- Best AI Tools For Email Writing & Assistants
- 8 Data Science Competition Platforms Beyond Kaggle
- Data Analysis Books that You Can Buy
- Robotics Books that You Can Buy
- Data Visualization Books that You can Buy
Plotly: How to make an annotated confusion matrix using a heatmap?
Written by- Aionlinecourse1726 times views
To create an annotated confusion matrix using a heatmap in Plotly, you will need to use the go.Heatmap trace type. Here is an example of how you can do this:
import plotly.express as pxThis will create a heatmap of the confusion matrix, with each cell in the matrix annotated with its value. You can customize the appearance of the heatmap and the annotations by using the various options available in the go.Heatmap and fig.add_annotation functions.
import plotly.graph_objects as go
# Define the confusion matrix and labels
confusion_matrix = [[10, 2, 3], [4, 5, 6], [7, 8, 9]]
labels = ['Class 1', 'Class 2', 'Class 3']
# Create the heatmap trace
heatmap = go.Heatmap(z=confusion_matrix, x=labels, y=labels, colorscale='Viridis')
# Create the figure and add the heatmap trace
fig = go.Figure(data=[heatmap])
# Add annotations for each cell in the confusion matrix
for i in range(len(confusion_matrix)):
for j in range(len(confusion_matrix[i])):
fig.add_annotation(
text=confusion_matrix[i][j],
x=labels[j],
y=labels[i],
xref='x',
yref='y'
)
# Show the figure
fig.show()