{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Lets track the Public LB Standings\n## For the Recursion Cellular Image Classification\n\n[Shamelessly stolen](https://www.kaggle.com/robikscube/the-race-to-predict-molecular-properties) from @robikscube\n\n# All credits go to @robikscube.\n\nI really liked his presentation style. Since he is not in this competition, I am blatantly stealing his code. "},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport matplotlib.pylab as plt\nimport plotly\nimport plotly.graph_objs as go\nfrom plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot\nfrom sklearn.linear_model import LinearRegression\nimport datetime\nimport colorlover as cl\nplt.style.use('ggplot')\ncolor_pal = [x['color'] for x in plt.rcParams['axes.prop_cycle']]\n\n# Format the dataa\ndf = pd.read_csv('../input/recursion-public-leaderboard/recursion-cellular-image-classification-publicleaderboard.csv')\ndf['SubmissionDate'] = pd.to_datetime(df['SubmissionDate'])\ndf = df.set_index(['TeamName','SubmissionDate'])['Score'].unstack(-1).T\ndf.columns = [name for name in df.columns]\n\nFIFTEENTH_SCORE = df.max().sort_values(ascending=False)[15]\nFIFTYTH_SCORE = df.max().sort_values(ascending=False)[50]\nTOP_SCORE = df.max().sort_values(ascending=False)[0]","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Public LB Scores of Top Teams over time"},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"# Interative Plotly\nmypal = cl.scales['9']['div']['Spectral']\ncolors = cl.interp( mypal, 15 )\nannotations = []\ninit_notebook_mode(connected=True)\nTOP_TEAMS = df.min().loc[df.max() > FIFTEENTH_SCORE].index.values\ndf_filtered = df[TOP_TEAMS].ffill()\nteam_ordered = df_filtered.loc[df_filtered.index.max()] \\\n    .sort_values(ascending=False).index.tolist()\n\ndata = []\ni = 0\nfor col in df_filtered[team_ordered].columns:\n    data.append(go.Scatter(\n                        x = df_filtered.index,\n                        y = df_filtered[col],\n                        name=col,\n                        line=dict(color=colors[i], width=2),)\n               )\n    i += 1\n\nannotations.append(dict(xref='paper', yref='paper', x=0.0, y=1.05,\n                              xanchor='left', yanchor='bottom',\n                              text='Recursion Leaderboard Tracking',\n                              font=dict(family='Arial',\n                                        size=30,\n                                        color='rgb(37,37,37)'),\n                              showarrow=False))\n\nlayout = go.Layout(yaxis=dict(range=[0, TOP_SCORE+0.1]),\n                   hovermode='x',\n                   plot_bgcolor='white',\n                  annotations=annotations,\n                  )\nfig = go.Figure(data=data, layout=layout)\nfig.update_layout(\n    legend=go.layout.Legend(\n        traceorder=\"normal\",\n        font=dict(\n            family=\"sans-serif\",\n            size=12,\n            color=\"black\"\n        ),\n        bgcolor=\"LightSteelBlue\",\n        bordercolor=\"Black\",\n        borderwidth=2,\n    )\n)\n\nfig.update_layout(legend_orientation=\"h\")\nfig.update_layout(template=\"plotly_white\")\n#fig.update_yaxes(showgrid=True, gridwidth=0.5, gridcolor='LightGrey')\nfig.update_xaxes(showgrid=False)\n\niplot(fig)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# All competitors LB Position over Time"},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"# Scores of top teams over time\nplt.rcParams[\"font.size\"] = \"12\"\nALL_TEAMS = df.columns.values\ndf[ALL_TEAMS].ffill().plot(figsize=(20, 10),\n                           color=color_pal[0],\n                           legend=False,\n                           alpha=0.05,\n                           ylim=(0, TOP_SCORE + 0.01),\n                           title='All Teams Public LB Scores over Time')\ndf.ffill().max(axis=1).plot(color=color_pal[1], label='1st Place Public LB', legend=True)\nplt.show()\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Number of teams by Date"},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"plt.rcParams[\"font.size\"] = \"12\"\nax =df.ffill() \\\n    .count(axis=1) \\\n    .plot(figsize=(20, 8),\n          title='Number of Teams in the Competition by Date',\n         color=color_pal[5], lw=5)\nax.set_ylabel('Number of Teams')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Top LB Scores\nLarger bar is better"},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"plt.rcParams[\"font.size\"] = \"12\"\n# Create Top Teams List\nTOP_TEAMS = df.max().loc[df.max() > FIFTYTH_SCORE].index.values\ndf[TOP_TEAMS].max().sort_values(ascending=True).plot(kind='barh',\n                                       xlim=(0.8,TOP_SCORE),\n                                       title='Top 50 Public LB Teams',\n                                       figsize=(12, 15),\n                                       color=color_pal[3])\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Distribution of Scores over time"},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"plt.rcParams[\"font.size\"] = \"7\"\nn_days = (datetime.date.today() - datetime.date(2019, 6, 27)).days # Num days of the comp\nfig, axes = plt.subplots(n_days, 1, figsize=(15, 10), sharex=True)\nplt.subplots_adjust(top=8, bottom=2)\nfor x in range(n_days):\n    date2 = df.loc[df.index.date == datetime.date(2019, 6, 27) + datetime.timedelta(x)].index.min()\n    num_teams = len(df.ffill().loc[date2].dropna())\n    max_cutoff = df.ffill().loc[date2] < 5\n    df.ffill().loc[date2].loc[max_cutoff].plot(kind='hist',\n                               bins=50,\n                               xlim=(0.0,1.0),\n                               ax=axes[x],\n                               title='{} ({} Teams)'.format(date2.date().isoformat(),\n                                                            num_teams))\n    y_axis = axes[x].yaxis\n    y_axis.set_label_text('')\n    y_axis.label.set_visible(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":1}