forked from quaquel/EMAworkbench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeseries_clustering_flu.py
43 lines (34 loc) · 1.05 KB
/
timeseries_clustering_flu.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
"""
Created on 11 Apr 2019
@author: jhkwakkel
"""
import matplotlib.pyplot as plt
import seaborn as sns
from ema_workbench import load_results
from ema_workbench.analysis import clusterer, plotting, Density
experiments, outcomes = load_results("./data/1000 flu cases no policy.tar.gz")
data = outcomes["infected_fraction_R1"]
# calculate distances
distances = clusterer.calculate_cid(data)
# plot dedrog
clusterer.plot_dendrogram(distances)
# do agglomerative clustering on the distances
clusters = clusterer.apply_agglomerative_clustering(distances, n_clusters=5)
# show the clusters in the output space
x = experiments.copy()
x["clusters"] = clusters.astype("object")
plotting.lines(x, outcomes, group_by="clusters", density=Density.BOXPLOT)
# show the input space
sns.pairplot(
x,
hue="clusters",
vars=[
"infection ratio region 1",
"root contact rate region 1",
"normal contact rate region 1",
"recovery time region 1",
"permanent immune population fraction R1",
],
plot_kws=dict(s=7),
)
plt.show()