This commit is contained in:
Adi 2022-05-11 00:59:27 +02:00
parent dc2a76c237
commit 6c3ca75b83
6 changed files with 1658 additions and 1684 deletions

View File

@ -7,8 +7,16 @@ from sklearn.metrics import accuracy_score
df = pd.read_csv("train/train.tsv", sep="\t", header=None, error_bad_lines=False) df = pd.read_csv("train/train.tsv", sep="\t", header=None, error_bad_lines=False)
dev_x = pd.read_csv("dev-0/in.tsv", sep="\t", header=None, error_bad_lines=False) dev_x = pd.read_csv("dev-0/in.tsv", sep="\t", header=None, error_bad_lines=False)
test_x = pd.read_csv("test-A/in.tsv", sep="\t", header=None, error_bad_lines=False)
with open('test-A/in.tsv', 'r', encoding='utf8') as file:
test = file.readlines()
test = pd.Series(test)
x = df[1] x = df[1]
y = df[0] y = df[0]
@ -17,17 +25,20 @@ model = make_pipeline(TfidfVectorizer(), MultinomialNB())
model.fit(x,y) model.fit(x,y)
pred_dev = model.predict(dev_x[0]) pred_dev = model.predict(dev_x[0])
pred_test = model.predict(test_x[0]) pred_dev = pd.Series(pred_dev)
with open('dev-0/out.tsv', 'wt') as file:
with open('dev-0/out.tsv', 'wt') as f:
for pred in pred_dev: for pred in pred_dev:
f.write(str(pred)+'\n') file.write(str(pred)+'\n')
pred_test = model.predict(test)
pred_test = pd.Series(pred_test)
pred_test = pred_test.astype('int')
with open('test-A/out.tsv', 'wt') as f: with open('test-A/out.tsv', 'wt') as file:
for pred in pred_test: for pred in pred_test:
f.write(str(pred)+'\n') file.write(str(pred)+'\n')

View File

@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": 23,
"id": "ce420679-f5aa-4c83-a912-3c4afa982d7e", "id": "ce420679-f5aa-4c83-a912-3c4afa982d7e",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -28,7 +28,7 @@
"\n", "\n",
"\n", "\n",
"df = pd.read_csv(\"train/train.tsv\", sep=\"\\t\", header=None, error_bad_lines=False)\n", "df = pd.read_csv(\"train/train.tsv\", sep=\"\\t\", header=None, error_bad_lines=False)\n",
"df = df.head(1000)\n", "\n",
"\n", "\n",
"\n", "\n",
"dev_x = pd.read_csv(\"dev-0/in.tsv\", sep=\"\\t\", header=None, error_bad_lines=False)\n", "dev_x = pd.read_csv(\"dev-0/in.tsv\", sep=\"\\t\", header=None, error_bad_lines=False)\n",
@ -69,54 +69,6 @@
"\n", "\n",
" \n" " \n"
] ]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "3e2a9ef0-6da0-4934-8099-378d859ae04e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0\n",
"0 ATP Sztokholm: Juergen Zopp wykorzystał szansę...\n",
"1 Krowicki z reprezentacją kobiet aż do igrzysk ...\n",
"2 Wielki powrót Łukasza Kubota Odradza się zawsz...\n",
"3 Marcel Hirscher wygrał ostatni slalom gigant m...\n",
"4 Polki do Czarnogóry z pełnią zaangażowania. Sy...\n",
"... ...\n",
"5440 Biało-czerwona siła w Falun. Oni będą reprezen...\n",
"5441 Finał WTA Tokio na żywo: Woźniacka - Osaka LIV...\n",
"5442 Oni zapisali się w annałach. Hubert Hurkacz 15...\n",
"5443 Poprawia się stan Nikiego Laudy. Austriak może...\n",
"5444 Liga Mistrzów. Zabójcza końcówka Interu Mediol...\n",
"\n",
"[5445 rows x 1 columns]\n",
"0 ATP Sztokholm: Juergen Zopp wykorzystał szansę...\n",
"1 Krowicki z reprezentacją kobiet aż do igrzysk ...\n",
"2 Wielki powrót Łukasza Kubota Odradza się zawsz...\n",
"3 Marcel Hirscher wygrał ostatni slalom gigant m...\n",
"4 Polki do Czarnogóry z pełnią zaangażowania. Sy...\n",
" ... \n",
"5442 Biało-czerwona siła w Falun. Oni będą reprezen...\n",
"5443 Finał WTA Tokio na żywo: Woźniacka - Osaka LIV...\n",
"5444 Oni zapisali się w annałach. Hubert Hurkacz 15...\n",
"5445 Poprawia się stan Nikiego Laudy. Austriak może...\n",
"5446 Liga Mistrzów. Zabójcza końcówka Interu Mediol...\n",
"Length: 5447, dtype: object\n"
]
}
],
"source": [
"print(test)\n",
"\n",
"\n",
"\n",
"\n",
"print(Xtest)"
]
} }
], ],
"metadata": { "metadata": {

File diff suppressed because it is too large Load Diff

31
run.py
View File

@ -7,8 +7,16 @@ from sklearn.metrics import accuracy_score
df = pd.read_csv("train/train.tsv", sep="\t", header=None, error_bad_lines=False) df = pd.read_csv("train/train.tsv", sep="\t", header=None, error_bad_lines=False)
dev_x = pd.read_csv("dev-0/in.tsv", sep="\t", header=None, error_bad_lines=False) dev_x = pd.read_csv("dev-0/in.tsv", sep="\t", header=None, error_bad_lines=False)
test_x = pd.read_csv("test-A/in.tsv", sep="\t", header=None, error_bad_lines=False)
with open('test-A/in.tsv', 'r', encoding='utf8') as file:
test = file.readlines()
test = pd.Series(test)
x = df[1] x = df[1]
y = df[0] y = df[0]
@ -17,17 +25,20 @@ model = make_pipeline(TfidfVectorizer(), MultinomialNB())
model.fit(x,y) model.fit(x,y)
pred_dev = model.predict(dev_x[0]) pred_dev = model.predict(dev_x[0])
pred_test = model.predict(test_x[0]) pred_dev = pd.Series(pred_dev)
with open('dev-0/out.tsv', 'wt') as file:
with open('dev-0/out.tsv', 'wt') as f:
for pred in pred_dev: for pred in pred_dev:
f.write(str(pred)+'\n') file.write(str(pred)+'\n')
pred_test = model.predict(test)
pred_test = pd.Series(pred_test)
pred_test = pred_test.astype('int')
with open('test-A/out.tsv', 'wt') as f: with open('test-A/out.tsv', 'wt') as file:
for pred in pred_test: for pred in pred_test:
f.write(str(pred)+'\n') file.write(str(pred)+'\n')

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff