36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
def predictMenOrFemale(filpath):
|
|
file = open(filpath+"/in.tsv",'r',encoding='utf-8')
|
|
listOfLine = file.readlines()
|
|
lenOfFile = len(listOfLine)
|
|
sum=0
|
|
for line in listOfLine:
|
|
sum+=len(line)
|
|
avarageLenOfLine = sum/lenOfFile
|
|
result= open(filpath+'/out.tsv','w+',encoding='utf-8')
|
|
for line in listOfLine:
|
|
if any(item in line for item in listOfFemaleWord) or avarageLenOfLine >= len(line):
|
|
answer = 0
|
|
elif any(item in line for item in listOfMaleWord) or avarageLenOfLine < len(line):
|
|
answer = 1
|
|
result.write(f'{answer}\n')
|
|
def acc(filepath):
|
|
expexted = open(filepath+'/expected.tsv','r')
|
|
exp = expexted.readlines()
|
|
lenOfFile = len(exp)
|
|
resulte = open(filepath+'/out.tsv','r')
|
|
sum=0
|
|
for i,line in enumerate(exp):
|
|
for line2 in resulte:
|
|
if line2[0]==line[0]:
|
|
sum +=1
|
|
break
|
|
return sum/lenOfFile
|
|
|
|
listOfMaleWord = ['silnik','windows','silnika','gb','mb','meczu','pc','opony','apple','iphone','zwiastuny','hd','ubuntu','systemu','serwer']
|
|
listOfFemaleWord = ['ciąży','miesiączki','ciasto','ciąże','zadowolona','ciąża','ciazy','antykoncepcyjne','ginekolog','tabletki','mąż','miesiączka','krwawienie','ciasta']
|
|
|
|
predictMenOrFemale('test-A')
|
|
predictMenOrFemale('dev-1')
|
|
|
|
predictMenOrFemale('train')
|
|
print(acc('train')) |