simple improvements on tasks

This commit is contained in:
Jonas Weinz 2018-05-28 19:13:57 +02:00
parent 7e1af5ac2c
commit c055f72af7
3 changed files with 156 additions and 213 deletions

File diff suppressed because one or more lines are too long

View File

@ -2,9 +2,19 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/jonas/.local/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
" from ._conv import register_converters as _register_converters\n",
"Using TensorFlow backend.\n"
]
}
],
"source": [ "source": [
"import numpy as np \n", "import numpy as np \n",
"import pandas as pd \n", "import pandas as pd \n",
@ -18,9 +28,22 @@
"import re\n" "import re\n"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
">**Task 3**: playing with NN framwork/keras and basic sentiment analysis\n",
">- use the following model as a baseline and improve it!\n",
">- export your metadata (just basic hyperparameters and outcomes for test data!)\n",
">- test data = 0.3 (not in this example, change it!)\n",
">- random_state = 4222\n",
">- no need to cross-validation!\n",
"\n"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -65,7 +88,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -94,12 +117,12 @@
"df = df[df.sentiment != \"Neutral\"]\n", "df = df[df.sentiment != \"Neutral\"]\n",
"df['text'] = df['text'].apply(lambda x: x.lower())\n", "df['text'] = df['text'].apply(lambda x: x.lower())\n",
"df['text'] = df['text'].apply(lambda x: x.replace('rt',' '))\n", "df['text'] = df['text'].apply(lambda x: x.replace('rt',' '))\n",
"df['text'] = df['text'].apply((lambda x: re.sub('[^a-zA-z0-9\\s]','',x)))" "df['text'] = df['text'].apply((lambda x: re.sub('[^a-zA-Z0-9\\s]','',x)))"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 22,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -111,7 +134,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -121,13 +144,13 @@
"_________________________________________________________________\n", "_________________________________________________________________\n",
"Layer (type) Output Shape Param # \n", "Layer (type) Output Shape Param # \n",
"=================================================================\n", "=================================================================\n",
"embedding_1 (Embedding) (None, 26, 128) 64000 \n", "embedding_2 (Embedding) (None, 26, 128) 64000 \n",
"_________________________________________________________________\n", "_________________________________________________________________\n",
"spatial_dropout1d_1 (Spatial (None, 26, 128) 0 \n", "spatial_dropout1d_2 (Spatial (None, 26, 128) 0 \n",
"_________________________________________________________________\n", "_________________________________________________________________\n",
"lstm_1 (LSTM) (None, 196) 254800 \n", "lstm_2 (LSTM) (None, 196) 254800 \n",
"_________________________________________________________________\n", "_________________________________________________________________\n",
"dense_1 (Dense) (None, 2) 394 \n", "dense_2 (Dense) (None, 2) 394 \n",
"=================================================================\n", "=================================================================\n",
"Total params: 319,194\n", "Total params: 319,194\n",
"Trainable params: 319,194\n", "Trainable params: 319,194\n",
@ -157,15 +180,15 @@
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Epoch 1/2\n", "Epoch 1/2\n",
" - 30s - loss: 0.4374 - acc: 0.8161\n", " - 21s - loss: 0.4322 - acc: 0.8196\n",
"Epoch 2/2\n", "Epoch 2/2\n",
" - 30s - loss: 0.3614 - acc: 0.8487\n" " - 25s - loss: 0.3612 - acc: 0.8509\n"
] ]
}, },
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"<keras.callbacks.History at 0x7fe38072e978>" "<keras.callbacks.History at 0x7f0646b9e828>"
] ]
}, },
"execution_count": 7, "execution_count": 7,
@ -181,7 +204,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -189,7 +212,7 @@
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"score: 0.37\n", "score: 0.37\n",
"acc: 0.85\n" "acc: 0.84\n"
] ]
} }
], ],
@ -205,7 +228,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -221,15 +244,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"pos_acc 31.770833333333332 %\n", "pos_acc 39.58333333333333 %\n",
"neg_acc 97.27722772277228 %\n" "neg_acc 95.29702970297029 %\n"
] ]
} }
], ],
@ -240,7 +263,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -249,7 +272,7 @@
"text": [ "text": [
"[[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 37\n", "[[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 37\n",
" 311 189 4 144 22 16 1 281]]\n", " 311 189 4 144 22 16 1 281]]\n",
"[0.93431044 0.06568963]\n" "[0.8364928 0.16350722]\n"
] ]
} }
], ],

