sport-text-classification s478874

This commit is contained in:
Jakub Eichner 2022-06-07 17:27:48 +02:00
parent d043e30286
commit 64f81bcc7e
4 changed files with 109081 additions and 0 deletions

5452
dev-0/out.tsv Normal file

File diff suppressed because it is too large Load Diff

52
run.py Normal file
View File

@ -0,0 +1,52 @@
import pandas as pd
from sklearn.naive_bayes import GaussianNB
from sklearn.feature_extraction.text import TfidfVectorizer
nrows = 10000
def load_data(path):
try:
in_df = pd.read_csv(f'{path}/in.tsv', sep='\t', header=None, nrows=nrows, error_bad_lines=False)
except:
in_df = pd.read_csv(f'{path}/train.tsv', sep='\t', header=None, nrows=nrows, error_bad_lines=False)
try:
exp_df = pd.read_csv(f'{path}/expected.tsv', sep='\t', header=None, nrows=nrows, error_bad_lines=False)
except:
exp_df = None
return in_df, exp_df
def write_res(data, path):
with open(path, 'w') as f:
for line in data:
f.write(f'{line}\n')
print(f"Data written {path}/out.tsv")
def main():
in_df = load_data('train')
x_df, y_df = in_df[0][1], in_df[0][0]
vectorizer = TfidfVectorizer(lowercase=True, stop_words=['english'])
train_x = vectorizer.fit_transform(x_df)
gnb = GaussianNB()
gnb.fit(train_x.toarray(), y_df)
paths = ['dev-0', 'test-A']
for path in paths:
x = load_data(path)
vec = vectorizer.transform(x[0][0])
result = gnb.predict(vec.todense())
write_res(result, f'{path}/out.tsv')
if __name__ == '__main__':
main()

5445
test-A/out.tsv Normal file

File diff suppressed because it is too large Load Diff

98132
train/train.tsv Normal file

File diff suppressed because it is too large Load Diff