My solution

This commit is contained in:
korne 2022-05-11 20:22:28 +02:00
parent bad68dfb59
commit 0adf4ab778
11 changed files with 125926 additions and 0 deletions

View File

@ -0,0 +1,116 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "835530c2-0129-4b5f-a41c-f1870ca1307f",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sklearn\n",
"import pandas as pd\n",
"from sklearn.metrics import accuracy_score\n",
"from gzip import open as open_gz\n",
"from sklearn.feature_extraction.text import TfidfVectorizer\n",
"from sklearn.naive_bayes import MultinomialNB\n",
"from sklearn.pipeline import make_pipeline"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "5db73671-80b9-4099-85a0-08ecf77250d1",
"metadata": {},
"outputs": [],
"source": [
"def evaluation(x, path_out, model):\n",
" results = model.predict(x)\n",
"\n",
" with open(path_out, 'wt') as file:\n",
" for r in results:\n",
" file.write(str(r) + '\\n')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2120f43e-d587-4481-a04c-dea9520cecec",
"metadata": {},
"outputs": [],
"source": [
"train = pd.read_csv('train/train.tsv', header = None, sep = '\\t', error_bad_lines = False)\n",
"\n",
"x_train = train[1]\n",
"y_train = train[0]\n",
"x_dev = pd.read_csv('dev-0/in.tsv',header = None, sep = '/t',engine = 'python')\n",
"x_dev = x_dev[0]\n",
"x_test = pd.read_csv('test-A/in.tsv',header = None, sep = '/t',engine = 'python')\n",
"x_test = x_test[0]"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "cdfefa84-e535-48e8-844a-10e24b2a3555",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Pipeline(steps=[('tfidfvectorizer', TfidfVectorizer()),\n",
" ('multinomialnb', MultinomialNB())])"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model = make_pipeline(TfidfVectorizer(), MultinomialNB())\n",
"model.fit(x_train, y_train)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "e1b7fe0c-a21a-42cf-8cd4-46ee932d5282",
"metadata": {},
"outputs": [],
"source": [
"evaluation(x_dev,'dev-0/out.tsv', model)\n",
"evaluation(x_test,'test-A/out.tsv', model)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7a269ea0-eefd-4907-bf65-9bb53ad296b7",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

5452
dev-0/out.tsv Normal file

File diff suppressed because it is too large Load Diff

116
run.ipynb Normal file
View File

@ -0,0 +1,116 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "835530c2-0129-4b5f-a41c-f1870ca1307f",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sklearn\n",
"import pandas as pd\n",
"from sklearn.metrics import accuracy_score\n",
"from gzip import open as open_gz\n",
"from sklearn.feature_extraction.text import TfidfVectorizer\n",
"from sklearn.naive_bayes import MultinomialNB\n",
"from sklearn.pipeline import make_pipeline"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "5db73671-80b9-4099-85a0-08ecf77250d1",
"metadata": {},
"outputs": [],
"source": [
"def evaluation(x, path_out, model):\n",
" results = model.predict(x)\n",
"\n",
" with open(path_out, 'wt') as file:\n",
" for r in results:\n",
" file.write(str(r) + '\\n')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2120f43e-d587-4481-a04c-dea9520cecec",
"metadata": {},
"outputs": [],
"source": [
"train = pd.read_csv('train/train.tsv', header = None, sep = '\\t', error_bad_lines = False)\n",
"\n",
"x_train = train[1]\n",
"y_train = train[0]\n",
"x_dev = pd.read_csv('dev-0/in.tsv',header = None, sep = '/t',engine = 'python')\n",
"x_dev = x_dev[0]\n",
"x_test = pd.read_csv('test-A/in.tsv',header = None, sep = '/t',engine = 'python')\n",
"x_test = x_test[0]"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "cdfefa84-e535-48e8-844a-10e24b2a3555",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Pipeline(steps=[('tfidfvectorizer', TfidfVectorizer()),\n",
" ('multinomialnb', MultinomialNB())])"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model = make_pipeline(TfidfVectorizer(), MultinomialNB())\n",
"model.fit(x_train, y_train)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "e1b7fe0c-a21a-42cf-8cd4-46ee932d5282",
"metadata": {},
"outputs": [],
"source": [
"evaluation(x_dev,'dev-0/out.tsv', model)\n",
"evaluation(x_test,'test-A/out.tsv', model)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7a269ea0-eefd-4907-bf65-9bb53ad296b7",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

File diff suppressed because it is too large Load Diff

5447
test-A/out.tsv Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
0 1
1 1
2 0
3 1
4 0
..
19995 0
19996 0
19997 1
19998 0
19999 0
Name: y, Length: 20000, dtype: object
1 0 1
2 1 1
3 2 0
4 3 1
5 4 0
6 ..
7 19995 0
8 19996 0
9 19997 1
10 19998 0
11 19999 0
12 Name: y, Length: 20000, dtype: object

12
train/expected.tsv Normal file
View File

@ -0,0 +1,12 @@
0 1
1 1
2 0
3 1
4 0
..
19995 0
19996 0
19997 1
19998 0
19999 0
Name: y, Length: 20000, dtype: object
1 0 1
2 1 1
3 2 0
4 3 1
5 4 0
6 ..
7 19995 0
8 19996 0
9 19997 1
10 19998 0
11 19999 0
12 Name: y, Length: 20000, dtype: object

288
train/in.tsv Normal file

File diff suppressed because one or more lines are too long

98132
train/train.tsv Normal file

File diff suppressed because it is too large Load Diff