def plotIterationAcc(itr,tau): newInstanceD = {} wt = np.ones(300) # create a random weight vector for i in range(0,300): wt[i] = np.random.rand() for i in range(0,itr): wt, newInstanceD = computeWeight(superBagsDict,Y,wt) # wt, newInstanceD = computeWeightDelta(superBagsDict,Y,wt) pX=[] nX=[] nY=[] pY=[] FinalTweets = [] cntP=1 cntN=1 # Algorithm1 for k in newInstanceD.keys(): # print "super",k # print "***************************************************************8" for i in newInstanceD[k].keys(): # print "bag",i # print "########################" for j in newInstanceD[k][i].keys(): # print "art",j # print "=====================" if Y[k-1]==1: pX.append(cntP) pY.append(newInstanceD[k][i][j]) cntP=cntP+1 else: nX.append(cntN) nY.append(newInstanceD[k][i][j]) cntN=cntN+1 if newInstanceD[k][i][j]>=tau and Y[k-1]==1: #print "article: ",k,i,j #print "prob: ",newInstanceD[k][i][j] #print "sentence: ", sentenceDict[k][i][j] item = [] item.append(k) item.append(i) item.append(j) FinalTweets.append(item) print "size of finaltweets",len(FinalTweets) acc=findCosineScore(FinalTweets) print "Accuracy=",acc return acc
superBagsDict = pickle.load(handle) with open('../input/tfSentence.pickle', 'rb') as handle: # '../input/dataSentences.pickle' sentenceDict = pickle.load(handle) # print superBagsDict[1].keys() # print superBagsDict[2].keys() newInstanceD = {} wt = np.ones(300) # create a random weight vector for i in range(0, 300): wt[i] = np.random.rand() eta = 1.2 for i in range(0, 2): wt, newInstanceD = computeWeight(eta, superBagsDict, Y, wt) pX = [] nX = [] nY = [] pY = [] FinalTweets = [] tau = 0.85 cntP = 1 cntN = 1 # Algorithm1 for k in newInstanceD.keys(): # print "super",k # print "***************************************************************8" for i in newInstanceD[k].keys():