-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclustering_freelancer.py
executable file
·64 lines (40 loc) · 1.42 KB
/
clustering_freelancer.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
#!/usr/bin/env python2
import sqlite3
import numpy as np
from sklearn.cluster import KMeans
import config.clustering as g_config
from logger import Logger
logger = Logger()
SEL_PROJECTS_QUERY = 'SELECT "technologies" FROM "projects" LIMIT %d'
con = sqlite3.connect("datasets/freelancer.sqlite")
cursor = con.cursor()
def index_technologies():
technologies = {}
nb_projects = 0
cursor.execute(SEL_PROJECTS_QUERY % g_config.fl_projects_limit)
for row in cursor.fetchall():
nb_projects += 1
for tech in row[0].split(' '):
t = int(tech)
if t not in technologies:
technologies[t] = len(technologies)
logger.log("# technologies: %d" % len(technologies))
logger.log("# projects: %d" % nb_projects)
return technologies, nb_projects
def scikit_learn_format():
technologies, nb_projects = index_technologies()
data = np.zeros((nb_projects, len(technologies)), dtype=np.uint8)
cursor.execute(SEL_PROJECTS_QUERY % g_config.fl_projects_limit)
for index, row in enumerate(cursor.fetchall()):
for tech in row[0].split(' '):
data[index, technologies[int(tech)]] = 1
return np.transpose(data)
def cluster():
estimator = KMeans(n_clusters=g_config.nb_fl_clusters)
data = scikit_learn_format()
labels = estimator.fit_predict(data)
print(labels)
def main():
cluster()
if __name__ == "__main__":
main()