Пример #1
0
img = np.zeros((nx, nz), dtype=int)
img.fill(5)

#air
for ind, (x, z) in enumerate(locations):
    i = int((x - 14700) // 40)
    k = int((z - 2200) // 20)

    img[i, k] = 4

for c, cluster in enumerate([kmeans, pca, fcew, sfcew, fc, sfc]):
    fig = plt.figure(figsize=(20, 10))
    ax = fig.add_subplot(111, aspect='equal')

    #ore
    new_clusters = adjust_clusters(cluster, equivalences[c])

    for ind, (x, z) in enumerate(locations_ore):
        i = int((x - 14700) // 40)
        k = int((z - 2200) // 20)

        img[i, k] = new_clusters[ind]

    new_img = img[20:80, 10:]
    nx2, nz2 = new_img.shape

    ax.set_xlim(0, nx2 * sx)
    ax.set_ylim(0, nz2 * sz)

    for i in range(nx2):
        for k in range(nz2):
Пример #2
0
    equivalences[1] = {0:3, 1:1, 2:2, 3:0, 4:4}

    equivalences[2] = {0:2, 1:0, 2:1, 3:3, 4:4}
    equivalences[3] = {0:2, 1:0, 2:1, 3:3, 4:4}

    equivalences[4] = {0:1, 1:0, 2:2, 3:3, 4:4}
    equivalences[5] = {0:1, 1:0, 2:2, 3:3, 4:4}
    
    clay_color = ['r','b','g']

    i = 5
    cluster = sfc
        
    if i in equivalences:
        adjust_cluster = adjust_clusters(cluster,equivalences[i])
    else:
        adjust_cluster =  cluster

    fignames = ['fig7a','fig7b','fig7c','fig7d']
    
    print("ND",ND,attributes)

                
    for var in range(ND-1):
        fig, ax = plt.subplots(figsize=(6, 6)) 
        #ax.set_ylim([mins[v],maxs[v]])
        if var_types[var] == 3:
            counter = Counter(data[:,var])
            mostc =  counter.most_common()
            cats = len(mostc)
            for j in range(NC):
                if j in equivalence:
                    c = equivalence[j]
                else:
                    c = j

                cluster = np.where(clusters[true_c] == c)[0]
                cm[i, j] = len(cluster)

        return cm

    classes = ['C1', 'C2', 'C3', 'C4']
    #KMeans
    i = 1
    if i in equivalences:
        adjust_cluster = adjust_clusters(kmeans_clusters, equivalences[i])
    else:
        adjust_cluster = kmeans_clusters

    cm_kmeans = build_cm(NC, true_clusters, adjust_cluster)

    fig, ax = plt.subplots()
    plot_confusion_matrix(cm_kmeans,
                          classes,
                          normalize=True,
                          title='Confusion matrix K-Means',
                          cmap=plt.cm.Blues,
                          xlabel="Predicted",
                          ylabel="True")

    plt.savefig("../figures/confusion-matrix-kmeans-ds4")