optimization and fehler behebung

This commit is contained in:
Carsten 2018-06-26 16:29:04 +02:00
parent 160821b1e3
commit 753d28d725

View File

@ -139,12 +139,22 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 5,
"metadata": { "metadata": {},
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"#TODO" "#sys.path.append(\"..\")\n",
"#print(sys.path)\n",
"\n",
"import naive_approach.naive_approach as clf_naive"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"tmp_dict = clf_naive.prepareData()"
] ]
}, },
{ {
@ -157,25 +167,31 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 25,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"def merged_prediction(msg , split = 1 , number = 8, target_emojis = top_emojis):\n", "def merged_prediction(msg , split = 0.5 , number = 8, target_emojis = top_emojis):\n",
" \n", " \n",
" #calc ratio of prediction splitted between advanced aprroach and naive approach\n", " #calc ratio of prediction splitted between advanced aprroach and naive approach\n",
" number_advanced = round(split*number)\n", " number_advanced = round(split*number)\n",
" number_naive = round(1-split)*number\n", " number_naive = round((1-split)*number)\n",
" \n",
" #predict emojis with the naive approach\n",
" prediction_naive = clf_naive.predict(sentence = msg, lookup= tmp_dict, n = number_naive)\n",
" \n",
" if(len(prediction_naive) < number_naive):\n",
" print(\"only few matches\")\n",
" number_advanced = number - len(prediction_naive)\n",
" \n",
" #print(number, number_advanced, number_naive)\n",
" \n", " \n",
" #predict the advanced approach\n", " #predict the advanced approach\n",
" sentiment = clf_advanced.predict([msg])\n", " sentiment = clf_advanced.predict([msg])\n",
" prediction_advanced = ed.sentiment_vector_to_emoji(sentiment,n_results = number_advanced, custom_target_emojis=target_emojis)\n", " prediction_advanced = ed.sentiment_vector_to_emoji(sentiment,n_results = number_advanced, custom_target_emojis=target_emojis)\n",
" \n", " \n",
" #predict emojis with the naive approach\n",
" #prediction_naive = clf_naive.predict(msg, target_emojis)\n",
" \n",
" #concat both predictions\n", " #concat both predictions\n",
" prediction = prediction_advanced#.append(prediction_naive)\n", " prediction = list(prediction_advanced)+list(prediction_naive)\n",
" \n", " \n",
" return prediction[:number]" " return prediction[:number]"
] ]
@ -189,7 +205,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 8,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -222,7 +238,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 9,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -251,7 +267,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 10,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -262,7 +278,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23, "execution_count": 11,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -287,7 +303,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 12,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -295,7 +311,7 @@
"source": [ "source": [
"text_input.on_submit(submit_new_message)\n", "text_input.on_submit(submit_new_message)\n",
"\n", "\n",
"text_input.observe(lambda b: trigger_new_prediction(None, text_input.value))" "#text_input.observe(lambda b: trigger_new_prediction(None, text_input.value))"
] ]
}, },
{ {
@ -308,7 +324,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 13,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -329,7 +345,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 14,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -347,7 +363,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 15,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -365,7 +381,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 16,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -383,7 +399,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 17,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -401,7 +417,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 18,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -419,7 +435,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": 19,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -437,7 +453,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": 20,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -455,7 +471,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": 21,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -473,7 +489,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21, "execution_count": 22,
"metadata": { "metadata": {
"collapsed": true "collapsed": true
}, },
@ -511,13 +527,13 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": 24,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"application/vnd.jupyter.widget-view+json": { "application/vnd.jupyter.widget-view+json": {
"model_id": "dc2c580ed3224ae7b2582c7c039813dd", "model_id": "9b6fd63901c84db9a5a2d10399053cb3",
"version_major": 2, "version_major": 2,
"version_minor": 0 "version_minor": 0
}, },
@ -527,6 +543,16 @@
}, },
"metadata": {}, "metadata": {},
"output_type": "display_data" "output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"8 4 4\n",
"8 4 4\n",
"8 4 4\n",
"8 4 4\n"
]
} }
], ],
"source": [ "source": [
@ -537,6 +563,15 @@
"display(total_layout)" "display(total_layout)"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,