-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclustering_v2.py
92 lines (57 loc) · 1.81 KB
/
clustering_v2.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#! /usr/bin/env python
# -*- coding: UTF-8 -*-
"""
Clustering Version 2
=====================
After Feature Extraction, that returns a data of the format
[(filename, linenum, vote, sentence, feat1, feat2, ...)]
Improving the initial clustering mechanism (via R scripts) to
SciKit based clustering and producing plots
For clustering there shall be no resampling required.
We are looking for clues via unsupervised learning approach.
Attempting the following clustering operations
- [ ] k-means
- [ ] mini k-means
======================
"""
from __future__ import division
from optparse import OptionParser
from pprint import pprint
import pandas as pd
def getUserInput():
"""
The following flags are supported
-f or --file
provide the path to the app features file extracted
-c or --cluster
choose a clustering engine
- km (for kmeans)
- mkm (for minikmeans)
"""
optionparser = OptionParser()
usage = "usage: $python clustering_v2.py arg1 arg2"
optionparser.add_option('-c', '--cl', dest="cluster", default="km")
optionparser.add_option('-f', '--file', dest="file")
(option, args) = optionparser.parse_args()
if not option.file:
print "App Features file not provided"
print usage
print getUserInput.__doc__
return
else:
return {'cluster': option.cluster, 'file': option.file}
def loadData(filepath):
"""
load the features from the appfeatures file, where features have
been stored after extraction
"""
featDframe = pd.read_csv(filepath)
print featDframe.columns
return featDframe
def main():
print __doc__
userInput = getUserInput()
## a pandas dataframe object
appData = loadData(userInput['file'])
if __name__ == "__main__":
main()