Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用matplotlib实现相当混乱的矩阵可视化_Matplotlib_Data Visualization_Confusion Matrix - Fatal编程技术网

使用matplotlib实现相当混乱的矩阵可视化

使用matplotlib实现相当混乱的矩阵可视化,matplotlib,data-visualization,confusion-matrix,Matplotlib,Data Visualization,Confusion Matrix,我想知道是否有一些模板可以在matplotlib中查看具有类似渲染的混淆矩阵,我忽略了其中的特定术语 我试过用你的fig 2做类似的事情。这是我使用手写数字数据的代码 import numpy as np from scipy import ndimage from matplotlib import pyplot as plt from sklearn import manifold, datasets from scipy.spatial.distance import pdist, sq

我想知道是否有一些模板可以在matplotlib中查看具有类似渲染的混淆矩阵,我忽略了其中的特定术语


我试过用你的fig 2做类似的事情。这是我使用手写数字数据的代码

import numpy as np
from scipy import ndimage
from matplotlib import pyplot as plt
from sklearn import manifold, datasets
from scipy.spatial.distance import pdist, squareform
from scipy.cluster.hierarchy import leaves_list, linkage

def get_small_Xy(X, y, n=8):
    X = np.vstack([X[y==e][0:n] for e in np.unique(y)])
    y = np.hstack([[e]*n for e in np.unique(y)])
    return X, y

# Load digit data
X_, y_ = datasets.load_digits(return_X_y=True)

# get a small set of data
X, y = get_small_Xy(X_, y_)

# Get similarity matrix
D = 1-squareform(pdist(X, metric='cosine'))

Z = linkage(D, method='ward')
ind = leaves_list(Z)
D = D[ind, :]
D = D[:, ind]

# labels and colors related
lbs = np.array([i if i==j else 10 for i in y for j in y])
colors = np.array(['C{}'.format(i) for i in range(10)]+['gray'])
colors[7] = '#413c39'
c = colors[lbs]


font1 = {'family': 'Arial',
        'weight': 'normal',
        'size': 8,
        }

fig, ax = plt.subplots(1, 1, figsize=(10, 10))

n = np.product(X.shape[0])
xx, yy = np.meshgrid(range(n), range(n))
xy = np.stack([xx.ravel(), yy.ravel()]).T


ax.scatter(xy[:, 0], xy[:, 1], s=D**4*30, fc=c, ec=None, alpha=0.8)
ax.set_xlim(-1, n)
ax.set_ylim(n, -1)

ax.tick_params(top=False, bottom=False, left=False, right=False, labelleft=False, labelbottom=False)

# place text
for i, e in enumerate(y):
    ax.text(-1.2, i, e, ha='right', va='center', fontdict=font1, c=colors[e])
    
for i, e in enumerate(y):
    ax.text(i, -1, e, ha='center', va='bottom', fontdict=font1, c=colors[e])
    
# draw lines
for e in np.where(np.diff(y))[0]:
    ax.axhline(e+0.5, color='gray', lw=0.5, alpha=0.8)
    ax.axvline(e+0.5, color='gray', lw=0.5, alpha=0.8)
一个问题是所有点的alpha值,这似乎不可能在一次运行中使用不同的值设置打印散点