Example #1
0
	# Take max value in preds rows as classification
	# pred = np.zeros((len(X_test)))
	# yint = np.zeros((len(X_test)))
	# for row in np.arange(0,len(predictions)) :
	# 	pred[row] = np.argmax(predictions[row])
	# 	yint[row] = np.argmax(y_test[row])

	# print("Classifier Accuracy = %d"%(metrics.accuracy_score(yint,pred)))

	
	#####
	# now to test
	#####
	print("Testing classifier on Test data")
	print("Re-train with full training set")
	X, y, unique_cuisines,classes,test_indices,Xtest = getdata(ngram_range=(1,2)) # import the data

	clf2 = nnk(X,unique_cuisines,lr=0.1)
	f = clf2.fit(X.toarray(), y.toarray(), nb_epoch=25, batch_size=1000, 
		validation_split=0.15, show_accuracy=True)

	predictions = clf2.predict(X.toarray(), batch_size=1000, verbose=1)
	writestackgen(predictions,'StackGen.DNN.1-2grams.adadelta.train.csv')

	predictions = clf2.predict(Xtest.toarray(), batch_size=1000, verbose=1)
	writestackgen(predictions,'StackGen.DNN.1-2grams.adadelta.test.csv')
	# # Take max value in preds rows as classification
	# pred = np.zeros((len(Xtest)))
	# for row in np.arange(0,len(predictions)) :
	# 	pred[row] = np.argmax(predictions[row])
Example #2
0
if __name__ == '__main__':
	# Do the training
	res1 = np.genfromtxt('StackGen.DNN.1-2grams.train.csv',delimiter=',')
	res2 = np.genfromtxt('StackGen.DNN.1-2grams.adadelta.train.csv',delimiter=',')
	res3 = np.genfromtxt('StackGen.DNN.1grams.train.csv',delimiter=',')
	res4 = np.genfromtxt('StackGen.NN.1-2grams.train.csv',delimiter=',')
	res5 = np.genfromtxt('StackGen.NN.1grams.train.csv',delimiter=',')

	trainmat = np.mean(np.array([res1,res2,res3,res4,res5]),axis=0)

	# now normalize by row
	# trainmatnorm = preprocessing.normalize(trainmat)

	# pull in true values 
	_, y, _,_,_,_ = getdata(ngram_range=(1,2))

	# Instantiate neural network
	cfr = nnk(trainmat,y,lr=0.1)

	# train it 
	cfr.fit(trainmat, y.toarray(), nb_epoch=25, shuffle=True,
		batch_size=1000, validation_split=0.15,
		show_accuracy=True, verbose=1)

	# now get test values
	tst1 = np.genfromtxt('StackGen.DNN.1-2grams.test.csv',delimiter=',')
	tst2 = np.genfromtxt('StackGen.DNN.1-2grams.adadelta.test.csv',delimiter=',')
	tst3 = np.genfromtxt('StackGen.DNN.1grams.test.csv',delimiter=',')
	tst4 = np.genfromtxt('StackGen.NN.1-2grams.test.csv',delimiter=',')
	tst5 = np.genfromtxt('StackGen.NN.1grams.test.csv',delimiter=',')