forked from jasonfreak/ple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
many2many.py
39 lines (30 loc) · 1.06 KB
/
many2many.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
#!/usr/bin/env python
import numpy as np
from sklearn.decomposition import PCA
from feature import Feature
def doWithPCA(model, featureList):
leaves = np.array([])
n_features = len(featureList)
for i in range(model.n_components_):
newFeature = Feature(model.__class__.__name__)
leaves = np.append(leaves, newFeature)
for i in range(n_features):
feature = featureList[i]
for j in range(model.n_components_):
newFeature = leaves[j]
feature.transform(model.__class__.__name__, newFeature)
return leaves
def main():
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
root = Feature('root')
featureList = np.array([])
for i in range(len(X[0])):
feature = Feature('feature_%d' % i)
root.transform('init', feature)
featureList = np.append(featureList, feature)
model = PCA(n_components=1)
model.fit(X)
doWithPCA(model, featureList)
root.printTree()
if __name__ == '__main__':
main()