bayes lib

This commit is contained in:
s434766 2021-05-12 13:23:10 +02:00
parent 9cb2fb2612
commit a16904d4cf
4 changed files with 10937 additions and 0 deletions

40
bayes2.py Normal file
View File

@ -0,0 +1,40 @@
import gzip
import io
import pandas as pd
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import make_pipeline
from sklearn.metrics import accuracy_score
def read_data_gz(baseUrl):
f = gzip.open(baseUrl,'r')
data_unzip = f.read()
data = pd.read_table(io.StringIO(data_unzip.decode('utf-8')), error_bad_lines=False, header= None)
return data
baseUrl = '/home/przemek/ekstrakcja/sport-text-classification-ball-ISI-public/'
data = read_data_gz(baseUrl + 'train/train.tsv.gz')
y_train = data[0].values
x_train = data[1].values
model = make_pipeline(TfidfVectorizer(), MultinomialNB())
model.fit(x_train, y_train)
# dev-0
x_dev = pd.read_table(baseUrl + 'dev-0/in.tsv', error_bad_lines=False, header= None)
x_dev = x_dev[0].values
y_pred = model.predict(x_dev)
y_pred.tofile(baseUrl + 'dev-0/out.tsv', sep='\n')
# --------------
# test-A
x_testA = pd.read_table(baseUrl + '/test-A/in.tsv', error_bad_lines=False, header= None)
x_testA= x_testA[0].values
y_predA = model.predict(x_testA)
y_predA.tofile(baseUrl + 'test-A/out.tsv', sep='\n')
# --------------

5452
dev-0/out.tsv Normal file

File diff suppressed because it is too large Load Diff

BIN
geval Executable file

Binary file not shown.

5445
test-A/out.tsv Normal file

File diff suppressed because it is too large Load Diff