solution
This commit is contained in:
parent
756ef4277a
commit
2194c77c4b
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
|
||||
.idea/*
|
||||
*~
|
||||
*.swp
|
||||
*.bak
|
||||
|
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
BIN
dev-0/in.tsv.xz
BIN
dev-0/in.tsv.xz
Binary file not shown.
5272
dev-0/out.tsv
Normal file
5272
dev-0/out.tsv
Normal file
File diff suppressed because it is too large
Load Diff
30
run.py
Normal file
30
run.py
Normal file
@ -0,0 +1,30 @@
|
||||
import pandas as pd
|
||||
from sklearn.feature_extraction.text import TfidfVectorizer
|
||||
from sklearn.naive_bayes import MultinomialNB
|
||||
|
||||
with open('train/in.tsv', 'r', encoding='utf-8') as f:
|
||||
x_train = pd.DataFrame([line.strip().split('\t') for line in f.readlines()], columns=['text', 'text_id'])
|
||||
with open('dev-0/in.tsv', 'r', encoding='utf-8') as f:
|
||||
x_dev = pd.DataFrame([line.strip().split('\t') for line in f.readlines()], columns=['text', 'text_id'])
|
||||
with open('train/in.tsv', 'r', encoding='utf-8') as f:
|
||||
x_test = pd.DataFrame([line.strip().split('\t') for line in f.readlines()], columns=['text', 'text_id'])
|
||||
|
||||
y_train = pd.read_csv('train/expected.tsv', sep='\t', names=['paranormal'], encoding='utf-8')
|
||||
tfidf_vectorizer = TfidfVectorizer(max_df=0.95, max_features=500)
|
||||
x_train_vectorized = tfidf_vectorizer.fit_transform(x_train['text'].values)
|
||||
|
||||
mnb_model = MultinomialNB().fit(x_train_vectorized, y_train.values.ravel())
|
||||
|
||||
# Dev data
|
||||
x_dev_prepared = tfidf_vectorizer.transform(x_dev['text'].values)
|
||||
predictions = mnb_model.predict(x_dev_prepared)
|
||||
with open('dev-0/out.tsv', 'w') as f:
|
||||
for pred in predictions:
|
||||
f.write(f'{pred}\n')
|
||||
|
||||
# Test data
|
||||
x_test_vectorized = tfidf_vectorizer.transform(x_test['text'].values)
|
||||
predictions = mnb_model.predict(x_test_vectorized)
|
||||
with open('test-A/out.tsv', 'w') as f:
|
||||
for pred in predictions:
|
||||
f.write(f'{pred}\n')
|
5152
test-A/in.tsv
Normal file
5152
test-A/in.tsv
Normal file
File diff suppressed because one or more lines are too long
BIN
test-A/in.tsv.xz
BIN
test-A/in.tsv.xz
Binary file not shown.
289579
test-A/out.tsv
Normal file
289579
test-A/out.tsv
Normal file
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
BIN
train/in.tsv.xz
BIN
train/in.tsv.xz
Binary file not shown.
Loading…
Reference in New Issue
Block a user