示例#1
0
	def test_build_recommender(self):
		fi = open('simple_filter_test').readlines()
		item_sim_mat,user_dict,item_pos,user_pos,item_dict = rec.build_recommender(rec.parse_array(fi),1)
		test_arr = []
		item_sim_mat = item_sim_mat.toarray()
		print 'item sim mat'
		print item_sim_mat
		for item1 in self.jac_matrix:
			temp = []
			for item2 in self.jac_matrix:
				temp.append(rec.jaccard_distance(item1,item2))
			test_arr.append(temp)
		for ent in self.used_coords:
			self.assertEqual(test_arr[ent[0]][ent[1]],item_sim_mat[ent[0]][ent[1]])
		for i in range(len(item_sim_mat)):
			for j in range(len(item_sim_mat)):
				if (i,j) in self.used_coords:
					self.assertEqual(test_arr[i][j],item_sim_mat[i][j])
				else:
#					print '(%d,%d)' %(i,j)
					self.assertEqual(item_sim_mat[i][j],0)	
	
		print item_pos
		print user_dict
		print user_pos 
		print item_dict
示例#2
0
	def test_speed_build_recommender(self):
		NUM_CUSTOMERS = 100
		NUM_ITEMS = 100
		NUM_ITEMS_PER_CUST = 10
		fi = {}
		for i in xrange(0,NUM_CUSTOMERS):
			i = str(i)
			fi[i] = randint(0,NUM_ITEMS,50)
			fi[i] = [str(x) for x in fi[i]]
		t3 = time.time()
		rec.build_naive_recommender(fi)
		t4 = time.time()
		print (t4-t3)/60.0

		t1 = time.time()
		rec.build_recommender(fi)
		t2 = time.time()

		print (t2-t1)/60.0