Ejemplo n.º 1
0
def train(histogram):
    data, centroidList, distance = Cluster.kMeans(histogram, main.CLUSTERS)
    data = Utils.prepareData(histogram)
    labels = Utils.closestCentroidList(data, centroidList)
    clf = svm.SVC(kernel='rbf')
    clf.fit(data, labels)
    return data, clf
Ejemplo n.º 2
0
def clusterDraw(data, centroidList, histogram):
    fig = plt.figure()
    ax = Axes3D(fig)
    labels = Utils.closestCentroidList(data, centroidList)
    data, labels = Utils.removeDuplicates(data, labels)
    Xs, Ys, Zs, sizes, colors = Utils.getDrawInfo(data, histogram, labels)
    scatter = ax.scatter(Xs, Ys, Zs, s=sizes, c=colors)
    plt.show()
Ejemplo n.º 3
0
def drawSlice(data, centroidList):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    labels = Utils.closestCentroidList(data, centroidList)
    clusterList = Utils.getClusters(data, labels)
    clusterA = clusterList.pop(random.randrange(len(clusterList)))
    clusterB = clusterList.pop(random.randrange(len(clusterList)))
    colorA = Utils.getAverageColor(clusterA)
    colorB = Utils.getAverageColor(clusterB)
    Xs = []
    Zs = []
    for i in range(len(clusterA)):
        Xs.append(clusterA[i][0])
        Zs.append(clusterA[i][2])
    scatter = ax.scatter(Xs, Zs, s=20, c="b")
    Xs = []
    Zs = []
    for i in range(len(clusterB)):
        Xs.append(clusterB[i][0])
        Zs.append(clusterB[i][2])
    scatter = ax.scatter(Xs, Zs, s=20, c="r")
    plt.show()