feature_scoring_flu_overtime.py

 1"""
 2Created on 30 Oct 2018
 3
 4@author: jhkwakkel
 5"""
 6
 7import matplotlib.pyplot as plt
 8import pandas as pd
 9import seaborn as sns
10
11from ema_workbench import ema_logging, load_results
12from ema_workbench.analysis import get_ex_feature_scores, RuleInductionType
13
14ema_logging.log_to_stderr(level=ema_logging.INFO)
15
16# load data
17fn = r"./data/1000 flu cases no policy.tar.gz"
18
19x, outcomes = load_results(fn)
20x = x.drop(["model", "policy"], axis=1)
21
22y = outcomes["deceased_population_region_1"]
23
24all_scores = []
25
26# we only want to show those uncertainties that are in the top 5
27# most sensitive parameters at any time step
28top_5 = set()
29for i in range(2, y.shape[1], 8):
30    data = y[:, i]
31    scores = get_ex_feature_scores(x, data, mode=RuleInductionType.REGRESSION)[0]
32    # add the top five for this time step to the set of top5s
33    top_5 |= set(scores.nlargest(5, 1).index.values)
34    scores = scores.rename(columns={1: outcomes["TIME"][0, i]})
35    all_scores.append(scores)
36
37all_scores = pd.concat(all_scores, axis=1, sort=False)
38all_scores = all_scores.loc[top_5, :]
39
40fig, ax = plt.subplots()
41sns.heatmap(all_scores, ax=ax, cmap="viridis")
42plt.show()