コード例 #1
0
def main(testfile=None):
    if testfile:
        tr = rd.read(testfile)
        ti = np.array(tr)
        tir = [np.reshape(x, (784, 1)) for x in ti]
        return (n.evaluate(tir))
    else:
        n.SGD(a, 20, 20, 3, 0, c)
コード例 #2
0
def main(testfile=None):
	if testfile:
		tf=rd.read(testfile)
		ts=np.array(tf)
		return(clf.predict(ts))
	else:
		pred=[int(a) for a in clf.predict(c[0])]
		nc=sum(int(x==y) for x,y in zip(pred,c[1]))
		print "{0} of {1} correct = {2}%".format(nc,len(c[1]),(100.0*float(nc)/len(c[1])))
コード例 #3
0
def main(testfile=None):
	if testfile:
		a=rd.read(testfile)
		k=3
		predictions=[]
		for x in range(len(a)):
			neighbors = knn.getNeighbors(train, a[x], k)
			result = knn.getResponse(neighbors)
			predictions.append(result)
		return(predictions)
	else:
		knn.main(train,tests)
コード例 #4
0
def main(testfile=None):
    global n
    global a
    global b
    if testfile:
        tr = rd.read(testfile)
        ti = np.array(tr)
        tir = [np.reshape(x, (2500, 1)) for x in ti]
        res = n.evaluate(tir)
        for i in res:
            res_converted.append(cnv.convert(int(i)))
        print(res_converted)
    else:
        n.SGD(a, 20, 20, 3.0, b)
コード例 #5
0
def main(testfile=None):
	global clf
	global a
	global b
	if testfile:
		tf=rd.read(testfile)
		ts=np.array(tf)
		res=clf.predict(ts)
		for i in res:
			res_converted.append(cnv.convert(int(i)))
		print (res_converted)
	else:
		pred=[int(a+.1) for a in clf.predict(b[0])]
		nc=sum(int(x==y) for x,y in zip(pred,b[1]))
		print "{0} of {1} correct = {2}%".format(nc,len(b[1]),(100.0*float(nc)/len(b[1])))