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": [
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 1,
"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": [
"import numpy as np \n",
"import pandas as pd \n",
@ -18,9 +28,22 @@
"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",
"execution_count": 17,
"execution_count": 2,
"metadata": {},
"outputs": [
{
@ -65,7 +88,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 13,
"metadata": {},
"outputs": [
{
@ -94,12 +117,12 @@
"df = df[df.sentiment != \"Neutral\"]\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: 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",
"execution_count": 5,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
@ -111,7 +134,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 15,
"metadata": {},
"outputs": [
{
@ -121,13 +144,13 @@
"_________________________________________________________________\n",
"Layer (type) Output Shape Param # \n",
"=================================================================\n",
"embedding_1 (Embedding) (None, 26, 128) 64000 \n",
"embedding_2 (Embedding) (None, 26, 128) 64000 \n",
"_________________________________________________________________\n",
"spatial_dropout1d_1 (Spatial (None, 26, 128) 0 \n",
"spatial_dropout1d_2 (Spatial (None, 26, 128) 0 \n",
"_________________________________________________________________\n",
"lstm_1 (LSTM) (None, 196) 254800 \n",
"lstm_2 (LSTM) (None, 196) 254800 \n",
"_________________________________________________________________\n",
"dense_1 (Dense) (None, 2) 394 \n",
"dense_2 (Dense) (None, 2) 394 \n",
"=================================================================\n",
"Total params: 319,194\n",
"Trainable params: 319,194\n",
@ -157,15 +180,15 @@
"output_type": "stream",
"text": [
"Epoch 1/2\n",
" - 30s - loss: 0.4374 - acc: 0.8161\n",
" - 21s - loss: 0.4322 - acc: 0.8196\n",
"Epoch 2/2\n",
" - 30s - loss: 0.3614 - acc: 0.8487\n"
" - 25s - loss: 0.3612 - acc: 0.8509\n"
]
},
{
"data": {
"text/plain": [
"<keras.callbacks.History at 0x7fe38072e978>"
"<keras.callbacks.History at 0x7f0646b9e828>"
]
},
"execution_count": 7,
@ -181,7 +204,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"outputs": [
{
@ -189,7 +212,7 @@
"output_type": "stream",
"text": [
"score: 0.37\n",
"acc: 0.85\n"
"acc: 0.84\n"
]
}
],
@ -205,7 +228,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
@ -221,15 +244,15 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"pos_acc 31.770833333333332 %\n",
"neg_acc 97.27722772277228 %\n"
"pos_acc 39.58333333333333 %\n",
"neg_acc 95.29702970297029 %\n"
]
}
],
@ -240,7 +263,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 11,
"metadata": {},
"outputs": [
{
@ -249,7 +272,7 @@
"text": [
"[[ 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",
"[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 ;
prov:wasGeneratedBy this:conf4 .
this:Dataset03 a mexcore:dataset ;
rdfs:label "Dataset03" .
this:conf1 a mexcore:ExperimentConfiguration ;
rdfs:label "configuration 1" ;
prov:used this:ds1,
this:modela ;
rdfs:label "conf1" ;
prov:used this:Dataset01,
this:model_a ;
prov:wasStartedBy this:jonas_weinz_task_2 .
this:conf2 a mexcore:ExperimentConfiguration ;
rdfs:label "configuration 2" ;
prov:used this:ds2,
this:modelb ;
rdfs:label "conf2" ;
prov:used this:Dataset02,
this:model_b ;
prov:wasStartedBy this:jonas_weinz_task_2 .
this:conf3a a mexcore:ExperimentConfiguration ;
rdfs:label "configuration 3a" ;
prov:used this:ds1,
this:modelb ;
rdfs:label "conf3a" ;
prov:used this:Dataset01,
this:model_b ;
prov:wasStartedBy this:jonas_weinz_task_2 .
this:conf3b a mexcore:ExperimentConfiguration ;
rdfs:label "configuration 3b" ;
prov:used this:ds2,
this:modela ;
rdfs:label "conf3b" ;
prov:used this:Dataset02,
this:model_a ;
prov:wasStartedBy this:jonas_weinz_task_2 .
this:conf4 a mexcore:ExperimentConfiguration ;
rdfs:label "configuration 4" ;
prov:used this:ds3,
this:modelc ;
rdfs:label "conf4" ;
prov:used this:Dataset03,
this:model_c ;
prov:wasStartedBy this:jonas_weinz_task_2 .
this:ds3 a mexcore:dataset ;
rdfs:label "Dataset03" .
this:modelc a mexalgo:Algorithm ;
rdfs:label "model c" ;
this:model_c a mexalgo:Algorithm ;
rdfs:label "model_c" ;
dct:identifier "MLPClassifier" .
this:ds1 a mexcore:dataset ;
this:Dataset01 a mexcore:dataset ;
rdfs:label "Dataset01" .
this:ds2 a mexcore:dataset ;
this:Dataset02 a mexcore:dataset ;
rdfs:label "Dataset02" .
this:modela a mexalgo:Algorithm ;
rdfs:label "model a" ;
this:model_a a mexalgo:Algorithm ;
rdfs:label "model_a" ;
dct:identifier "RandomForestClassifier" .
this:modelb a mexalgo:Algorithm ;
rdfs:label "model b" ;
this:model_b a mexalgo:Algorithm ;
rdfs:label "model_b" ;
dct:identifier "MLPClassifier" .
this:jonas_weinz_task_2 a mexcore:Experiment .