X_scaled = scale(X) #Declare list for t2 mean mean area under ROC curve (mma) values t2_mmas = [] # Create initial variables to update max_t2_mma = 0 opt_t2_gamma = 0 print('\n### TIER 2 GRID SEARCH ###') for gamma in t2_gamma_list: amat_dict.update({gamma: []}) t2_auc_mat, t2_kpcas, t2_models = p2f.m_test5_2_rocplot( X_scaled, y, gamma, dataset, filepath, 'tier2') amat_dict[gamma].append(t2_auc_mat) t2_mmas.append(np.mean(t2_auc_mat)) amat_dict_list.append(amat_dict) # Select optimal t2 gamma for i in range(len(t2_mmas)): if t2_mmas[i] > max_t2_mma: max_t2_mma = t2_mmas[i] opt_t2_gamma = t2_gamma_list[i] # Record optimal gamma for given dataset opt_t2_gammas.append(opt_t2_gamma)
#Scale initial data to centre toy_X_scaled = scale(toy_X) #Declare list for t2 mean mean area under ROC curve (mma) values t2_mmas = [] # Create initial variables to update max_t2_mma = 0 opt_t2_gamma = 0 for gamma in t2_gamma_list: amat_dict.update({gamma: []}) t2_auc_mat, t2_kpcas, t2_models = p2f.m_test5_2_rocplot( toy_X_scaled, toy_y, gamma, toy_label, filepath, plotpath, 'tier1') amat_dict[gamma].append(t2_auc_mat) p2f.plot_mpl_heatmap( t2_auc_mat, t2_kpcas, t2_models, cmap="autumn", cbarlabel= "Mean area under ROC curve after 10-fold cross validation", output='save', path='%s%s_tier2_heatmap_gamma_%s.png' % (filepath, nowtime, gamma)) p2f.js_heatmap(t2_auc_mat, t2_kpcas, t2_models,
plotpath = '%splotting/' % filepath if not os.path.exists(filepath): os.makedirs(filepath) os.makedirs(plotpath) X_rows, X_cols = X.shape def_gamma = 1 / X_cols gamma_list = [def_gamma / 100, def_gamma / 10, def_gamma] for gamma in gamma_list: auc_mat, kpcas, models = p2f.m_test5_2_rocplot(X, y, gamma, ds_label, filepath, plotpath, 'gamma_%s' % gamma) p2f.plot_mpl_heatmap( auc_mat, kpcas, models, cmap="autumn", cbarlabel= "Mean area under ROC curve after 10-fold cross validation", output='save', path='%s%s_tier2_heatmap_gamma_%s.png' % (filepath, nowtime, gamma)) p2f.js_heatmap(auc_mat, kpcas, models, "hmapgamma%s" % (gamma), "%s%sheatmap_gamma%s.js" % (plotpath, nowtime, gamma))