This commit is contained in:
s434695 2021-05-11 23:07:21 +02:00
parent 756ef4277a
commit f02d3abb2f
13 changed files with 310702 additions and 0 deletions

View File

@ -0,0 +1,110 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from sklearn.preprocessing import LabelEncoder\n",
"from sklearn.naive_bayes import MultinomialNB\n",
"from sklearn.pipeline import make_pipeline\n",
"from sklearn.feature_extraction.text import TfidfVectorizer"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"with open(\"train/in.tsv\") as f:\n",
" x_train = f.readlines()\n",
"\n",
"with open(\"train/expected.tsv\") as f:\n",
" y_train = f.readlines()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 0, 0, ..., 0, 0, 1])"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y_train = LabelEncoder().fit_transform(y_train)\n",
"y_train"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"pipeline = make_pipeline(TfidfVectorizer(),MultinomialNB())"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"model = pipeline.fit(x_train, y_train)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"with open(\"dev-0/in.tsv\") as f:\n",
" x_dev = f.readlines()"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"prediction = model.predict(x_dev)\n",
"np.savetxt(\"dev-0/out.tsv\", prediction, fmt='%d')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

130
Bayes.ipynb Normal file
View File

@ -0,0 +1,130 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from sklearn.preprocessing import LabelEncoder\n",
"from sklearn.naive_bayes import MultinomialNB\n",
"from sklearn.pipeline import make_pipeline\n",
"from sklearn.feature_extraction.text import TfidfVectorizer"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"with open(\"train/in.tsv\") as f:\n",
" x_train = f.readlines()\n",
"\n",
"with open(\"train/expected.tsv\") as f:\n",
" y_train = f.readlines()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 0, 0, ..., 0, 0, 1])"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y_train = LabelEncoder().fit_transform(y_train)\n",
"y_train"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"pipeline = make_pipeline(TfidfVectorizer(),MultinomialNB())"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"model = pipeline.fit(x_train, y_train)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"with open(\"dev-0/in.tsv\") as f:\n",
" x_dev = f.readlines()"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"prediction = model.predict(x_dev)\n",
"np.savetxt(\"dev-0/out.tsv\", prediction, fmt='%d')"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"with open(\"test-A/in.tsv\") as f:\n",
" x_test = f.readlines()"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"prediction = model.predict(x_test)\n",
"np.savetxt(\"test-A/out.tsv\", prediction, fmt='%d')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

5272
dev-0/in.tsv Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

5272
dev-0/out.tsv Normal file

File diff suppressed because it is too large Load Diff

BIN
geval Executable file

Binary file not shown.

29
program.py Executable file
View File

@ -0,0 +1,29 @@
import numpy as np
from sklearn.preprocessing import LabelEncoder
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import make_pipeline
from sklearn.feature_extraction.text import TfidfVectorizer
with open("train/in.tsv") as f:
x_train = f.readlines()
with open("train/expected.tsv") as f:
y_train = f.readlines()
y_train = LabelEncoder().fit_transform(y_train)
pipeline = make_pipeline(TfidfVectorizer(),MultinomialNB())
model = pipeline.fit(x_train, y_train)
with open("dev-0/in.tsv") as f:
x_dev = f.readlines()
prediction = model.predict(x_dev)
np.savetxt("dev-0/out.tsv", prediction, fmt='%d')
with open("test-A/in.tsv") as f:
x_test = f.readlines()
prediction = model.predict(x_test)
np.savetxt("test-A/out.tsv", prediction, fmt='%d')

5152
test-A/in.tsv Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

5152
test-A/out.tsv Normal file

File diff suppressed because it is too large Load Diff

289579
train/in.tsv Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

6
wyniki.txt Normal file
View File

@ -0,0 +1,6 @@
Likelihood 0.0000
Accuracy 0.7367
F1.0 0.4367
Precision 0.8997
Recall 0.2883