def kfcvkNN(mi, k=10):
	correct = []
	tested = []
	tot = 0
	cor = 0
	for i in range(k):
		#mark_test_set(mi, k, i)
		MessageFeatures.test_fold = i
		MessageFeatures.folds = k
		
		tf = TFIDF(mi, 3)
		tf.train1()
		tf.correct = 0
		tf.correct = 0
		c = 0
		t = 0
		for m in mi:
			if m.isTest(mi.num_msgs):
				cl = tf.get_class_kNN(m)
				#print(cl)
				if cl == m.newsgroupnum:
					c+=1
				t+=1
		print(tf.correct)	
		correct.append(c)
		tested.append(t)
		tot+=t
		cor+=c
	print (1.0*cor/tot)
		
	pass
def tfidf(mi):
	MessageFeatures.test_fold = -1
	tf = TFIDF(mi, 3)
	tf.train1()
	cj = 0
	cj_count = 0
	tf.correct = 0
	cj = 0
	cj_count = 0
	tf.correct = 0
	for m in mi:
		if cj_count >= 20:
			cj_count = 0
			cj += 1
		elif m.newsgroupnum == cj:
			cj_count += 1
			c = tf.get_class_kNN(m)
			print(c)
	print(tf.correct)	
	pass