Example #1
0
	#y_hat_batch = [[[0,1]], [[0,1]], [[0,1]]]
	for i in xrange(batch_num):
		c_cost = train(x_batch[i], y_hat_batch[i])
		#print 'c_cost', c_cost
		current_cost += c_cost
	current_cost /= batch_num
	print 'current_cost', current_cost
	DataParser.save_parameters(parameters)
	#current_validate_cost = validate(validation_set)
	#print 'validate cost', current_validate_cost
	#if current_validate_cost < validate_cost:
	#	validate_cost = current_validate_cost
	#else:
	#	break

test_data, test_id = DataParser.load_test_data(sample_file)
result = test(test_data)
result = list(result)
result = map(list, zip(*result))  # transpose
with open('result.txt', 'w') as f:
	for i in xrange(len(result)):
		f.write(test_id[i] + ',')
		max_value = 0
		max_index = -1
		candidate = []
		candidate_value = []
		for j in xrange(len(result[i])):
			if result[i][j] > 0.8:
				candidate.append(DataParser.label_index[j])
				candidate_value.append(result[i][j])
			if result[i][j] > max_value:
Example #2
0
	for i in xrange(batch_num):
		c_cost = train(x_batch[i], y_hat_batch[i])
		#print 'c_cost', c_cost
		current_cost += c_cost
	current_cost /= batch_num
	print 'current_cost', current_cost
	DataParser.save_parameters(parameters, 'parameter.txt')
	DataParser.save_parameters(grad_hists, 'parameter-g.txt')
	#current_validate_cost = validate(validation_set)
	#print 'validate cost', current_validate_cost
	#if current_validate_cost < validate_cost:
	#	validate_cost = current_validate_cost
	#else:
	#	break

test_data, test_id = DataParser.load_test_data(sample_file)
result = test(test_data)
result = list(result)
result = map(list, zip(*result))  # transpose
with open('result.txt', 'w') as f:
	for i in xrange(len(result)):
		f.write(test_id[i] + ',')
		max_value = 0
		max_index = -1
		candidate = []
		candidate_value = []
		for j in xrange(len(result[i])):
			if result[i][j] > 0.8:
				candidate.append(DataParser.label_index[j])
				candidate_value.append(result[i][j])
			if result[i][j] > max_value: