-
Notifications
You must be signed in to change notification settings - Fork 0
/
em_gcmh1.py
40 lines (31 loc) · 1.09 KB
/
em_gcmh1.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
import numpy as np
import pandas as pd
from sklearn.mixture import GaussianMixture
import matplotlib.pyplot as plt
import seaborn as sns
CLUSTER=11
BIAS='GCMH'
for s in range(1, 11):
simData = pd.read_csv('./summary.additive_select_split' + str(s) + '.csv', ',')
OUTPUT = './1d_split/em_1d_gcmh_tied' + str(s) + '/'
ks = simData['KS']
bbgp = simData['BBGP']
gcmh = simData['GCMH']
name = simData['2L_POS']
feature = pd.concat([gcmh], axis=1)
logPATH = OUTPUT + 'em_' + BIAS + '_' + str(CLUSTER) + '.csv'
logW = open(logPATH, 'w')
for i in range(2, CLUSTER):
model = GaussianMixture(n_components=i, covariance_type='tied', max_iter=300)
simData['label'] = model.fit_predict(feature)
bic = model.bic(feature)
aic = model.aic(feature)
logW.write(str(aic) + ',\t' + str(bic) + '\n')
fig = plt.figure()
sns.set_style('white')
plt.scatter(y=feature, x=simData['label'], c=simData['label'])
plt.xticks(range(0,i))
plt.savefig(OUTPUT + 'em_' + str(i) + '.png')
plt.close()
simData.to_csv(OUTPUT + 'em_' + str(i) + '.csv')
logW.close()