lambd = 0.25455
print("list_k=", list_k, "lambda=", lambd)

n = Xtr2.shape[0]

current_kernel = MultipleSpectrumKernel(list_k=list_k,
                                        lexicon={
                                            "A": 0,
                                            "T": 1,
                                            "C": 2,
                                            "G": 3
                                        },
                                        remove_dimensions=True)
svm2 = SVM(current_kernel, center=True)
svm2.train(Xtr2, Ytr2, n, lambd)
# Training accuracy
f = svm2.get_training_results()
tmp = Ytr2 == np.sign(f)
accuracy = np.sum(tmp) / np.size(tmp)
print("Training accuracy:", accuracy, "expected~",
      0.88)  # expected perf 0.6465. Bad!!

#%%

Xte0 = np.loadtxt('./data/Xte0.csv', dtype=bytes, delimiter="\n").astype(str)
Xte1 = np.loadtxt('./data/Xte1.csv', dtype=bytes, delimiter="\n").astype(str)
Xte2 = np.loadtxt('./data/Xte2.csv', dtype=bytes, delimiter="\n").astype(str)

generate_submission_file_2(svm0, svm1, svm2, \
    Xte0, len(Xte0), Xte1, len(Xte1), Xte2, len(Xte2))
Exemplo n.º 2
0
#~ svm2.train(Xtr2, Ytr2, n, lambd)
#~ # Training accuracy
#~ f = svm2.get_training_results()
#~ tmp = Ytr2 == np.sign(f)
#~ accuracy = np.sum(tmp) / np.size(tmp)
#~ print("Training accuracy:", accuracy, "expected~", 0.700625) # expected perf 0.65

#%%
print(">>> Set 2")

gamma = 10
lambd = 0.0002

svm2 = kmlpa.SVM(kmlpk.GaussianKernel(gamma), center=True)
svm2.train(Xtr2, Ytr2, Xtr2.shape[0], lambd)
# Training accuracy
f = svm2.get_training_results()
print(f)
tmp = Ytr2 == np.sign(f)
accuracy = np.sum(tmp) / np.size(tmp)
print("Training accuracy:", accuracy)

#%%

Xte0 = np.loadtxt('./data/Xte0.csv', dtype=bytes, delimiter="\n").astype(str)
Xte1 = np.loadtxt('./data/Xte1.csv', dtype=bytes, delimiter="\n").astype(str)
Xte2 = np.genfromtxt('./data/Xte2_mat50.csv', delimiter=' ')

generate_submission_file_2(svm0, svm1, svm2, \
    Xte0, len(Xte0), Xte1, len(Xte1), Xte2, Xte2.shape[0])