def applyKNN(request): #get the file on which we will be applying docList = Document.objects.all() l = len(docList) revDocList = [] i = 0 while i<l: revDocList.append(docList[l-i-1]) i += 1 document = revDocList[0] if request.GET['K']!='' : k = int(request.GET['K']) else: k = 7 classList = wKNN(str(document.docfile),k) l = len(classList) lis = [] for i in range(l): lis.append((classList[i][1],classList[i][0])) filename = str(document.docfile) context = { 'title':'KNN Results', 'msg':'<br>For the file '+filename+' .<a href="/home/">Click here to go back!!</a>', 'colA':'Class Name', 'colB':'Percentage Chance', 'dataSet' : lis, } return render(request,'results.html',context)
def testFile(path,knnResult,bayesianResult,f): i = 1 realClass = path.split('/')[1] while i<8: classList = wKNN(path,i) knnResult.append((str(path)+' - '+str(i)+' - '+str(classList[0][1]),realClass,classList[0][1])) print(str(path)+' - '+str(i)+' - '+str(classList[0][1])+' | '+realClass+' | '+classList[0][1]) f.write((str(path)+' - '+str(i)+' - '+str(classList[0][1])+' | '+realClass+' | '+classList[0][1])+'\n') i += 2 classList = NaiveBayes(path) bayesianResult.append((str(path)+' - '+str(classList[0][1]),realClass,classList[0][1])) print(str(path)+' - '+str(classList[0][1])+' | '+realClass+' | '+classList[0][1]) f.write((str(path)+' - '+str(classList[0][1])+' | '+realClass+' | '+classList[0][1])+'\n')
def applyKNN(request): #get the file on which we will be applying docList = Document.objects.all() l = len(docList) revDocList = [] i = 0 while i<l: revDocList.append(docList[l-i-1]) i += 1 document = revDocList[0] k = int(request.GET['K']) classList = wKNN(str(document.docfile),k) filename = str(document.docfile) return HttpResponse('<br>for the file '+filename+' .The class list is: <br>'+str(classList))