Compare commits

...

26 Commits

Author SHA1 Message Date
6be8cd183c laptop commit fixed naive baise 2020-05-02 19:26:03 +02:00
a6694d768d laptop commit fixed naive baise 2020-05-02 19:16:25 +02:00
84b8b45e76 laptop commit fixed naive baise 2020-05-02 18:49:56 +02:00
4d38c7f755 laptop commit fixed naive baise 2020-05-02 18:40:30 +02:00
88f4a83b98 laptop commit fixed naive baise 2020-05-02 18:40:08 +02:00
d22c01b95e laptop commit fixed naive baise 2020-05-02 18:31:32 +02:00
02fc6df77e laptop commit fixed naive baise 2020-05-02 18:30:58 +02:00
0afeba8ac8 laptop commit fixed naive baise 2020-05-02 18:24:22 +02:00
763ce22710 laptop commit fixed naive baise 2020-05-02 18:16:25 +02:00
7c966a9c00 laptop commit 2020-05-02 17:08:25 +02:00
a3ee97af95 laptop commit 2020-05-02 17:01:57 +02:00
Bartusiak
c435242456 Rewrite linear regression (0/1) 2020-04-20 18:40:51 +02:00
Bartusiak
2311010c15 Rewrite linear regression (0/1) 2020-04-20 18:35:38 +02:00
Bartusiak
b60422d0b7 Rewrite linear regression (0/1) 2020-04-20 18:34:14 +02:00
Bartusiak
caca661287 Create new prediction, becasue forgot about another in.tsv 2020-03-31 17:09:32 +02:00
Bartusiak
02b281edc8 Fixed problem with KeyError 2020-03-31 14:50:58 +02:00
Bartusiak
7ffbacd865 Fixed problem with KeyError 2020-03-31 14:47:37 +02:00
Bartusiak
5d7f903e18 Fixed problem with KeyError 2020-03-31 14:41:37 +02:00
Bartusiak
c6dff78d16 Fixed problem with KeyError 2020-03-31 01:34:48 +02:00
Bartusiak
d128feed46 Fixed problem with KeyError 2020-03-31 01:14:53 +02:00
Bartusiak
8946cee780 Fixed problem with KeyError 2020-03-31 01:10:38 +02:00
Bartusiak
f290964067 Added file code_prediction, where code creating file out.tsv which results is saving to folders dev-0 and test-A 2020-03-29 01:04:18 +01:00
Bartusiak
082c69e025 Added file code_prediction, where code creating file out.tsv which results is saving to folders dev-0 and test-A 2020-03-29 00:58:08 +01:00
Bartusiak
4951a7cc47 Added file code_prediction, where code creating file out.tsv which results is saving to folders dev-0 and test-A 2020-03-29 00:37:57 +01:00
Bartusiak
5c036684c8 First comment 2020-03-28 20:40:28 +01:00
Bartusiak
0774e8bc17 First comment 2020-03-23 20:24:24 +01:00
22 changed files with 606840 additions and 294861 deletions

2
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Default ignored files
/workspace.xml

8
.idea/Pierwsze.iml Normal file
View 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>

View 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
View 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
View 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
View 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

Binary file not shown.

38
code.py
View File

@ -1,15 +1,21 @@
from collections import defaultdict
import math
import pickle
import re
open_file=('test-A/out.tsv')
#---------------TRAIN START
#Prawdopodobienstwo wylosowania dokumentu
def calc_class_logprob(expected_path):
paranormal_classcount=0
skeptic_classcount=0
with open(expected_path) as f:
with open(expected_path,encoding='utf-8') as f:
for line in f:
if 'P' in line:
if '1' in line:
paranormal_classcount += 1
if 'S' in line:
if '0' in line:
skeptic_classcount += 1
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):
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):
class_ = exp.rstrip('\n').replace(' ','')
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:
if class_ == 'P':
if class_ == '1':
word_counts['paranormal'][token] += 1
elif class_ == 'S':
elif class_ == '0':
word_counts['skeptic'][token] += 1
return word_counts
@ -46,12 +62,14 @@ def calc_word_logprobs(word_counts):
word_logprobs[class_][token] = math.log(word_prob)
return word_logprobs
#--------------- TRAIN END
def main():
paranomal_class_logprob, skeptic_class_logprob = calc_class_logprob("F:/UAM/SEMESTR_I_MGR/SYSTEMY_INTELIGENTNE/ic4g/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")
paranomal_class_logprob, skeptic_class_logprob = calc_class_logprob("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)
pickle.dump([paranomal_class_logprob, skeptic_class_logprob, word_logprobs], open('naive_base_model.pkl','wb'))
main()

46
code_prediction.py Normal file
View 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()

File diff suppressed because it is too large Load Diff

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

File diff suppressed because it is too large Load Diff

BIN
model.pkl Normal file

Binary file not shown.

BIN
naive_base_model.pkl Normal file

Binary file not shown.

1439
out.tsv Normal file

File diff suppressed because it is too large Load Diff

6
out_y_hat.tsv Normal file
View 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
1 Y_hat: -0.0005393564509196473
2 Y_hat: -3.9997270479357687
3 Y_hat: -4.058054620846149
4 Y_hat: -4.948997989328446
5 Y_hat: -5.607522681904628
6 Y_hat: -5.510496552820199

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

File diff suppressed because it is too large Load Diff

0
test.tsv Normal file
View File

6
test_a.tsv Normal file
View File

@ -0,0 +1,6 @@
0
0
0
0
0
0
1 0
2 0
3 0
4 0
5 0
6 0

File diff suppressed because it is too large Load Diff

289579
train/in.tsv Normal file

File diff suppressed because one or more lines are too long