def make_score_heatmap(parameters, param1, param2, grid_model, dataset): """ Produce heatmap of mean scores for each combination of the parameters Parameters ---------- parameters : dictionary of lists Grid values for the Grid Search algorithm param1 : string The parameter C param2 : string The parameter gamma grid_model : GridSearchCV object Trained model dataset : string Type of dataset: 'All' or 'Reduced' Returns ------- Produce chart files in directory ../../target/visualization """ scores = [score for score in grid_model.cv_results_['mean_test_score']] scores = np.array(scores).reshape(6, 6) fig, ax = plt.subplots() im, cbar = heatmap(scores, parameters[param1], parameters[param2], ax=ax, cmap="YlGn", cbarlabel="Mean Scores") annotate_heatmap(im, valfmt="{x:.2f}") ax.set_xlabel(param2) ax.set_ylabel(param1) title = dataset + ' Datapoints GridSearchCV Mean Scores' ax.set_title(title) fig.tight_layout() outfile = '../../target/visualization/' + title + '.png' plt.savefig(outfile, format="png")
def optimal_play_chart(player): data = np.genfromtxt('../HU_push_fold/nash_' + player + '.csv', delimiter=',', dtype=float) data = np.reshape(data, (13, 13)) fig, ax = plt.subplots() title = 'Small blind optimal play' if player == 'sb' else 'Big blind optimal play' ax.set_title(title) axis_labels = [ "A", "K", "Q", "J", "T", "9", "8", "7", "6", "5", "4", "3", "2" ] im, cbar = heatmap.heatmap(data, axis_labels, axis_labels, ax=ax, cmap="YlGn", cbarlabel="Big Blinds") texts = heatmap.annotate_heatmap(im, valfmt="{x:.1f}") fig.tight_layout() fig.savefig('./' + player + '_range.svg')
# Selezione dati per Adriatica (SS1), Aurelia (SS16), # A1 (del Sole), Torino-Trieste (A4) e Raccordo anulare di Roma adriatica = data[data['CODICE'] == 'SS01601'][mesi] a1 = data[data['CODICE'] == 'AA00101'][mesi] aurelia = data[data['CODICE'] == 'SS00101'][mesi] a4 = data[data['CODICE'] == 'AA00401'][mesi] a90 = data[data['CODICE'] == 'AA09001'][mesi] adriatica = aci_utils.sum_columns(adriatica) a1 = aci_utils.sum_columns(a1) aurelia = aci_utils.sum_columns(aurelia) a4 = aci_utils.sum_columns(a4) a90 = aci_utils.sum_columns(a90) df = pd.DataFrame([a1, adriatica, aurelia, a4, a90], [ 'A1 Milano-Roma-Napoli', 'SS16 Adriatica', 'SS1 Aurelia', 'A4 Torino Trieste', 'A90 Raccordo Anulare' ]) fig, ax = plt.subplots() im = H.heatmap(df, df.index, df.columns, ax=ax, cmap="OrRd", xticks_rotated=True, cbar_visible=False) texts = H.annotate_heatmap(im, valfmt="{x}") fig.tight_layout() plt.show()
es_score_n = [] #others_n = [] for N in test_sizes: select = df.loc[(df["P"] == P) & (df["N"] == N)] if selected_dataset: select = select.loc[select["Dataset"] == datasets[selected_dataset-1]] if P in test_sizes[2:] and N in test_sizes[2:]: overall = select.loc[:, "ROC(auc)"].mean() else: overall = select.loc[:, "Balanced accuracy"].mean() es_score_n.append(overall) score_dict["es_score"].append(es_score_n) test_sizes_p = [x+"P" for x in test_sizes] test_sizes_n = [x+"N" for x in test_sizes] ext = "hepmark_es_svm_"+str(selected_dataset-1)+".pdf" if selected_dataset else "hepmark_es_svm.pdf" # Uncomment to Latexify the heatmap #latexify(columns=2) # Generate a Heatmap scores = np.array(score_dict["es_score"]) fig, ax = plt.subplots() im, cbar = heatmap.heatmap(scores, test_sizes_p, test_sizes_n, ax=ax, vmin = 0.0, vmax = 1.0, cmap=cm.Reds, cbarlabel="score [AUC / Acc]") texts = heatmap.annotate_heatmap(im, valfmt="{x:.2f}") fig.tight_layout() plt.show() fig.savefig("C:/Users/Vegard/Desktop/Master/Mastersproject/Plots/analyze/"+ext)
prov_chap = np.zeros((len(dep_options), len(chap_set))) for aux in range(len(dep)): i = dep_options.index(dep[aux]) for j in icd9_chap([x[:3] for x in labels_cid[aux]]): if j < 19: prov_chap[i][j - 1] += 1 fig, ax = plt.subplots(figsize=(20, 25)) im = heatmap(prov_chap, dep_options, chap_set, ax=ax, cmap="Reds", cbarlabel="Prevalence") text = annotate_heatmap(im, valfmt="{x:.0f}") plt.ylabel('Department', fontsize='large') ax.set_xlabel('ICD-9 chapters', fontsize='large') ax.xaxis.set_label_position('top') fig.tight_layout() fig.savefig('heatmap_dep.png', dpi=250) #%% print('- Age Groups:') idade = [int(line[2]) for line in texts] for i in range(len(idade)): if idade[i] < 5: idade[i] = 0 elif idade[i] < 15: idade[i] = 1
x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1] return np.ma.masked_array(np.interp(value, x, y)) # create a matplotlib figure for the Q table fig = plt.figure('Q-table') ax = fig.add_subplot(111) im, cbar = heatmap(q_table[0], list(range(numDistSensorStates)), action_names, ax=ax, cmap="RdBu", cbarlabel="Q table", norm=DivergingNorm(vcenter=0.0)) #norm=MidpointNormalize(midpoint=0)) texts = annotate_heatmap(im, valfmt="{x:.1f}") plt.draw() #fig, ax = plt.subplots() total_reward = 0 start_time = datetime.datetime.now() # log start of episode rewards = np.zeros(200) for step in range(0, steps - 1): # Use epsilon greedy policy based on Q table if N0 == 0: epsilon = 0 else: epsilon = N0 / (N0 + step) if random.random() > epsilon: a = np.argmax( q_table[st,
data = pd.read_csv(path + str(year) + ".txt", sep="\t", error_bad_lines=False, engine='python') else: data = pd.read_csv(path + str(year) + ".txt", sep="\t", encoding="latin1") natura_incidente = data['natura_incidente'] natura_incidente_labels = label_utils.join_labels( natura_incidente, "dataset/incidenti/istat/Classificazioni/natura_incidente.csv" ).value_counts(normalize=True) natura_incidente_labels = natura_incidente_labels[tipo_incidenti] inc_per_anno[str(year)] = pd.Series(natura_incidente_labels) fig, ax = plt.subplots() im = H.heatmap(inc_per_anno, inc_per_anno.index, inc_per_anno.columns, ax=ax, cmap="OrRd", cbar_visible=False) texts = H.annotate_heatmap(im) fig.tight_layout() plt.show()
a2 = a2 + o[2] a3 = a3 + o[3] return [a1 / len(obs), a2 / len(obs), a3 / len(obs)] matrix = [] for room in Rooms: observations = [] for d in Data: if d[0] == room: observations.append(d) matrix.append(getAvg(observations)) measures = np.array(matrix) fig, ax = plt.subplots(figsize=(5, 8)) im, cbar = heatmap(measures, Rooms, Accesspoints, ax=ax, cmap="Blues", cbarlabel="Signal strength in dBm ") texts = annotate_heatmap(im, valfmt="{x:.1f} ") fig.tight_layout() plt.savefig("Plots/AvgSignalPrLocation.svg", bbox_inches="tight") # 'tight' makes room for x-axis labels plt.show()