{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Rainforest Post Process - Private LB 0.974!\nIn this notebook we demonstrate a post process for rainforest comp. We will use the output from the following notebook:\nhttps://www.kaggle.com/meaninglesslives/rfcx-minimal\nWe will increase it's private LB score from 0.964 to 0.974!\n\nTo learn more about this post process, read the discussion [here][1]\n\n[1]: https://www.kaggle.com/c/rfcx-species-audio-detection/discussion/220389"},{"metadata":{},"cell_type":"markdown","source":"# Post Process Parameters\nTo use the following post process, load your `submission.csv` file and first try `MODE=1`. Next try `MODE=2`. Next try `MODE=3`. If those three don't increase your LB, then try `MODE=1` with different `FUDGE` values. Try values 0.5, 1, and 3."},{"metadata":{"trusted":true},"cell_type":"code","source":"# USE MODE 1, 2, or 3\nMODE = 1\n\n# LOAD SUBMISSION\nimport pandas as pd, numpy as np\nFUDGE = 2.0\nFILE = '../input/rfcx-minimal/submission.csv'\ndf = pd.read_csv(FILE)\nfor k in range(24):\n    df.iloc[:,1+k] -= df.iloc[:,1+k].min()\n    df.iloc[:,1+k] /= df.iloc[:,1+k].max()\n\n# CONVERT PROBS TO ODDS, APPLY MULTIPLIER, CONVERT BACK TO PROBS\ndef scale(probs, factor):\n    probs = probs.copy()\n    idx = np.where(probs!=1)[0]\n    odds = factor * probs[idx] / (1-probs[idx])\n    probs[idx] =  odds/(1+odds)\n    return probs\n\n# TRAIN AND TEST MEANS\nd1 = df.iloc[:,1:].mean().values\nd2 = np.array([113,204,44,923,53,41,3,213,44,23,26,149,255,14,123,222,46,6,474,4,17,18,23,72])/1000.\n\nfor k in range(24):\n    if MODE==1: d = FUDGE\n    if MODE==2: d = d1[k]/(1-d1[k])\n    if MODE==3: s = d2[k] / d1[k]\n    else: s = (d2[k]/(1-d2[k]))/d\n    df.iloc[:,k+1] = scale(df.iloc[:,k+1].values,s)\n    \ndf.to_csv('submission_with_pp.csv',index=False)","execution_count":null,"outputs":[]}],"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}