- How to get the Weight of Evidence (WOE) and Information Value (IV) in Python/pandas?
- How to save weights of keras model for each epoch?
- How to avoid reloading ML model every time when I call python script?
- How to split data based on a column value in sklearn
- How to use sklearn ( chi-square or ANOVA) to removes redundant features
- How to graph centroids with KMeans
- How to solve ' CUDA out of memory. Tried to allocate xxx MiB' in pytorch?
- How to calculate TPR and FPR in Python without using sklearn?
- How to create a custom PreprocessingLayer in TF 2.2
- Python: How to retrive the best model from Optuna LightGBM study?
- How to predownload a transformers model
- How to reset Keras metrics?
- How to handle missing values (NaN) in categorical data when using scikit-learn OneHotEncoder?
- How to get probabilities along with classification in LogisticRegression?
- How to choose the number of units for the Dense layer in the Convoluted neural network for a Image classification problem?
- How to use pydensecrf in Python3.7?
- How to set class weights in DecisionTreeClassifier for multi-class setting
- How to Extract Data from tmdB using Python
- How to add attention layer to a Bi-LSTM
- How to include SimpleImputer before CountVectorizer in a scikit-learn Pipeline?
Plotly: How to make an annotated confusion matrix using a heatmap?
Written by- Aionlinecourse2095 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()