From cd6167f80a71c1bb42aa8a8e28559fdfe4399afc Mon Sep 17 00:00:00 2001 From: Carsten Date: Tue, 26 Jun 2018 23:05:27 +0200 Subject: [PATCH] merge prediction optimization --- Project/Tools/User_Interface.ipynb | 54 ++++++++++++++++++------------ 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/Project/Tools/User_Interface.ipynb b/Project/Tools/User_Interface.ipynb index 42edc2b..05efedc 100644 --- a/Project/Tools/User_Interface.ipynb +++ b/Project/Tools/User_Interface.ipynb @@ -139,7 +139,9 @@ { "cell_type": "code", "execution_count": 5, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "#sys.path.append(\"..\")\n", @@ -151,7 +153,9 @@ { "cell_type": "code", "execution_count": 6, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "tmp_dict = clf_naive.prepareData()" @@ -167,8 +171,10 @@ }, { "cell_type": "code", - "execution_count": 25, - "metadata": {}, + "execution_count": 7, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "def merged_prediction(msg , split = 0.5 , number = 8, target_emojis = top_emojis):\n", @@ -178,10 +184,23 @@ " 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", + " prediction_naive , prediction_naive_values = clf_naive.predict(sentence = msg, lookup= tmp_dict, n = number_naive)\n", + "\n", + " #filter 0 values\n", + " tmp1 = []\n", + " tmp2 = []\n", + " epsilon = 0.0001\n", + "\n", + " for i in range(len(prediction_naive)):\n", + " if(abs(prediction_naive_values[i]) > epsilon):\n", + " tmp1.append(prediction_naive[i])\n", + " tmp2.append(prediction_naive[i])\n", + "\n", + " prediction_naive = tmp1\n", + " prediction_naive_values = tmp2\n", " \n", " if(len(prediction_naive) < number_naive):\n", - " print(\"only few matches\")\n", + " #print(\"only few matches\")\n", " number_advanced = number - len(prediction_naive)\n", " \n", " #print(number, number_advanced, number_naive)\n", @@ -222,10 +241,11 @@ " #p = ed.sentiment_vector_to_emoji(sent,n_results = 8, custom_target_emojis=top_emojis)\n", " \n", " #merged prediction\n", - " p = merged_prediction(msg = current_message, target_emojis=top_emojis)\n", - " \n", - " predictions = p\n", - " update_descriptions()" + " if(current_message != \"\"):\n", + " p = merged_prediction(msg = current_message, target_emojis=top_emojis)\n", + "\n", + " predictions = p\n", + " update_descriptions()" ] }, { @@ -527,13 +547,13 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "9b6fd63901c84db9a5a2d10399053cb3", + "model_id": "3b8a6a311c1e4a1bb2b711d59246577a", "version_major": 2, "version_minor": 0 }, @@ -543,16 +563,6 @@ }, "metadata": {}, "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": [