-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclustering_tests.py
More file actions
48 lines (39 loc) · 1.24 KB
/
Copy pathclustering_tests.py
File metadata and controls
48 lines (39 loc) · 1.24 KB
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
from analysis import *
from vis import *
import numpy as np
data_contents, student_codes = read_python_files("data/test2")
tokens = [ast_to_tokens(file) for file in data_contents]
vectorizer = make_vectorizer(tokens)
vectors = vectorizer.transform(tokens)
# K-Means n_clusters=10
clusters = get_clusters(vectors, n_clusters=10)
run_vis(vectors, clusters)
# show the plot
plt.show()
plt.savefig("results/clusters_KMeans-10-2.png")
# K-Means n_clusters=5
clusters = get_clusters(vectors, n_clusters=5)
run_vis(vectors, clusters)
# show the plot
plt.show()
plt.savefig("results/clusters_KMeans-5-2.png")
from sklearn.cluster import DBSCAN
# DBSCAN eps=0.5
clusters = get_clusters(vectors, clustering=DBSCAN)
run_vis(vectors, clusters)
# show the plot
plt.show()
plt.savefig("results/clusters_DBSCAN-0.5-2.png")
# DBSCAN eps=1
clusters = get_clusters(vectors, clustering=DBSCAN, eps=1)
run_vis(vectors, clusters)
# show the plot
plt.show()
plt.savefig("results/clusters_DBSCAN-1.0-2.png")
from sklearn.cluster import SpectralClustering
# SpectralClustering n_clusters=5
clusters = get_clusters(vectors, clustering=SpectralClustering, n_clusters=5)
run_vis(vectors, clusters)
# show the plot
plt.show()
plt.savefig("results/clusters_SpectralClustering-5-2.png")