View File

@ -39,55 +39,55 @@ this:measure4 a mexcore:PerformanceMeasure ;
mexperf:recall "0.7680865449628127"^^xsd:float ; mexperf:recall "0.7680865449628127"^^xsd:float ;
prov:wasGeneratedBy this:conf4 . prov:wasGeneratedBy this:conf4 .
this:Dataset03 a mexcore:dataset ;
rdfs:label "Dataset03" .
this:conf1 a mexcore:ExperimentConfiguration ; this:conf1 a mexcore:ExperimentConfiguration ;
rdfs:label "configuration 1" ; rdfs:label "conf1" ;
prov:used this:ds1, prov:used this:Dataset01,
this:modela ; this:model_a ;
prov:wasStartedBy this:jonas_weinz_task_2 . prov:wasStartedBy this:jonas_weinz_task_2 .
this:conf2 a mexcore:ExperimentConfiguration ; this:conf2 a mexcore:ExperimentConfiguration ;
rdfs:label "configuration 2" ; rdfs:label "conf2" ;
prov:used this:ds2, prov:used this:Dataset02,
this:modelb ; this:model_b ;
prov:wasStartedBy this:jonas_weinz_task_2 . prov:wasStartedBy this:jonas_weinz_task_2 .
this:conf3a a mexcore:ExperimentConfiguration ; this:conf3a a mexcore:ExperimentConfiguration ;
rdfs:label "configuration 3a" ; rdfs:label "conf3a" ;
prov:used this:ds1, prov:used this:Dataset01,
this:modelb ; this:model_b ;
prov:wasStartedBy this:jonas_weinz_task_2 . prov:wasStartedBy this:jonas_weinz_task_2 .
this:conf3b a mexcore:ExperimentConfiguration ; this:conf3b a mexcore:ExperimentConfiguration ;
rdfs:label "configuration 3b" ; rdfs:label "conf3b" ;
prov:used this:ds2, prov:used this:Dataset02,
this:modela ; this:model_a ;
prov:wasStartedBy this:jonas_weinz_task_2 . prov:wasStartedBy this:jonas_weinz_task_2 .
this:conf4 a mexcore:ExperimentConfiguration ; this:conf4 a mexcore:ExperimentConfiguration ;
rdfs:label "configuration 4" ; rdfs:label "conf4" ;
prov:used this:ds3, prov:used this:Dataset03,
this:modelc ; this:model_c ;
prov:wasStartedBy this:jonas_weinz_task_2 . prov:wasStartedBy this:jonas_weinz_task_2 .
this:ds3 a mexcore:dataset ; this:model_c a mexalgo:Algorithm ;
rdfs:label "Dataset03" . rdfs:label "model_c" ;
this:modelc a mexalgo:Algorithm ;
rdfs:label "model c" ;
dct:identifier "MLPClassifier" . dct:identifier "MLPClassifier" .
this:ds1 a mexcore:dataset ; this:Dataset01 a mexcore:dataset ;
rdfs:label "Dataset01" . rdfs:label "Dataset01" .
this:ds2 a mexcore:dataset ; this:Dataset02 a mexcore:dataset ;
rdfs:label "Dataset02" . rdfs:label "Dataset02" .
this:modela a mexalgo:Algorithm ; this:model_a a mexalgo:Algorithm ;
rdfs:label "model a" ; rdfs:label "model_a" ;
dct:identifier "RandomForestClassifier" . dct:identifier "RandomForestClassifier" .
this:modelb a mexalgo:Algorithm ; this:model_b a mexalgo:Algorithm ;
rdfs:label "model b" ; rdfs:label "model_b" ;
dct:identifier "MLPClassifier" . dct:identifier "MLPClassifier" .
this:jonas_weinz_task_2 a mexcore:Experiment . this:jonas_weinz_task_2 a mexcore:Experiment .