def testModel(): acc=0 for t in test: tokens = we.make_token(t[1:]) prob = knn.knnclassifier(knnpos,knnneg,tokens.keys(),5) if((prob[1]>prob[0])==(t[0]=="1") or (prob[0]>prob[1])==(t[0]=="0")): acc = acc+1 return (acc/462.0)*100
def addNegKeywords(index): tokens = we.make_token(label[index][1:]) l = Set() for t in tokens: if t in negkeywords: l.add(t) if(len(l)!=0): knnneg.append(l) return l
def addNegKeywords(ln): tokens = we.make_token(ln) l = Set() for t in tokens: #if t in negkeywords : neg.add(t) l.add(t) if(len(l)!=0): knnneg.append(l) return l
def addPosKeywords(lp): tokens = we.make_token(lp) l = Set() for t in tokens: #if t in poskeywords : pos.add(t) l.add(t) if(len(l)!=0): knnpos.append(l) return l
def addNegKeywords(ln): tokens = we.make_token(ln) l = Set() for t in tokens: #if t in negkeywords : neg.add(t) l.add(t) if (len(l) != 0): knnneg.append(l) return l
def addPosKeywords(lp): tokens = we.make_token(lp) l = Set() for t in tokens: #if t in poskeywords : pos.add(t) l.add(t) if (len(l) != 0): knnpos.append(l) return l
def testModel(): acc=0 for t in test: tokens = we.make_token(t[1:]) testlabel = knn.knnclassifier2(knnpos,knnneg,tokens.keys(),5) if((testlabel==1)==(t[0]=="1") or (testlabel==0)==(t[0]=="0")): acc = acc+1 # else: # print t # print we.tagged_tokens(t[1:])""" return (acc/3662.0)*100
def addNegKeywords(index): global negl tokens = we.make_token(label[index][1:]) l = [] for t in tokens: if t in negkeywords: if(neg.has_key(t)): neg[t]+=1 else: neg[t]=1 negl+=1 l.append(t) if(len(l)!=0): knnneg.append(l) return l
def addPosKeywords(index): global posl tokens = we.make_token(label[index][1:]) l = [] for t in tokens: if t in poskeywords: if(pos.has_key(t)): pos[t]+=1 else: pos[t]=1 posl+=1 l.append(t) if(len(l)!=0): knnpos.append(l) return l
for t in tokens: #if t in negkeywords : neg.add(t) l.add(t) if(len(l)!=0): knnneg.append(l) return l train = [] index = 0 while(maxp>0): if label[index][0] == "1": train.append(label[index]) maxp -=1 tokens = we.make_token(label[index][1:]) l = Set() for t in tokens: if t in poskeywords : pos.add(t) l.add(t) if(len(l)!=0): knnpos.append(l) index+=2 index = 1 while(maxn>0): if label[index][0] == "0": train.append(label[index]) maxn -=1 tokens = we.make_token(label[index][1:])
#print test def testModel(): acc=0 for t in test: tokens = we.make_token(t[1:]) prob = knn.knnclassifier(knnpos,knnneg,tokens.keys(),5) if((prob[1]>prob[0])==(t[0]=="1") or (prob[0]>prob[1])==(t[0]=="0")): acc = acc+1 return (acc/462.0)*100 index = 0 while(maxp>0): if label[index][0] == "1": maxp -=1 tokens = we.make_token(label[index][1:]) l = Set() for t in tokens: if t in poskeywords : pos.add(t) l.add(t) if(len(l)!=0): knnpos.append(l) index+=2 index = 1 while(maxn>0): if label[index][0] == "0": maxn -=1 tokens = we.make_token(label[index][1:]) l = Set()
#if t in negkeywords : neg.add(t) l.add(t) if (len(l) != 0): knnneg.append(l) return l train = [] index = 0 while (maxp > 0): if label[index][0] == "1": train.append(label[index]) maxp -= 1 tokens = we.make_token(label[index][1:]) l = Set() for t in tokens: if t in poskeywords: pos.add(t) l.add(t) if (len(l) != 0): knnpos.append(l) index += 2 index = 1 while (maxn > 0): if label[index][0] == "0": train.append(label[index]) maxn -= 1 tokens = we.make_token(label[index][1:])