示例#1
0
 def calculate_silhoutte(self,location,labels):
     util=Utilty()
     self.result=util.read_file("C:\personal\PhD\Dataset\sonar-data-set\glass-classification\\glass.csv",",")
     '''print('result',result.shape[0])'''
     D = pairwise_distances(self.result, metric='euclidean')
     '''print('result', D)'''
     '''labels=np.ones(result.shape[0])
     labels[0:300]=0'''
     print('silhoutte labels', labels)
     silhoute=silhouette_score(D, labels, "precomputed")
     '''print('silhoutte labels', labels)
     print('silhoutte score',silhoute)'''
     return silhoute
    for key in large_clusters:
        array = large_clusters[key]
        centroid = np.mean(array, axis=0)
        for itr in range(len(large_clusters[key])):
            anomalyscore_largeclusters = np.linalg.norm(array[itr] - centroid)
            anomaly_largeclusters[anomalyscore_largeclusters] = array[itr]

    return anomaly_largeclusters


# In[4]:

util = Utilty()
'''reading data'''
result = util.read_file("processed_dataset_D1.csv", ",")
obj = MSMA(2, len(result), '', 12, result)
print('dataset shape', result.shape)
'''obtaining best population sample'''
final_dict = obj.start_clustering()
print('final dict')
print(final_dict, '\n')

final_cluster = final_dict[max(final_dict)]
'''running recursive algorithm'''
print('running binary tree\n')
count = 0
leaf_nodes = []
tree_dic = {}

a = binary_tree(result, final_cluster, count, tree_dic, leaf_nodes)