-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from HBPMedical/feat/add-matching-widget-and-r…
…efine-embedding-widget refactor+feat: refine widget for embedding visualization and ad widget to visualize matching distance results
- Loading branch information
Showing
8 changed files
with
507 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
"""Module to plot the initial matching results between the input dataset columns and the target CDE codes.""" | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import matplotlib.pyplot as plt | ||
import seaborn as sns | ||
|
||
# Define colors used to plot the column and CDE code embeddings | ||
# '#4fa08b' green / '#009E73' green / '#0072B2' blue / '#FFA500' orange | ||
COLORS = ["#0072B2", "#FFA500"] | ||
# Set seaborn style | ||
sns.set_style("darkgrid") | ||
sns.set( | ||
rc={ | ||
"axes.facecolor": "#081512", | ||
"figure.facecolor": "#081512", | ||
"text.color": "white", | ||
"axes.edgecolor": "white", | ||
"patch.edgecolor": "#081512", | ||
"xtick.color": "white", | ||
"ytick.color": "white", | ||
"axes.labelcolor": "white", | ||
"grid.color": "#4fa08b", | ||
"axes3d.xaxis.panecolor": "#081512", | ||
"axes3d.yaxis.panecolor": "#081512", | ||
"axes3d.zaxis.panecolor": "#081512", | ||
"ytick.major.pad": 8, | ||
} | ||
) | ||
|
||
|
||
def heatmap_matching( | ||
figure, matrix, inputDatasetColumns, targetCDECodes, matchingMethod | ||
): | ||
"""Render a heatmap of the initial matching results between the input dataset columns and the target CDE codes. | ||
Parameters | ||
---------- | ||
figure: matplotlib.figure.Figure | ||
Figure to render the heatmap of the matching results. | ||
matrix: numpy.ndarray | ||
Similarity / distance matrix of the matching results. | ||
inputDatasetColumns: list | ||
List of the input dataset columns. Used as ytick labels. | ||
targetCDECodes: list | ||
List of the target CDE codes. Used as xtick labels. | ||
matchingMethod: str | ||
Matching method used to generate the similarity / distance matrix. | ||
Used to generate the title of the figure. | ||
""" | ||
# Generate the figure | ||
left, bottom, width, height = 0.2, 0.1, 0.8, 0.2 | ||
ax = figure.add_axes([left, bottom, width, height]) | ||
xtickLabels = targetCDECodes | ||
ytickLabels = inputDatasetColumns | ||
sns.heatmap( | ||
matrix, | ||
ax=ax, | ||
xticklabels=xtickLabels, | ||
yticklabels=ytickLabels, | ||
annot=True, | ||
fmt=".2f", | ||
cmap="viridis", | ||
) | ||
ax.tick_params(top=True, labeltop=True, bottom=False, labelbottom=False) | ||
|
||
distance_type = ( | ||
r"$(1 - 0.01 * \mathrm{LevenshteinRatio})$" | ||
if matchingMethod == "fuzzy" | ||
else "Cosine distance" | ||
) | ||
title = ( | ||
f"Distances for the most 10 similar CDE codes\n" | ||
f"(method: {matchingMethod}, distance: {distance_type})" | ||
) | ||
ax.set_title(title) | ||
plt.xticks(rotation=75) | ||
plt.yticks(rotation=90) | ||
return figure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.