{"cells":[{"metadata":{},"cell_type":"markdown","source":"<div>\n    <h1 align=\"center\"> Comparative Method - Part(B)</h1></h1>\n    <h2 align=\"center\">Rainforest Connection Species Audio Detection</h2>\n    <h3 align=\"center\">By: Somayyeh Gholami & Mehran Kazeminia</h3>\n</div>"},{"metadata":{},"cell_type":"markdown","source":"<div class=\"alert alert-success\">  \n</div>"},{"metadata":{},"cell_type":"markdown","source":"# Description:"},{"metadata":{},"cell_type":"markdown","source":"### - In this notebook, we use the Comparative Method to improve the results of the previous notebook (Part A). The address of our previous notebook (Part A) is as follows:\n\nhttps://www.kaggle.com/mehrankazeminia/lb-0-980-rainforest-comparative-method-part-a\n\n### - Of course, to use the Comparative Method, we need another suitable notebook. We have used the following notebook for this purpose. Thanks also to Mr. [@vzaguskin](https://www.kaggle.com/vzaguskin) for sharing this great notebook.\n\nhttps://www.kaggle.com/vzaguskin/rfcx-complete-tpu-training-and-inference-lb-0-95\n\n### - In the end, we were able to easily improve the results once again with our own method. We saved the final results in the \"f\" file. The scores of the \"f\" file are as follows:\n\n### \"f\" : [(Private Score: 0.98415) , (Public Score: 0.97684)]\n"},{"metadata":{},"cell_type":"markdown","source":"<div class=\"alert alert-success\">  \n</div>"},{"metadata":{},"cell_type":"markdown","source":"## If you find this work useful, please don't forget upvoting :)"},{"metadata":{},"cell_type":"markdown","source":"<div class=\"alert alert-success\">  \n</div>"},{"metadata":{},"cell_type":"markdown","source":"# Import & Data Set"},{"metadata":{"trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd \nimport matplotlib.pyplot as plt\n\n%matplotlib inline\n\n# _______________________________\n\nsub974 = pd.read_csv(\"../input/lb-0-980-rainforest-comparative-method-part-a/submission.csv\") \n\nsub943 = pd.read_csv(\"../input/rain943/RAIN943.csv\") \n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div class=\"alert alert-success\">  \n</div>"},{"metadata":{},"cell_type":"markdown","source":"# Functions"},{"metadata":{"trusted":true},"cell_type":"code","source":"def generate(main, support, coeff):\n    g1 = main.copy()\n    g2 = main.copy()\n    g3 = main.copy()\n    g4 = main.copy()\n    \n    for i in main.columns[1:]:\n        lm, Is = [], []                \n        lm = main[i].tolist()\n        ls = support[i].tolist() \n        \n        res1, res2, res3, res4 = [], [], [], []          \n        for j in range(len(main)):\n            res1.append(max(lm[j] , ls[j]))\n            res2.append(min(lm[j] , ls[j]))\n            res3.append((lm[j] + ls[j]) / 2)\n            res4.append((lm[j] * coeff) + (ls[j] * (1.- coeff)))\n            \n        g1[i] = res1\n        g2[i] = res2\n        g3[i] = res3\n        g4[i] = res4\n        \n    return g1,g2,g3,g4","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def generate1(main, support, coeff):\n    \n    g = main.copy()    \n    for i in main.columns[1:]:\n        \n        res = []\n        lm, Is = [], []        \n        lm = main[i].tolist()\n        ls = support[i].tolist()  \n        \n        for j in range(len(main)):\n            res.append((lm[j] * coeff[i]) + (ls[j] * (1.- coeff[i])))            \n        g[i] = res\n        \n    return g","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def drawing(main, support, generated, column_number):\n    \n    X  = main.iloc[:, column_number]\n    Y1 = support.iloc[:, column_number]\n    Y2 = generated.iloc[:, column_number]\n    \n    plt.style.use('seaborn-whitegrid') \n    plt.figure(figsize=(8, 8), facecolor='lightgray')\n    plt.title(f'\\nOn the X axis >>> main\\n\\nOn the Y axis >>> support\\n')           \n    plt.scatter(X, Y1, s=3)\n    plt.show() \n    \n    plt.style.use('seaborn-whitegrid') \n    plt.figure(figsize=(8, 8), facecolor='lightgray')\n    plt.title(f'\\nOn the X axis >>> main\\n\\nOn the Y axis >>> generated\\n')           \n    plt.scatter(X, Y2, s=3)\n    plt.show()     ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def drawing1(main, support, generated, column_number):\n    \n    X  = main.iloc[:, column_number]\n    Y1 = support.iloc[:, column_number]\n    Y2 = generated.iloc[:, column_number]\n    \n    plt.style.use('seaborn-whitegrid') \n    plt.figure(figsize=(8, 8), facecolor='lightgray')\n    plt.title(f'\\nBlue | X axis >> main | Y axis >> support\\n\\nOrange | X axis >> main | Y axis >> generated\\n') \n    \n    plt.scatter(X, Y1, s=3)    \n    plt.scatter(X, Y2, s=3)\n    \n    plt.show()     ","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div class=\"alert alert-success\">  \n</div>"},{"metadata":{},"cell_type":"markdown","source":"# Comparative Method\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"# print(sub974.mean() , sub943.mean())\n\nm1 = sub974.mean() + sub943.mean()\n\nm1mean = m1.mean()\n\nm2 = m1 / m1mean\n\nm2","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"m3 = m2.copy()\nfor k in range(24):\n    m3[k] = 0.80\n\n# m3    ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"m4 = m3.copy()\n\nm4[2]   = 0.70\n\nm4[3]   = 0.70\n\nm4[17]  = 0.70\n\nm4[18]  = 1.00\n\nm4[20]  = 0.50\n\nm4[23]  = 0.70\n\nm4","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"f = generate1(sub974, sub943, m4)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub974.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub943.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 2)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 3)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 4)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 6)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 7)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 8)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 9)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 10)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 11)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 12)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 13)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 14)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 15)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 16)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 17)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 18)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 19)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 20)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 21)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 22)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 23)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"drawing1(sub974, sub943, f, 24)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Result\n\n## [(Score: 0.974) , (Score: 0.943)] >>> f\n\n## f : [(Private Score: 0.98415) , (Public Score: 0.97684)]"},{"metadata":{"trusted":true},"cell_type":"code","source":"f.describe()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div class=\"alert alert-success\">  \n</div>"},{"metadata":{},"cell_type":"markdown","source":"# Submission\n"},{"metadata":{"trusted":true},"cell_type":"code","source":"sub = f\nsub.to_csv(\"submission.csv\", index=False)\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div class=\"alert alert-success\">  \n</div>"}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}