Exemplo n.º 1
0
Arquivo: run.py Projeto: xmli/cme193
def test_bow():
	print 'BagOfWords Check:\n----------------------'
	try:
		d = ['this is the final cme193 assignment', 'i hope you learn some skills you can apply elsewhere']
		bow = BagOfWords(top_n=8)
		bow.fit(d)
		X = bow.transform(d)
		ref = [[ 0.,  1.,  0.,  1.,  1.,  1.,  0.,  0.],
			   [ 2.,  0.,  1.,  0.,  0.,  0.,  1.,  1.]]

		
		if not np.allclose(X, ref):
			print '[FAILED], incorrect representation' 
			return False
		else:
			print '[PASSED]' 
			return True
	except Exception:
		print '[FAILED], error in calculation' 
		return False
Exemplo n.º 2
0
Arquivo: run.py Projeto: xmli/cme193
	TEST(test_regression_theta())
	TEST(test_regression_pred())

	yhat = False
	
	with open('labels.txt') as f:
		y = [int(l.strip()) for l in f.readlines()]

	with open('example_text.txt') as f:
		texts = [l.strip().lower() for l in f.readlines()]

	
	bow = BagOfWords(top_n=1500)

	
	bow.fit(texts)

	X = bow.transform(texts)

	#-CME193-START-------------------

	# !!!!!! PLEASE READ !!!!!!
	# you will need to create a new instance of LinearProbabilityModel, you will need
	# to call your .fit on X and y, and you will need to put your preductions 
	# (after calling .predict) in a variable called yhat.

	#-CME193-END---------------------


	if not yhat:
		yhat = np.random.normal(0, 1, len(y))