-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
75 lines (53 loc) · 2.56 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import numpy as np
import pandas as pd
import sklearn.cluster as sklearn_cluster
from sklearn import datasets
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
from agglomerative_clustering import AgglomerativeClustering
iris = datasets.load_iris()
X = iris.data
y = iris.target
n_clusters = len(iris.target_names)
print("\n===========================\n")
print("Agglomerative Clustering (Single) from Scratch")
y_predict = AgglomerativeClustering(pd.DataFrame(X), n_clusters, 'single').fit_predict()
print(y_predict)
print ('Confusion Matrix :', confusion_matrix(y, y_predict))
print ('Accuracy Score :', accuracy_score(y, y_predict))
print("\n===========================\n")
print("Agglomerative Clustering (Single) SKLearn")
y_predict = sklearn_cluster.AgglomerativeClustering(linkage='single').fit_predict(X)
print(y_predict)
print ('Confusion Matrix :', confusion_matrix(y, y_predict))
print ('Accuracy Score :', accuracy_score(y, y_predict))
print("\n===========================\n")
print("Agglomerative Clustering (Complete) from Scratch")
y_predict = AgglomerativeClustering(pd.DataFrame(X), n_clusters, 'complete').fit_predict()
print(y_predict)
print ('Confusion Matrix :', confusion_matrix(y, y_predict))
print ('Accuracy Score :', accuracy_score(y, y_predict))
print("\n===========================\n")
print("Agglomerative Clustering (Complete) SKLearn")
y_predict = sklearn_cluster.AgglomerativeClustering(linkage='complete').fit_predict(X)
print(y_predict)
print ('Confusion Matrix :', confusion_matrix(y, y_predict))
print ('Accuracy Score :', accuracy_score(y, y_predict))
print("\n===========================\n")
print("Agglomerative Clustering (Average) from Scratch")
y_predict = AgglomerativeClustering(pd.DataFrame(X), n_clusters, 'average').fit_predict()
print(y_predict)
print ('Confusion Matrix :', confusion_matrix(y, y_predict))
print ('Accuracy Score :', accuracy_score(y, y_predict))
print("\n===========================\n")
print("Agglomerative Clustering (Average) SKLearn")
y_predict = sklearn_cluster.AgglomerativeClustering(linkage='average').fit_predict(X)
print(y_predict)
print ('Confusion Matrix :', confusion_matrix(y, y_predict))
print ('Accuracy Score :', accuracy_score(y, y_predict))
print("\n===========================\n")
print("Agglomerative Clustering (Average-Group) from Scratch")
y_predict = AgglomerativeClustering(pd.DataFrame(X), n_clusters, 'average-group').fit_predict()
print(y_predict)
print ('Confusion Matrix :', confusion_matrix(y, y_predict))
print ('Accuracy Score :', accuracy_score(y, y_predict))