Exemple #1
0
def cross_validate(args):
	# import some functions
	encode = Data_Loader().encode
	find_error = NFL_Predictor().compareVector
	try:	
		nn = Neural_Network.createFromFile(args.file)
		print "Loaded Neural Network with %i hidden nodes" % len(nn.hidden_nodes)
		totalCorrect = 0.0
		total_tested = 0.0
		for y in range(args.start,args.end+1):
			classRight = [0, 0, 0, 0, 0, 0]
			correct = incorrect = 0
			if(args.db == 'u'):
				dl = Data_Loader()
				teams = dl.getAllTeams(y)
			elif(args.db == 'b'):
				dl = Data_Loader()
				teams = dl.getAllTeams(y)
			elif(args.db == 'p'):
				dl = Data_Loader('playoffTeams.csv')
				teams = dl.getAllTeams(y)
			elif(args.db == 'o'):
				dl = Data_Loader('balancedData.csv')
				teams = dl.getAllTeams(y)
			total_tested += len(teams)
			total_error = 0.0
			for t in teams:
				t.result = nn.feed_forward(t.stats)
				error = (find_error(t.result, encode(t.classification)))
				total_error += error**2
				if error < .08:
					correct += 1
					classRight
				if args.v:
					print "team %s, results %s, class %s, error %s" % (t.name, t.result, encode(t.classification), error)
			if not args.q:
				print "%d \t within threshold: %d/%d \t error: %s" % (y, correct, len(teams), str(total_error))
			totalCorrect += correct
		print "totalCorrect: %i/%i, %.2f%%" % (totalCorrect, total_tested, (totalCorrect/total_tested)*100)
	except Exception as e:
		print "invalid formatting, consult neural_main.py c --help \nError: %s" % e
Exemple #2
0
 '''
 nn = Neural_Network.createWithRandomWeights(66,40,6)    
     
 # train! with learning rate proportional to # of teams in the situations
 inputs = []
 targets = []
 for y in range(2005,2007):
     i,t = DL.getTargets(y)
     inputs += i
     targets += t 
     #print targets
 nn = nn.train(10000,inputs,targets,1.5)
 nn.saveToFile("predictortest.txt")
 '''
 nn = Neural_Network.createFromFile("predictortest.txt")
 teams_2011 = DL.getAllTeams(2011)
 pats_2011 = filter(lambda t: t.name == "nwe", teams_2011)[0]
 all_other_teams = filter(lambda t: t.name != "nwe", teams_2011)
 predictor = NFL_Predictor(nn)
 similar = predictor.compareWithPastTeams(all_other_teams, pats_2011, 3)
 for t,d in similar:
     print t.name + " " + str(d) + "\n"