Пример #1
0
if __name__ == "__main__":
    import sys
    if len(sys.argv) < 3:
        print "specify file with objects to evaluate and k for k-fold"

    k = int(sys.argv[2])
    #print "w:", w, "bias:", bias
    print "reading input file..."
    X, y = read_input_file_shuffling(sys.argv[1])
    print "read input file."
    #print X, y
    #input_shuffle = range(len(X))
    #random.shuffle(input_shuffle)

    kf = cross_val.KFold(len(X), k)

    for train_index, test_index in kf:
        #print "TRAIN:", train_index, "TEST:", test_index
        #print "sum(train_index), sum(test_index):", sum(map(train_index)), sum(test_index)
        X_small_tr = X[train_index]
        y_small_tr = y[train_index]
        X_small_tst = X[test_index]
        y_small_tst = y[test_index]

        w, bias, _ = get_hyperplane(X_small_tr, y_small_tr)
        print "w:", w
        print "bias:", bias
        print "Blad", get_error(w, bias, X_small_tst, y_small_tst)
        #X_train, X_test = X[train_index], X[test_index]
        #y_train, y_test = y[train_index], y[test_index]
Пример #2
0
	import sys
	if len(sys.argv)<3:
		print "specify file with objects to evaluate and k for k-fold"
		
	k = int(sys.argv[2])
	#print "w:", w, "bias:", bias	
	print "reading input file..."
	X, y = read_input_file_shuffling(sys.argv[1])
	print "read input file."
	#print X, y
	#input_shuffle = range(len(X))
	#random.shuffle(input_shuffle)

	kf = cross_val.KFold(len(X), k)

	for train_index, test_index in kf:
		#print "TRAIN:", train_index, "TEST:", test_index
		#print "sum(train_index), sum(test_index):", sum(map(train_index)), sum(test_index)
		X_small_tr = X[train_index]
		y_small_tr = y[train_index]
		X_small_tst = X[test_index]
		y_small_tst = y[test_index]
		
		w, bias, _ = get_hyperplane(X_small_tr, y_small_tr)
		print "w:", w
		print "bias:", bias
		print "Blad", get_error(w, bias, X_small_tst, y_small_tst)
		#X_train, X_test = X[train_index], X[test_index]
		#y_train, y_test = y[train_index], y[test_index]

#!/usr/bin/env python

import numpy as np
import pylab as pl
from itertools import izip
from calc_weights import read_input_file, get_hyper_classif, get_error

def read_hyperplane(fname):
	with open(fname) as f:
		wbiasl = (f.readlines()[-1]).split("bias:")
		bias = float(wbiasl[1])
		w = map(lambda x: float(x), wbiasl[0].replace("w:", "").replace("[", "").replace("]", "").split(","))
	return w, bias

if __name__ == "__main__":
	import sys
	if len(sys.argv)<3:
		print "specify output file from calc-weights and file with objects to evaluate"
		
	w, bias = read_hyperplane(sys.argv[1])
	print "w:", w, "bias:", bias	
	X, y = read_input_file(sys.argv[2])
	print get_error(w, bias, X, y)
#!/usr/bin/env python

import numpy as np
import pylab as pl
from itertools import izip
from calc_weights import read_input_file, get_hyper_classif, get_error


def read_hyperplane(fname):
    with open(fname) as f:
        wbiasl = (f.readlines()[-1]).split("bias:")
        bias = float(wbiasl[1])
        w = map(
            lambda x: float(x),
            wbiasl[0].replace("w:",
                              "").replace("[", "").replace("]", "").split(","))
    return w, bias


if __name__ == "__main__":
    import sys
    if len(sys.argv) < 3:
        print "specify output file from calc-weights and file with objects to evaluate"

    w, bias = read_hyperplane(sys.argv[1])
    print "w:", w, "bias:", bias
    X, y = read_input_file(sys.argv[2])
    print get_error(w, bias, X, y)