Exemplo n.º 1
0
from sklearn.svm import SVC

import data_util as util

bc_data_train, bc_data_test, bc_target_train, bc_target_test = util.load_breast_cancer()
v_data_train, v_data_test, v_target_train, v_target_test = util.load_vowel()
KERNELS = ["linear", "rbf", "rbf", "rbf", "rbf", "rbf", "rbf", "poly", "poly", "poly", "poly"]
GAMMA = [.001, .01, .5, 1., 1.25, 1.5]

def svm():
	print "---bc---"
	d = 2
	g = 0
	for kernel in KERNELS:
		if kernel == "poly":
			_svm(bc_data_train, bc_data_test, bc_target_train, bc_target_test, kernel, degree=d)
			d += 1
		elif kernel == "rbf":
			_svm(bc_data_train, bc_data_test, bc_target_train, bc_target_test, kernel, gamma=GAMMA[g])
			g += 1
		else:
			_svm(bc_data_train, bc_data_test, bc_target_train, bc_target_test, kernel)


	print "---v---"
	d = 2
	g = 0
	for kernel in KERNELS:
		if kernel == "poly":
			_svm(v_data_train, v_data_test, v_target_train, v_target_test, kernel, degree=d)
			d += 1
        compressor.fit(tx, y=ty.ravel())
        newtx = compressor.transform(tx)
        runtime=time() - t0
        shape = newtx.shape
        print runtime, shape
    print "K-best done"

def clustering(tx, ty, rx, ry, num=2):
    print "KM"
    for j in range(tx[1].size - 1):
        i = j + 1
        clf = KM(n_components=i)
        clf.fit(tx)
    print "KM done"
    print "EM"
    for j in range(tx[1].size - 1):
        i = j + 1
        clf = EM(n_components=i)
        clf.fit(tx)
    print "EM done"


if __name__ == "__main__":
    print "----BC-----"
    tx, ty, rx, ry = util.load_breast_cancer()
    dimensional(tx, ty, rx, ry, add=chi2)
    print "----V-----"
    tx, ty, rx, ry = util.load_vowel()
    dimensional(tx, ty, rx, ry, add=f_classif)

Exemplo n.º 3
0
import data_util as util
import numpy as np

print "---bc--"
bc = util.load_breast_cancer()
print "train", len(bc[2]), np.bincount(bc[2])
print "test", len(bc[3]), np.bincount(bc[3])

print "---v--"
vowels = util.load_vowel()
print "train", len(vowels[2]), np.bincount(vowels[2])
print "test", len(vowels[3]), np.bincount(vowels[3])
Exemplo n.º 4
0
        print result
        resultst.append(result[1])
        resultsr.append(result[2])
    plot([0, iterations, 0, 1], (iter_arr, resultst, "ro", iter_arr, resultsr, "bo"), "Network Epoch", "Percent Error", "Neural Network Error", "NN"+add)
    print "nn done" + add

def _nn(tx, ty, rx, ry, n_iter):
    print "_nn"
    nn = Classifier(
            layers=[
                Layer("Tanh", units=100),
                Layer("Softmax")],
            n_iter=n_iter)
    nn.fit(tx, ty)
    resultst = nn.score(tx, ty)
    resultsr = nn.score(rx, ry)
    print "_nn done"
    return n_iter, resultst, resultsr



if __name__=="__main__":
    train_x, train_y, test_x, test_y = util.load_vowel()
    # nn(train_x, train_y, test_x, test_y)
    em(train_x, train_y, test_x, test_y)
    # km(train_x, train_y, test_x, test_y)
    # pca(train_x, train_y, test_x, test_y)
    # ica(train_x, train_y, test_x, test_y)
    # randproj(train_x, train_y, test_x, test_y)
    # kbest(train_x, train_y, test_x, test_y)