Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
6be8cd183c | |||
a6694d768d | |||
84b8b45e76 | |||
4d38c7f755 | |||
88f4a83b98 | |||
d22c01b95e | |||
02fc6df77e | |||
0afeba8ac8 | |||
763ce22710 | |||
7c966a9c00 | |||
a3ee97af95 | |||
|
c435242456 | ||
|
2311010c15 | ||
|
b60422d0b7 | ||
|
caca661287 | ||
|
02b281edc8 | ||
|
7ffbacd865 | ||
|
5d7f903e18 | ||
|
c6dff78d16 | ||
|
d128feed46 | ||
|
8946cee780 | ||
|
f290964067 | ||
|
082c69e025 | ||
|
4951a7cc47 | ||
|
5c036684c8 | ||
|
0774e8bc17 |
2
.idea/.gitignore
vendored
Normal file
2
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/workspace.xml
|
8
.idea/Pierwsze.iml
Normal file
8
.idea/Pierwsze.iml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.8" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
7
.idea/misc.xml
Normal file
7
.idea/misc.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JavaScriptSettings">
|
||||||
|
<option name="languageLevel" value="ES6" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Pierwsze.iml" filepath="$PROJECT_DIR$/.idea/Pierwsze.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
BIN
Pierwsze.rar
Normal file
BIN
Pierwsze.rar
Normal file
Binary file not shown.
38
code.py
38
code.py
@ -1,15 +1,21 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import math
|
import math
|
||||||
import pickle
|
import pickle
|
||||||
|
import re
|
||||||
|
|
||||||
|
open_file=('test-A/out.tsv')
|
||||||
|
|
||||||
|
#---------------TRAIN START
|
||||||
|
|
||||||
|
#Prawdopodobienstwo wylosowania dokumentu
|
||||||
def calc_class_logprob(expected_path):
|
def calc_class_logprob(expected_path):
|
||||||
paranormal_classcount=0
|
paranormal_classcount=0
|
||||||
skeptic_classcount=0
|
skeptic_classcount=0
|
||||||
with open(expected_path) as f:
|
with open(expected_path,encoding='utf-8') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
if 'P' in line:
|
if '1' in line:
|
||||||
paranormal_classcount += 1
|
paranormal_classcount += 1
|
||||||
if 'S' in line:
|
if '0' in line:
|
||||||
skeptic_classcount += 1
|
skeptic_classcount += 1
|
||||||
|
|
||||||
paranormal_prob = paranormal_classcount / (paranormal_classcount + skeptic_classcount)
|
paranormal_prob = paranormal_classcount / (paranormal_classcount + skeptic_classcount)
|
||||||
@ -20,15 +26,25 @@ def calc_class_logprob(expected_path):
|
|||||||
|
|
||||||
def calc_word_count(in_path, expected_path):
|
def calc_word_count(in_path, expected_path):
|
||||||
word_counts = {'paranormal':defaultdict(int), 'skeptic': defaultdict(int)}
|
word_counts = {'paranormal':defaultdict(int), 'skeptic': defaultdict(int)}
|
||||||
with open(in_path) as in_file, open(expected_path) as expected_file:
|
with open(in_path,encoding='utf-8') as in_file, open(expected_path,encoding='utf-8') as expected_file:
|
||||||
for line, exp in zip(in_file, expected_file):
|
for line, exp in zip(in_file, expected_file):
|
||||||
class_ = exp.rstrip('\n').replace(' ','')
|
class_ = exp.rstrip('\n').replace(' ','')
|
||||||
text, timestamp = line.rstrip('\n').split('\t')
|
text, timestamp = line.rstrip('\n').split('\t')
|
||||||
tokens = text.lower().split(' ')
|
text = text.lower()
|
||||||
|
text = re.sub(r'\\n+', " ", text)
|
||||||
|
text = re.sub(r'http\S+', " ", text)
|
||||||
|
text = re.sub(r'\/[a-z]\/', " ", text)
|
||||||
|
text = re.sub(r'[^a-z]', " ", text)
|
||||||
|
text = re.sub(r'\s{2,}', " ", text)
|
||||||
|
text = re.sub(r'\W\w{1,3}\W|\A\w{1,3}\W', " ", text)
|
||||||
|
text = re.sub(r'\W\w{1,3}\W|\A\w{1,3}\W', " ", text)
|
||||||
|
text = re.sub(r'\W\w{1,3}\W|\A\w{1,3}\W', " ", text)
|
||||||
|
text = re.sub(r'^\s', "", text)
|
||||||
|
tokens = text.split(' ')
|
||||||
for token in tokens:
|
for token in tokens:
|
||||||
if class_ == 'P':
|
if class_ == '1':
|
||||||
word_counts['paranormal'][token] += 1
|
word_counts['paranormal'][token] += 1
|
||||||
elif class_ == 'S':
|
elif class_ == '0':
|
||||||
word_counts['skeptic'][token] += 1
|
word_counts['skeptic'][token] += 1
|
||||||
return word_counts
|
return word_counts
|
||||||
|
|
||||||
@ -46,12 +62,14 @@ def calc_word_logprobs(word_counts):
|
|||||||
word_logprobs[class_][token] = math.log(word_prob)
|
word_logprobs[class_][token] = math.log(word_prob)
|
||||||
return word_logprobs
|
return word_logprobs
|
||||||
|
|
||||||
|
#--------------- TRAIN END
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
paranomal_class_logprob, skeptic_class_logprob = calc_class_logprob("F:/UAM/SEMESTR_I_MGR/SYSTEMY_INTELIGENTNE/ic4g/train/expected.tsv")
|
paranomal_class_logprob, skeptic_class_logprob = calc_class_logprob("train/expected.tsv")
|
||||||
word_counts=calc_word_count("F:/UAM/SEMESTR_I_MGR/SYSTEMY_INTELIGENTNE/ic4g/train/in.tsv","F:/UAM/SEMESTR_I_MGR/SYSTEMY_INTELIGENTNE/ic4g/train/expected.tsv")
|
word_counts=calc_word_count("train/in.tsv","train/expected.tsv")
|
||||||
|
word_counts['paranormal'][''] = 0
|
||||||
|
word_counts['skeptic'][''] = 0
|
||||||
word_logprobs = calc_word_logprobs(word_counts)
|
word_logprobs = calc_word_logprobs(word_counts)
|
||||||
pickle.dump([paranomal_class_logprob, skeptic_class_logprob, word_logprobs], open('naive_base_model.pkl','wb'))
|
pickle.dump([paranomal_class_logprob, skeptic_class_logprob, word_logprobs], open('naive_base_model.pkl','wb'))
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
46
code_prediction.py
Normal file
46
code_prediction.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
from collections import defaultdict
|
||||||
|
import math
|
||||||
|
import pickle
|
||||||
|
import re
|
||||||
|
|
||||||
|
open_file = open('naive_base_model.pkl', 'rb')
|
||||||
|
pickle_loaded = pickle.load(open_file)
|
||||||
|
paranomal_class_logprob, skeptic_class_logprob, word_logprobs = pickle_loaded
|
||||||
|
def prediction(input,output):
|
||||||
|
output_file = open(output,'w')
|
||||||
|
with open(input,encoding='utf-8') as in_file:
|
||||||
|
for line in in_file:
|
||||||
|
temp_paranormal_logprob = paranomal_class_logprob
|
||||||
|
temp_skeptic_logprob = skeptic_class_logprob
|
||||||
|
text, timestamp = line.rstrip('\n').split('\t')
|
||||||
|
text = text.lower()
|
||||||
|
text = re.sub(r'\\n+', " ", text)
|
||||||
|
text = re.sub(r'http\S+', " ", text)
|
||||||
|
text = re.sub(r'\/[a-z]\/', " ", text)
|
||||||
|
text = re.sub(r'[^a-z]', " ", text)
|
||||||
|
text = re.sub(r'\s{2,}', " ", text)
|
||||||
|
text = re.sub(r'\W\w{1,3}\W|\A\w{1,3}\W', " ", text)
|
||||||
|
text = re.sub(r'\W\w{1,3}\W|\A\w{1,3}\W', " ", text)
|
||||||
|
text = re.sub(r'\W\w{1,3}\W|\A\w{1,3}\W', " ", text)
|
||||||
|
text = re.sub(r'^\s', "", text)
|
||||||
|
tokens = text.split(' ')
|
||||||
|
for token in tokens:
|
||||||
|
if token not in word_logprobs['paranormal']:
|
||||||
|
word_logprobs['paranormal'][token] = -14.78
|
||||||
|
if token not in word_logprobs['skeptic']:
|
||||||
|
word_logprobs['skeptic'][token] = -15.6
|
||||||
|
|
||||||
|
temp_paranormal_logprob += paranomal_class_logprob + word_logprobs['paranormal'][token]
|
||||||
|
temp_skeptic_logprob += skeptic_class_logprob + word_logprobs['skeptic'][token]
|
||||||
|
|
||||||
|
if temp_paranormal_logprob > temp_skeptic_logprob:
|
||||||
|
output_file.write('1\n')
|
||||||
|
else:
|
||||||
|
output_file.write('0\n')
|
||||||
|
##
|
||||||
|
def main():
|
||||||
|
prediction('dev-0/in.tsv','dev-0/out.tsv')
|
||||||
|
prediction('test-A/in.tsv/in.tsv','test-A/out.tsv')
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
10544
dev-0/expected.tsv
10544
dev-0/expected.tsv
File diff suppressed because it is too large
Load Diff
5272
dev-0/in.tsv
Normal file
5272
dev-0/in.tsv
Normal file
File diff suppressed because one or more lines are too long
5272
dev-0/out.tsv
Normal file
5272
dev-0/out.tsv
Normal file
File diff suppressed because it is too large
Load Diff
BIN
naive_base_model.pkl
Normal file
BIN
naive_base_model.pkl
Normal file
Binary file not shown.
6
out_y_hat.tsv
Normal file
6
out_y_hat.tsv
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Y_hat: -0.0005393564509196473
|
||||||
|
Y_hat: -3.9997270479357687
|
||||||
|
Y_hat: -4.058054620846149
|
||||||
|
Y_hat: -4.948997989328446
|
||||||
|
Y_hat: -5.607522681904628
|
||||||
|
Y_hat: -5.510496552820199
|
|
5152
test-A/in.tsv/in.tsv
Normal file
5152
test-A/in.tsv/in.tsv
Normal file
File diff suppressed because one or more lines are too long
5152
test-A/out.tsv
Normal file
5152
test-A/out.tsv
Normal file
File diff suppressed because it is too large
Load Diff
6
test_a.tsv
Normal file
6
test_a.tsv
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
|
579158
train/expected.tsv
579158
train/expected.tsv
File diff suppressed because it is too large
Load Diff
289579
train/in.tsv
Normal file
289579
train/in.tsv
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user