Example #1
0
import p2funcs as p2f

x1 = ['a', 'b', 'c']

x2 = ['d', 'e', 'f']

#i_index, j_index = np.where(mat == chos_x )

mat1 = np.array([[1, 2, 3], [4, 5, 6], [4, 8, 9]])
mat2 = np.array([[11, 21, 31], [41, 51, 61], [71, 81, 91]])
mat3 = np.array([[1.1, 2.1, 3.1], [4.1, 5.1, 6.1], [7.1, 8.1, 9.1]])

matdict = {'1st': mat1, '2nd': mat2, '3rd': mat3}

choicedict = '3rd'

#print(matdict[choicedict])

dictmat = matdict[choicedict]

max_auc = np.max(dictmat)

i_index, j_index = np.where(dictmat == max_auc)

print('Corresponding element in x1: %s\nCorresponding element in x2: %s' %
      (x1[i_index[0]], x2[j_index[0]]))

array1 = [2, 2, 3, 3, 3, 4, 3, 5, 3, 6, 8]

print(p2f.most_common(array1))
Example #2
0
    # Show optimal gamma
    #print('Optimal Tier 1 gamma for dataset %s found to be %s' %(dataset, opt_t1_gamma))
    opt_t1_gammas.append(opt_t1_gamma)
    print("\n%.2f seconds elapsed so far.\n" % (time.time() - StartTime))

# End of dataset run
print('\n###################################################################')

# Print aggregate gamma values
for i in range(len(opt_t1_gammas)):
    print('\nOptimal tier 1 gamma for dataset %s found to be %s' %
          (toy_dataset_list[i][0], opt_t1_gammas[i]))

# Find most frequent gamma value
t1_gamma_consensus = p2f.most_common(opt_t1_gammas)

#Just in case last value selected:
if t1_gamma_consensus == t1_gamma_list[-1]:
    t1_gamma_consensus = t1_gamma_list[-2]

# Create tier 2 gamma list
gamma_i_t1 = t1_gamma_list.index(t1_gamma_consensus)
t2_gamma_list = list(
    p2f.frange(t1_gamma_list[gamma_i_t1 - 1], t1_gamma_list[gamma_i_t1],
               t1_gamma_list[gamma_i_t1 - 1])) + list(
                   p2f.frange(t1_gamma_list[gamma_i_t1],
                              t1_gamma_list[gamma_i_t1 + 1],
                              t1_gamma_list[gamma_i_t1]))
#t2_gamma_list = [t1_gamma_list[gamma_i_t1]]
Example #3
0
opt_models_byg = []

#Find highest mean AUC in each dataset for 'optimal' gamma
for i in range(len(amat_dict_list)):
    mat_dict = amat_dict_list[i]
    choice_auc_mat = mat_dict[opt_gamma]
    max_auc = np.max(choice_auc_mat)
    kpca_index, model_index = np.where(choice_auc_mat == max_auc)
    opt_kpca_byg = t2_kpcas[kpca_index]
    opt_kpcas_byg.append(opt_kpca_byg)
    opt_model_byg = t2_models[model_index]
    opt_models_byg.append(opt_model_byg)

    print('\nAt γ = %s, optimal KPCA is %s, whereas optimal KSVM is %s' %
          (opt_gamma, opt_kpca_byg, opt_model_byg))

opt_kpca = p2f.most_common(opt_kpcas_byg)
opt_model = p2f.most_common(opt_models_byg)

print(
    '\nOverall optimal KPCA/KSVM combination determined to be %s and %s respectively (γ = %s).'
    % s(opt_kpca, opt_model, gamma))

# End of dataset run
print("\n%.2f seconds elapsed so far\n" % (time.time() - StartTime))
print(
    '\n###################################################################\n')

#Calculate and display time taken or script to run
print("\nTime taken for script to run is %.2f seconds\n" %
      (time.time() - StartTime))