def training_dolphin_pubmed_twitter(strng):
	k=10
	
	current_directory = os.getcwd()	
	strng="twitter"
	#f2=open('task3.txt','w')
	if strng=="dolphins" or strng=="pubmed":
		# f=open("task_3.txt",'w')
		# f11=open("task_4.txt",'w')
		prior={}
		dic1={}
		dic2={}
		testset=[]
		trainset=[]
		trainlabel=[]
		testlabel=[]
		prior={}
		R=[]
		train=[]
		labels=[]
		if strng=="dolphins":
			print("FOR DOLPHIN DATA SET: ")
			final_directory = os.path.join(current_directory, r'dolphins_D_matrices')
			if not os.path.exists(final_directory):
				os.makedirs(final_directory)
			final_directory_out = os.path.join(current_directory, r'output_plots')
			if not os.path.exists(final_directory_out):
				os.makedirs(final_directory_out)
			f=open("task_3_dolphin.txt",'w')
			f11=open("task_4_dolphin.txt",'w')
			f.write("********************DOLPHIN DATASET***************************************")
			#f2.write(str("DOLPHIN DATA SET\n"))
			f11.write("********************DOLPHIN DATASET***************************************")
			train = pd.read_csv("dolphins.csv",delimiter=' ',header=None)
			labels=pd.read_csv("dolphins_label.csv",delimiter=' ',header=None)
			#f=open(final_directory+"/Accuracy.txt",'w')
		else:
			print("FOR PUBMED DATA SET:\n ")
			final_directory = os.path.join(current_directory, r'pubmed_D_matrices')
			if not os.path.exists(final_directory):
				os.makedirs(final_directory)
			final_directory_out = os.path.join(current_directory, r'output_plots')
			if not os.path.exists(final_directory_out):
				os.makedirs(final_directory_out)
			f.write("********************PUBMED DATASET***************************************")
			f11.write("********************PUBMED DATASET***************************************")
			#f2.write(str("DOLPHIN DATA SET\n"))
			train = pd.read_csv("dolphins.csv",delimiter=' ',header=None)
			labels=pd.read_csv("dolphins_label.csv",delimiter=' ',header=None)
			#f=open(final_directory+"/Accuracy.txt",'w')
			
			f=open("task_3_pubmed.txt",'w')
			f11=open("task_4_pubmed.txt",'w')
			train = pd.read_csv("pubmed.csv",delimiter=' ',header=None)
			labels=pd.read_csv("pubmed_label.csv",delimiter=' ',header=None)
		
		train=np.array(train)
		labels=np.array(labels)
		train_pca=train
		train_labels=labels
		predictions=[]
		accuracy_average=[0 for i in range(4)]
		f1_macro_average=[0 for i in range(4)]
		f1_micro_average=[0 for i in range(4)]

		f1_micro_average_list=[0 for i in range(4)]
		f1_macro_average_list=[0 for i in range(4)]
		accuracy_average_list=[0 for i in range(4)]
		for i in range(4):
			f1_micro_average_list[i]=[]
			f1_macro_average_list[i]=[]
			accuracy_average_list[i]=[]
		
		n,m=train.shape
		print(n,m)
		j21=2
		D=[]

		print("PERFORMING OPERATIONS ON R MATRIX")
		while j21<=int(m/2):
			
			accuracy_average=[0 for i in range(4)]
			f1_macro_average=[0 for i in range(4)]
			f1_micro_average=[0 for i in range(4)]
			print("THE VALUE OF D IS:",end=' ')
			print(j21)
			D.append(j21)
			f.write("THE VALUE OF D IS:")
			f.write(str(j21))
			f.write(str("\n\n"))
			f11.write("THE VALUE OF D IS:")
			f11.write(str(j21))
			f11.write(str("\n\n"))
			train_R=pro1.random_projection(m,n,train,j21,final_directory)
			j21=j21*2

			list_k_fold=cross_validation_k(train_R,labels,10)
			#print(R.shape)
			
			for k1 in range(10):
				print("k1=",end=' ')
				print(k1)
				prior={}
				dic1={}
				dic2={}
				testset=[]
				trainset=[]
				trainlabel=[]
				testlabel=[]
				prior={}
				dic={}
				testset=[]
				testlabel=[]
				label1=[]
				#print(train_R.shape)
				#print(list_k_fold)
				for i in range(10):
					#print(i)
					if i==k1:					
						label1.extend(list_k_fold[i])
				for i2 in range(len(labels)):
					if i2 in label1:
						testset.append(train_R[i2])
						testlabel.append(labels[i2])
					else:						
						trainset.append(train_R[i2])
						#print(trainset)
						trainlabel.append(labels[i2])
				for i1 in range(len(trainset)):
					if trainlabel[i1][0] not in dic:
						dic[trainlabel[i1][0]]=[]
					dic[trainlabel[i1][0]].append(trainset[i1])				
				
					
				dic1,dic2=b1.calc_mean_stddev(train_R,dic)
				prior=b1.priors(trainset,dic)
				#print(trainset.shape)
				predictions,acc=b1.predictions_calculate(testset,testlabel,dic1,dic2,prior)
				a,b=F1_score(testlabel,predictions)
				f1_micro_average[0]+=b
				f1_macro_average[0]+=a
				accuracy_average[0]+=acc

				predictions,acc=nn1.knn1(testset,trainset,testlabel,trainlabel)
				a,b=F1_score(testlabel,predictions)
				f1_micro_average[1]+=b
				f1_macro_average[1]+=a
				accuracy_average[1]+=acc

				predictions,acc=nn1.scikit_knn(testset,trainset,testlabel,trainlabel)
				a,b=F1_score(testlabel,predictions)
				f1_micro_average[2]+=b
				f1_macro_average[2]+=a
				accuracy_average[2]+=acc

				predictions,acc=b1.sklearn_bayes(testset,trainset,testlabel,trainlabel)
				F1_score(testlabel,predictions)
				f1_micro_average[3]+=b
				f1_macro_average[3]+=a
				accuracy_average[3]+=acc
			f1_micro_average[:]=[x /10 for x in f1_micro_average]
			f1_macro_average[:]=[x /10 for x in f1_macro_average]
			accuracy_average[:]=[x /10 for x in accuracy_average]
			for i in range(4):
				f1_micro_average_list[i].append(f1_micro_average[i])
				f1_macro_average_list[i].append(f1_macro_average[i])
				accuracy_average_list[i].append(accuracy_average[i])
			f.write("F1 MACRO SCORE:\n")
			f11.write("F1 MACRO SCORE:\n")
			f.write("Bayes: "+str(f1_macro_average[0])+str("\n")+"KNN: "+str(f1_macro_average[1])+str("\n"))
			f11.write(str("\n")+"Sklearn_knn: "+str(f1_macro_average[2])+"\nsklearn_bayes: "+str(f1_macro_average[3])+"\n")
			f.write("F1 MICRO SCORE:\n")
			f11.write("F1 MICRO SCORE:\n")
			f.write("Bayes: "+str(f1_micro_average[0])+str("\n")+"KNN: "+str(f1_micro_average[1])+str("\n"))
			f11.write("Sklearn_knn: "+str(f1_micro_average[2])+"\nsklearn_bayes: "+str(f1_micro_average[3])+"\n")
			f.write("ACCURACY:\n")
			f11.write("ACCURACY:\n")
			f.write("Bayes: "+str(accuracy_average[0])+str("\n")+"KNN: "+str(accuracy_average[1])+str("\n"))
			f11.write("Sklearn_knn: "+str(accuracy_average[2])+"\nsklearn_bayes: "+str(accuracy_average[3])+"\n")
			print("F1 MACRO SCORE:\n")
			print("Bayes: "+str(f1_macro_average[0])+str("\n")+"KNN: "+str(f1_macro_average[1])+str("\n")+"Sklearn_knn: "+str(f1_macro_average[2])+"\nsklearn_bayes: "+str(f1_macro_average[3])+"\n")
			print("F1 MICRO SCORE:\n")
			print("Bayes: "+str(f1_micro_average[0])+str("\n")+"KNN: "+str(f1_micro_average[1])+str("\n")+"Sklearn_knn: "+str(f1_micro_average[2])+"\nsklearn_bayes: "+str(f1_micro_average[3])+"\n")
			print("ACCURACY:\n")
			print("Bayes: "+str(accuracy_average[0])+str("\n")+"KNN: "+str(accuracy_average[1])+str("\n")+"Sklearn_knn: "+str(accuracy_average[2])+"\nsklearn_bayes: "+str(accuracy_average[3])+"\n")
		
		accuracy_average=[0 for i in range(4)]
		f1_macro_average=[0 for i in range(4)]
		f1_micro_average=[0 for i in range(4)]
		legends=["CustomBayes","CustomKNN","Sklearn_Bayes","Sklearn_KNN"]
		if strng=="dolphins":
			for i in range(4):
				#print(f1_micro_average_list[i])

				plt.plot(D,f1_macro_average_list[i])
				
			plt.xlabel('D Values')
			plt.ylabel('F1-Macro-Score')	
			plt.legend(legends)	
			#plt.show()
			plt.savefig(final_directory_out+'/task_4_dolphin_f1-Macro-accuracy.png')
			plt.clf()
			for i in range(4):
				plt.plot(D,f1_micro_average_list[i])
			plt.xlabel('D Values')
			plt.ylabel('F1-Micro-Score')
			plt.legend(legends)	
			#plt.show()
			plt.savefig(final_directory_out+'/task_4_dolphin_f1-Micro-accuracy.png')
			plt.clf()
			for i in range(4):
				plt.plot(D,accuracy_average_list[i])
			plt.xlabel('D Values')
			plt.ylabel('Accuracy')
			plt.legend(legends)	
			#plt.show()
			plt.savefig(final_directory_out+'/task_4_dolphin_Accuracy.png')
			plt.clf()
		elif strng=="pubmed":
			for i in range(4):
			#print(f1_micro_average_list[i])

				plt.plot(D,f1_macro_average_list[i])
			
			plt.xlabel('D Values')
			plt.ylabel('F1-Macro-Score')	
			plt.legend(legends)	
			#plt.show()
			plt.savefig(final_directory_out+'/task_4__pubmed_f1-Macro-accuracy.png')
			plt.clf()
			for i in range(4):
				plt.plot(D,f1_micro_average_list[i])
			plt.xlabel('D Values')
			plt.ylabel('F1-Micro-Score')
			plt.legend(legends)	
			#plt.show()
			plt.savefig(final_directory_out+'/task_4_pubmed_f1-Micro-accuracy.png')
			plt.clf()
			for i in range(4):
				plt.plot(D,accuracy_average_list[i])
			plt.xlabel('D Values')
			plt.ylabel('Accuracy')
			plt.legend(legends)	
			#plt.show()
			plt.savefig(final_directory_out+'/task_4_pubmed_Accuracy.png')
			plt.clf()

		# f1_micro_average_list=[]
		# f1_macro_average_list=[]
		# accuracy_average_list=[]

		print("PERFORMING OPERATIONS ON ORIGINAL MATRIX")
		f.write("\n**************PERFORMING OPERATIONS ON ORIGINAL MATRIX*****************\n")
		f11.write("\n*************PERFORMING OPERATIONS ON ORIGINAL MATRIX******************\n")
		list_k_fold=cross_validation_k(train,labels,10)
		for k1 in range(0,10):
			print("k1=",end=' ')
			print(k1)
			prior={}
			dic1={}
			dic2={}
			testset=[]
			trainset=[]
			trainlabel=[]
			testlabel=[]
			prior={}
			dic={}
			testset=[]
			testlabel=[]
			label1=[]
			#print(list_k_fold)
			for i in range(10):
				#print(i)
				if i==k1:					
					label1.extend(list_k_fold[i])
			for i2 in range(len(labels)):
				if i2 in label1:
					testset.append(train[i2])
					testlabel.append(labels[i2])
				else:
					
					trainset.append(train[i2])
					#print(trainset)
					trainlabel.append(labels[i2])
			for i1 in range(len(trainset)):
				if trainlabel[i1][0] not in dic:
					dic[trainlabel[i1][0]]=[]
				dic[trainlabel[i1][0]].append(trainset[i1])				
			
			dic1,dic2=b1.calc_mean_stddev(train_R,dic)
			prior=b1.priors(trainset,dic)
			predictions,acc=b1.predictions_calculate(testset,testlabel,dic1,dic2,prior)
			a,b=F1_score(testlabel,predictions)
			f1_micro_average[0]+=b
			f1_macro_average[0]+=a
			accuracy_average[0]+=acc

			predictions=[]
			predictions,acc=nn1.knn1(testset,trainset,testlabel,trainlabel)
			a,b=F1_score(testlabel,predictions)
			f1_micro_average[1]+=b
			f1_macro_average[1]+=a
			accuracy_average[1]+=acc

			predictions=[]
			predictions,acc=nn1.scikit_knn(testset,trainset,testlabel,trainlabel)
			# print(len(predictions))
			# print(len(testlabel))
			a,b=F1_score(testlabel,predictions)
			f1_micro_average[2]+=b
			f1_macro_average[2]+=a
			accuracy_average[2]+=acc

			predictions=[]
			predictions,acc=b1.sklearn_bayes(testset,trainset,testlabel,trainlabel)
			F1_score(testlabel,predictions)
			f1_micro_average[3]+=b
			f1_macro_average[3]+=a
			accuracy_average[3]+=acc
		#print(accuracy_average)
		f1_micro_average[:]=[x /10 for x in f1_micro_average]
		f1_macro_average[:]=[x /10 for x in f1_macro_average]
		accuracy_average[:]=[x /10 for x in accuracy_average]
		# f1_micro_average_list.append(f1_micro_average)
		# f1_macro_average_list.append(f1_macro_average)
		# accuracy_average_list.append(accuracy_average)
		f.write("\nF1 MACRO SCORE:\n")
		f11.write("\nF1 MACRO SCORE:\n")
		f.write("Bayes: "+str(f1_macro_average[0])+str("\n")+"KNN: "+str(f1_macro_average[1])+str("\n"))
		f11.write(str("\n")+"Sklearn_knn: "+str(f1_macro_average[2])+"\nsklearn_bayes: "+str(f1_macro_average[3])+"\n")
		f.write("\nF1 MICRO SCORE:\n")
		f11.write("\nF1 MICRO SCORE:\n")
		f.write("Bayes: "+str(f1_micro_average[0])+str("\n")+"KNN: "+str(f1_micro_average[1])+str("\n"))
		f11.write("Sklearn_knn: "+str(f1_micro_average[2])+"\nsklearn_bayes: "+str(f1_micro_average[3])+"\n")
		f.write("\nACCURACY:\n")
		f11.write("\nACCURACY:\n")
		f.write("Bayes: "+str(accuracy_average[0])+str("\n")+"KNN: "+str(accuracy_average[1])+str("\n"))
		f11.write("Sklearn_knn: "+str(accuracy_average[2])+"\nsklearn_bayes: "+str(accuracy_average[3])+"\n")
		
		
		print("F1 MACRO SCORE:\n")
		print("Bayes: "+str(f1_macro_average[0])+str("\n")+"KNN: "+str(f1_macro_average[1])+str("\n")+"Sklearn_knn: "+str(f1_macro_average[2])+"\nsklearn_bayes: "+str(f1_macro_average[3])+"\n")
		print("F1 MICRO SCORE:\n")
		print("Bayes: "+str(f1_micro_average[0])+str("\n")+"KNN: "+str(f1_micro_average[1])+str("\n")+"Sklearn_knn: "+str(f1_micro_average[2])+"\nsklearn_bayes: "+str(f1_micro_average[3])+"\n")
		print("ACCURACY:\n")
		print("Bayes: "+str(accuracy_average[0])+str("\n")+"KNN: "+str(accuracy_average[1])+str("\n")+"Sklearn_knn: "+str(accuracy_average[2])+"\nsklearn_bayes: "+str(accuracy_average[3])+"\n")
		
		# print(str("F1 MACRO SCORE:")+str(f1_macro_average)+str("\n")+str("F1 MICRO SCORE:")+str(f1_micro_average)+str("\n")+str("ACCURACY:")+str(accuracy_average)+str("\n"))		
		# print("\n")
		
		if strng=="dolphins":
			lsh1.LSH_main(train_pca,train_label,"dolphin")
		else:
			lsh1.LSH_main(train_pca,train_label,"pubmed")
		f.close()
		f11.close()

		
			
	elif strng=="twitter":
		accuracy_average=[0 for i in range(4)]
		f1_macro_average=[0 for i in range(4)]
		f1_micro_average=[0 for i in range(4)]
		print("FOR TWITTER DATA SET: ")
		final_directory = os.path.join(current_directory, r'twitter_D_matrices')
		if not os.path.exists(final_directory):
			os.makedirs(final_directory)
		#f=open(final_directory+"/Accuracy.txt",'w')
		final_directory_out = os.path.join(current_directory, r'output_plots')
		if not os.path.exists(final_directory_out):
			os.makedirs(final_directory_out)
		f=open("task_3_twitter.txt",'w')
		f11=open("task_4_twitter.txt",'w')
			#f2.write(str("DOLPHIN DATA SET\n"))
			
		dic1={}
		dic2={}
		testset=[]
		trainset=[]
		trainlabel=[]
		testlabel=[]
		prior={}
		word_freq={}
		train=[]	
		labels=[]
		train = pd.read_csv("twitter.txt",header=None)
		labels=pd.read_csv("twitter_label.txt",header=None)
		f1_micro_average_list=[0 for i in range(4)]
		f1_macro_average_list=[0 for i in range(4)]
		accuracy_average_list=[0 for i in range(4)]
		for i in range(4):
			f1_micro_average_list[i]=[]
			f1_macro_average_list[i]=[]
			accuracy_average_list[i]=[]

		bag_of_words = set()
		finalmat = []
		words1=set()
		text1={}
		for i,sentence in train.iterrows():
			text = {}
			
			for word in sentence[0].strip().split():
				if word not in stopwords.words('english'): 	
					if word in text:
						text[word] += 1
					else:
						text[word]=1
				
			finalmat.append(text)
			bag_of_words.update(text)	
		
		
		 	
		mat = [[(text[word] if word in text else 0) for word in bag_of_words] for text in finalmat]
		mat1=mat

		train_binary=np.array(mat)	
		train_pca=train_binary
		train=np.array(train)
		labels=np.array(labels)
		labels_pca=labels
		#list_k_fold=cross_validation_k(train_binary,labels,5)
		#train_binary=np.array(train_binary)
		#labels=np.array(labels)
		new_words = []
		#print(train)
		n,m=train_binary.shape

		# testset=train
		# testlabel=labels
		k3=10
		j21=2
		#print(m,n)
		D=[]
		f.write("\n******************************TWITTER DATASET:****************************************\n")
		f11.write("\n******************************TWITTER DATASET:****************************************\n")
		print("PERFORMING OPERATIONS ON R MATRIX")
		f.write("PERFORMING OPERATIONS ON R MATRIX\n")
		while j21<=int(m/2):
			accuracy_average=[0 for i in range(4)]
			f1_macro_average=[0 for i in range(4)]
			f1_micro_average=[0 for i in range(4)]
			print("THE VALUE OF D IS:",end=' ')
			print(j21)
			f.write("THE VALUE OF D IS:")
			f.write(str(j21))
			f.write(str("\n\n"))
			f11.write("THE VALUE OF D IS:")
			f11.write(str(j21))
			f11.write(str("\n\n"))
			D.append(j21)
			train_R=pro1.random_projection(m,n,train_binary,j21,final_directory)
			list_k_fold=cross_validation_k(train_R,labels,k3)
			j21=j21*2
			k=10
		# 	for k1 in range(10):
		# 		print("k1=",end=' ')
		# 		print(k1)
		# 		prior={}
		# 		testset=[]
		# 		trainset=[]
		# 		trainlabel=[]
		# 		testlabel=[]
		# 		dic={}
		# 		testset=[]
		# 		testlabel=[]
		# 		label1=[]
		# 		for i in range(10):
		# 			#print(i)
		# 			if i==k1:					
		# 				label1.extend(list_k_fold[i])
		# 		for i2 in range(len(labels)):
		# 			if i2 in label1:
		# 				testset.append(train_R[i2])
		# 				testlabel.append(labels[i2])
		# 			else:						
		# 				trainset.append(train_R[i2])
		# 				#print(trainset)
		# 				trainlabel.append(labels[i2])
		# 		for i1 in range(len(trainset)):
		# 			if trainlabel[i1][0] not in dic:
		# 				dic[trainlabel[i1][0]]=[]
		# 			dic[trainlabel[i1][0]].append(trainset[i1])	
				
				
		# 		dic1,dic2=b1.calc_mean_stddev(trainset,dic)
		# 		prior=b1.priors(trainset,dic)
		# 		predictions,acc=b1.predictions_calculate(testset,testlabel,dic1,dic2,prior)
		# 		a,b=F1_score(testlabel,predictions)
		# 		f1_micro_average[0]+=b
		# 		f1_macro_average[0]+=a
		# 		accuracy_average[0]+=acc

		# 		predictions,acc=nn1.knn1(testset,trainset,testlabel,trainlabel)
		# 		a,b=F1_score(testlabel,predictions)
		# 		f1_micro_average[1]+=b
		# 		f1_macro_average[1]+=a
		# 		accuracy_average[1]+=acc

		# 		predictions,acc=nn1.scikit_knn(testset,trainset,testlabel,trainlabel)
		# 		a,b=F1_score(testlabel,predictions)
		# 		f1_micro_average[2]+=b
		# 		f1_macro_average[2]+=a
		# 		accuracy_average[2]+=acc

		# 		predictions,acc=b1.sklearn_bayes(testset,trainset,testlabel,trainlabel)
		# 		F1_score(testlabel,predictions)
		# 		f1_micro_average[3]+=b
		# 		f1_macro_average[3]+=a
		# 		accuracy_average[3]+=acc


		# 	f1_micro_average[:]=[x /10 for x in f1_micro_average]
		# 	f1_macro_average[:]=[x /10 for x in f1_macro_average]
		# 	accuracy_average[:]=[x /10 for x in accuracy_average]
		# 	f1_micro_average_list.append(f1_micro_average)
		# 	f1_macro_average_list.append(f1_macro_average)
		# 	accuracy_average_list.append(accuracy_average)
		# 	f.write("\nF1 MACRO SCORE:\n")
		# 	f11.write("\nF1 MACRO SCORE:\n")
		# 	f.write("Bayes: "+str(f1_macro_average[0])+str("\n")+"KNN: "+str(f1_macro_average[1])+str("\n"))
		# 	f11.write(str("\n")+"Sklearn_knn: "+str(f1_macro_average[2])+"\nsklearn_bayes: "+str(f1_macro_average[3])+"\n")
		# 	f.write("\nF1 MICRO SCORE:\n")
		# 	f11.write("\nF1 MICRO SCORE:\n")
		# 	f.write("Bayes: "+str(f1_micro_average[0])+str("\n")+"KNN: "+str(f1_micro_average[1])+str("\n"))
		# 	f11.write("Sklearn_knn: "+str(f1_micro_average[2])+"\nsklearn_bayes: "+str(f1_micro_average[3])+"\n")
		# 	f.write("\nACCURACY:\n")
		# 	f11.write("\nACCURACY:\n")
		# 	f.write("Bayes: "+str(accuracy_average[0])+str("\n")+"KNN: "+str(accuracy_average[1])+str("\n"))
		# 	f11.write("Sklearn_knn: "+str(accuracy_average[2])+"\nsklearn_bayes: "+str(accuracy_average[3])+"\n")
		# 	print("F1 MACRO SCORE:\n")
		# 	print("Bayes: "+str(f1_macro_average[0])+str("\n")+"KNN: "+str(f1_macro_average[1])+str("\n")+"Sklearn_knn: "+str(f1_macro_average[2])+"\nsklearn_bayes: "+str(f1_macro_average[3])+"\n")
		# 	print("F1 MICRO SCORE:\n")
		# 	print("Bayes: "+str(f1_micro_average[0])+str("\n")+"KNN: "+str(f1_micro_average[1])+str("\n")+"Sklearn_knn: "+str(f1_micro_average[2])+"\nsklearn_bayes: "+str(f1_micro_average[3])+"\n")
		# 	print("ACCURACY:\n")
		# 	print("Bayes: "+str(accuracy_average[0])+str("\n")+"KNN: "+str(accuracy_average[1])+str("\n")+"Sklearn_knn: "+str(accuracy_average[2])+"\nsklearn_bayes: "+str(accuracy_average[3])+"\n")
			
		#legends=["CustomBayes","CustomKNN","Sklearn_Bayes","Sklearn_KNN"]
		# accuracy_average=[0 for i in range(4)]
		# f1_macro_average=[0 for i in range(4)]
		# f1_micro_average=[0 for i in range(4)]

		# # f1_micro_average_list=[]
		# # f1_macro_average_list=[]
		# # accuracy_average_list=[]
		# for i in range(4):
		# 	plt.plot(D,f1_micro_average_list[i])
	# 	plt.xlabel('D Values')
	# 	plt.ylabel('F1-MICRO-Score')
		#plt.legend(legends)	
			
		# #plt.show()

		# plt.savefig(final_directory_out+'/task_4_twitter_f1-Macro-accuracy.png')
		# plt.clf()
		
		
			#plt.show()
		# for i in range(4):
		# 	plt.plot(D,f1_macro_average_list[i])
	# 	plt.xlabel('D Values')
	# 	plt.ylabel('F1-MACRO-Score')
		#plt.legend(legends)	
	
		# #plt.show()
		# plt.savefig(final_directory_out+'/task_4_twitter_f1-Micro-accuracy.png')
		# plt.clf()
		# for i in range(4):
		# 	plt.plot(D,accuracy_average_list[i])
	# 	plt.xlabel('D Values')
	# 	plt.ylabel('ACCURACY')
		#plt.legend(legends)	
		
		# #plt.show()
		# plt.savefig(final_directory_out+'/task_4_twitter_Accuracy.png')
		# plt.clf()
		# k3=5
		
		print("PERFORMING OPERATIONS ON ORIGINAL MATRIX:\n")
		f.write("PERFORMING OPERATIONS ON ORIGINAL MATRIX:\n")
		list_k_fold=cross_validation_k(train,labels,10)
		for k1 in range(10):
			print("k1=",end=' ')
			print(k1)
			prior={}
			dic1={}
			dic2={}
			testset=[]
			trainset=[]
			trainlabel=[]
			testlabel=[]
			prior={}
			dic={}
			testset=[]
			testlabel=[]
			label1=[]
			#print(list_k_fold)
			for i in range(10):
				#print(i)
				if i==k1:					
					label1.extend(list_k_fold[i])
			for i2 in range(len(labels)):
				if i2 in label1:
					testset.append(train[i2])
					testlabel.append(labels[i2])
				else:
					
					trainset.append(train[i2])
					#print(trainset)
					trainlabel.append(labels[i2])
			for i1 in range(len(trainset)):
				if trainlabel[i1][0] not in dic:
					dic[trainlabel[i1][0]]=[]
				dic[trainlabel[i1][0]].append(trainset[i1])				
			
			label_dict={}
			trainset=pd.DataFrame(data=trainset)
			#print(len(trainset))
			text={}
			for i,sentence in trainset.iterrows():    #dictionary of all words to further remove words with frequency less than 1 and stopwords as well		
				for word in sentence[0].strip().split():
					if word not in stopwords.words('english'): 	
						if word in text:
							text[word] += 1
						else:
							text[word]=1
			text1={k:val for k,val in text.items() if val>=1}
			for i,sentence in trainset.iterrows():

				for word in sentence[0].strip().split():
					if word not in stopwords.words('english') and word in text1: 
						#print("h")
						if trainlabel[i][0] not in label_dict:
							label_dict[trainlabel[i][0]]={}
						#if labels[i][0]==1:
						if word not in label_dict[trainlabel[i][0]]:
							#print()
							label_dict[trainlabel[i][0]][word]=0   	
						label_dict[trainlabel[i][0]][word]+=1

			prior=b1.priors(trainset,dic)		
			predictions,acc=b1.bayes_twitter(labels,label_dict,prior,testset,testlabel)
			# calc_mean_stddev(dic)
			# priors(dic)
			#predictions,acc=predictions_calculate(testset,testlabel)
			a,b=F1_score(testlabel,predictions)
			f1_micro_average[0]+=b
			f1_macro_average[0]+=a
			accuracy_average[0]+=acc
			predictions=[]

			predictions,acc=nn1.knn1(testset,trainset,testlabel,trainlabel)
			a,b=F1_score(testlabel,predictions)
			f1_micro_average[1]+=b
			f1_macro_average[1]+=a
			accuracy_average[1]+=acc

			predictions=[]
			predictions,acc=nn1.scikit_knn(testset,trainset,testlabel,trainlabel)
			# print(len(predictions))
			# print(len(testlabel))
			a,b=F1_score(testlabel,predictions)
			f1_micro_average[2]+=b
			f1_macro_average[2]+=a
			accuracy_average[2]+=acc

			predictions=[]
			predictions,acc=b1.sklearn_bayes(testset,trainset,testlabel,trainlabel)
			F1_score(testlabel,predictions)
			f1_micro_average[3]+=b
			f1_macro_average[3]+=a
			accuracy_average[3]+=acc
		#print(accuracy_average)
		f1_micro_average[:]=[x /10 for x in f1_micro_average]
		f1_macro_average[:]=[x /10 for x in f1_macro_average]
		accuracy_average[:]=[x /10 for x in accuracy_average]
		# f1_micro_average_list.append(f1_micro_average)
		# f1_macro_average_list.append(f1_macro_average)
		# accuracy_average_list.append(accuracy_average)
		f.write("\nF1 MACRO SCORE:\n")
		f11.write("\nF1 MACRO SCORE:\n")
		f.write("Bayes: "+str(f1_macro_average[0])+str("\n")+"KNN: "+str(f1_macro_average[1])+str("\n"))
		f11.write(str("\n")+"Sklearn_knn: "+str(f1_macro_average[2])+"\nsklearn_bayes: "+str(f1_macro_average[3])+"\n")
		f.write("\nF1 MICRO SCORE:\n")
		f11.write("\nF1 MICRO SCORE:\n")
		f.write("Bayes: "+str(f1_micro_average[0])+str("\n")+"KNN: "+str(f1_micro_average[1])+str("\n"))
		f11.write("Sklearn_knn: "+str(f1_micro_average[2])+"\nsklearn_bayes: "+str(f1_micro_average[3])+"\n")
		f.write("\nACCURACY:\n")
		f11.write("\nACCURACY:\n")
		f.write("Bayes: "+str(accuracy_average[0])+str("\n")+"KNN: "+str(accuracy_average[1])+str("\n"))
		f11.write("Sklearn_knn: "+str(accuracy_average[2])+"\nsklearn_bayes: "+str(accuracy_average[3])+"\n")
		print("F1 MACRO SCORE:\n")
		print("Bayes: "+str(f1_macro_average[0])+str("\n")+"KNN: "+str(f1_macro_average[1])+str("\n")+"Sklearn_knn: "+str(f1_macro_average[2])+"\nsklearn_bayes: "+str(f1_macro_average[3])+"\n")
		print("F1 MICRO SCORE:\n")
		print("Bayes: "+str(f1_micro_average[0])+str("\n")+"KNN: "+str(f1_micro_average[1])+str("\n")+"Sklearn_knn: "+str(f1_micro_average[2])+"\nsklearn_bayes: "+str(f1_micro_average[3])+"\n")
		print("ACCURACY:\n")
		print("Bayes: "+str(accuracy_average[0])+str("\n")+"KNN: "+str(accuracy_average[1])+str("\n")+"Sklearn_knn: "+str(accuracy_average[2])+"\nsklearn_bayes: "+str(accuracy_average[3])+"\n")
		
		lsh1.LSH_main(train_pca,train_label,"twitter")
		f.close()
		f11.close()







