|
|
import numpy as np |
|
|
import matplotlib.pyplot as plt |
|
|
import umap |
|
|
|
|
|
|
|
|
file1 = "test_features.npz" |
|
|
file2 = "case_features.npz" |
|
|
|
|
|
titles = ["Before Finetune", "After Finetune"] |
|
|
|
|
|
|
|
|
umap_kwargs = dict(n_components=2, random_state=465, metric="euclidean") |
|
|
|
|
|
|
|
|
color_map = {0: "#81B9E9", 1: "#EBB4B1"} |
|
|
label_map = {0: "Not Improved", 1: "Improved"} |
|
|
|
|
|
|
|
|
data1 = np.load(file1) |
|
|
feats1 = data1["features"] |
|
|
gts1 = data1["gts"].ravel() |
|
|
|
|
|
data2 = np.load(file2) |
|
|
feats2 = data2["features"] |
|
|
gts2 = data2["gts"].ravel() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reducer = umap.UMAP(**umap_kwargs) |
|
|
emb1 = reducer.fit_transform(feats1) |
|
|
emb2 = reducer.fit_transform(feats2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fig, axes = plt.subplots(1, 2, figsize=(8, 5), sharex=False, sharey=False) |
|
|
fig.suptitle(" R2 UMAP Visualization", fontsize=26) |
|
|
|
|
|
for ax, emb, gts, title in zip(axes, (emb1, emb2), (gts1, gts2), titles): |
|
|
for cls in (0, 1): |
|
|
mask = (gts == cls) |
|
|
ax.scatter( |
|
|
emb[mask, 0], emb[mask, 1], |
|
|
c=color_map[cls], |
|
|
label=label_map[cls], |
|
|
s=50, alpha=0.8 |
|
|
) |
|
|
ax.set_title(title, fontsize=20) |
|
|
|
|
|
|
|
|
ax.set_xticks([]) |
|
|
ax.set_yticks([]) |
|
|
|
|
|
|
|
|
handles = [] |
|
|
labels = [] |
|
|
for cls in (0, 1): |
|
|
handles.append(plt.Line2D([], [], marker="o", color=color_map[cls], |
|
|
linestyle="", markersize=6)) |
|
|
labels.append(label_map[cls]) |
|
|
|
|
|
fig.legend( |
|
|
handles, labels, |
|
|
loc="lower center", |
|
|
ncol=2, |
|
|
frameon=False, |
|
|
bbox_to_anchor=(0.5, -0.02), |
|
|
fontsize=20, |
|
|
markerscale=2.0, |
|
|
) |
|
|
|
|
|
plt.tight_layout() |
|
|
plt.subplots_adjust(bottom=0.12, wspace=0.08) |
|
|
plt.savefig('umap.svg') |
|
|
|