-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIndicationClustering.py
More file actions
82 lines (61 loc) · 1.39 KB
/
IndicationClustering.py
File metadata and controls
82 lines (61 loc) · 1.39 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
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
import numpy as np
from sklearn import covariance
from sklearn.preprocessing import scale
import matplotlib.pylab as plt
from sklearn.mixture import GaussianMixture
from sklearn.cluster import KMeans
d = np.loadtxt('/Users/jlesage/Dropbox/Eclipse/IndicationReport.csv',delimiter=',')
# F = d[:,(1,2,9)]
# F = d[:,9].reshape(-1,1)
X = d[:,(3,4,5,6)]
Xkeep = X[:,3]>-55.
# print(Xkeep)
# print(Xkeep.shape)
#
# print(X.shape)
X = X[Xkeep,:]
# print(X.shape)
# gm = GaussianMixture(n_components=2,random_state=21)
# gm.fit(X)
#
# y = gm.predict_proba(X)
c = KMeans(n_clusters=2,random_state=42)
c.fit(X)
y = c.predict(X)
print(c.cluster_centers_)
print(y)
# print(c.transform(X))
# plt.plot(np.min(np.array(c.transform(X)),axis=1))
#
# plt.show()
# print(y)
# g = [(5.,-23.),(21.,-50.),(4.,-76.)]
#
# FG = np.zeros((G.shape[0],1))
# for i in range(G.shape[0]):
#
# FG[i,0] = min([np.sqrt(((G[i][0]+G[i][1] - gg[0])*0.5)**2 + ((G[i][2]+G[i][3])*0.5 - gg[1])**2) for gg in g])
#
# # FG[i,1] = np.arctan2(G[i][3]-G[i][2],G[i][1]-G[i][0])
#
# F = scale(np.hstack((F,FG)))
#
# O = covariance.EllipticEnvelope(assume_centered=True, random_state=21)
#
# O.fit(F)
#
# y = np.array(O.predict(F))
#
# L = O.mahalanobis(F)
#
# # plt.hist(L,bins=50)
# #
# # plt.show()
#
# print(np.sort(L))
# print(np.argsort(L))
#
# savetxt('/Users/jlesage/Dropbox'())
# print(O.mahalanobis(FG))
#
# print(np.where(y==-1)[0]+1)