Пример #1
0
def getClustersResult():
    data_name = request.args.get('dataname', '')
    kmean_number = request.args.get('kmeannumber', '')
    if data_name == '':
        data_name = 'normOutputCleanevaluation.txt'
    data_path = './dump/' + data_name
    method = request.args.get('method', '')

    # Use the method send to clusterize the data
    t1 = time.time()
    if method == 'kmean':
        clusterList, barycentersList, infosList = kmeanTreatment(data_path, int(kmean_number))
    elif method == 'meanshift':
        clusterList, barycentersList, infosList = meanShiftTreatment(data_path)
    else:
        clusterList, barycentersList, infosList = kmeanTreatment(data_path, 4)
    t2 = time.time()
    print 'Clusterized in:', strtimedelta(t1,t2)

    clusterNumber = range(len(clusterList))
    cluster_mbtags = []
    for i in clusterNumber:
        artist_number = len(infosList[0][i])
        temp_dic = {}
        for k, v in infosList[2][i].iteritems():
            temp_dic[k] = format(float(v)*100 / artist_number, '.2f')
        cluster_mbtags.append(sorted(temp_dic.iteritems(), key=operator.itemgetter(1), reverse = True))

    # Make a dump of the results!
    with open('./cluster/' + method + data_name, 'wb') as f:
        cPickle.dump([clusterList, barycentersList, infosList], f)

    return render_template('clusteringresult.html', 
        datapath = data_path,
        method = method,
        clusterNumber = clusterNumber,
        clusterList = clusterList,
        barycentersList = barycentersList,
        infosList = infosList,
        mbtags_sorted = cluster_mbtags)
Пример #2
0
		for i in feature_number:
			new_vector.append(row[1][i-1])
		new_data.append([new_info, new_vector])

	print "New data generated"
	
	filename = 'dataset_' + str(len(request)) + '_' + name

	data_path = './dump/normOutputClean' + filename + '.txt'
	# Dump the generated data
	with open(data_path, 'wb') as f:
		cPickle.dump(new_data, f)

	print "Data dumped"

	clusterList, barycentersList, infosList = kmeanTreatment(data_path, 5)

	with open('./cluster/kmean5' + name + '.txt', 'wb') as f:
		cPickle.dump([clusterList, barycentersList, infosList], f)

	print "Kmean 5 ok and dumped"

	clusterList, barycentersList, infosList = kmeanTreatment(data_path, 10)

	with open('./cluster/kmean10' + name + '.txt', 'wb') as f:
		cPickle.dump([clusterList, barycentersList, infosList], f)

	print "Kmean 10 ok and dumped"

	clusterList, barycentersList, infosList = kmeanTreatment(data_path, 20)