Skip to content

Instantly share code, notes, and snippets.

@g-leech
Last active June 25, 2022 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g-leech/cd151192e03ea453657a6c8cacd939e3 to your computer and use it in GitHub Desktop.
Save g-leech/cd151192e03ea453657a6c8cacd939e3 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "ColdTakesTables.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"id": "3IU1XcPdplRI"
},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"source": [
"asimov_url = \"https://docs.google.com/spreadsheets/d/e/2PACX-1vT6xk8FVWbA1U-0YRzTLf4FuBE2wo_WbOmN5m5LN4INELxe15BcAtL3slo7vRVCuvRTYReE2ZG92XUe/pub?gid=0&single=true&output=csv\"\n",
"clarke_url = \"https://docs.google.com/spreadsheets/d/e/2PACX-1vTQHFjeHPN-vnR8Ggmy8u8yJAYSJ4RO22QsNE0HZhjAyIwx6VNZ1qFM1wIVl9fxCTvQ5WNzLcRbN-j7/pub?gid=0&single=true&output=csv\"\n",
"heinlein_url = \"https://docs.google.com/spreadsheets/d/e/2PACX-1vRq-qcyqdbG-krcZmUXgpZLadDkpOSGjnqFGrp80pyk2kvdSR_2N5WTYcboksmuwhJsB_xxXX4pBZ6x/pub?gid=0&single=true&output=csv\""
],
"metadata": {
"id": "ScEukCznpt-f"
},
"execution_count": 14,
"outputs": []
},
{
"cell_type": "code",
"source": [
"asimov_df = pd.read_csv(asimov_url)\n",
"clarke_df = pd.read_csv(clarke_url)\n",
"heinlein_df = pd.read_csv(heinlein_url)"
],
"metadata": {
"id": "jBCQEaG7qFsU"
},
"execution_count": 15,
"outputs": []
},
{
"cell_type": "code",
"source": [
"asimov_table = {}\n",
"\n",
"asimov = asimov_df[asimov_df[\"Resolved\"] == 1]\n",
"asimov = asimov[asimov[\"Years out\"] >= 30]\n",
"\n",
"asimov_counts = asimov[\"Correctness\"].value_counts()\n",
"asimov_table[\"All predictions\"] = {\n",
" \"# correct\": asimov_counts[2],\n",
" \"# incorrect\": asimov_counts[0],\n",
" \"# ambiguous/near-miss\": asimov_counts[1],\n",
" \"correct / (correct + incorrect)\": round(asimov_counts[2] / (asimov_counts[2] + asimov_counts[0]), 2)\n",
"}\n",
"\n",
"\n",
"asimov_tech = asimov[asimov[\"Category\"] == \"Tech\"]\n",
"asimov_counts = asimov_tech[\"Correctness\"].value_counts()\n",
"asimov_table[\"Tech predictions\"] = {\n",
" \"# correct\": asimov_counts[2],\n",
" \"# incorrect\": asimov_counts[0],\n",
" \"# ambiguous/near-miss\": asimov_counts[1],\n",
" \"correct / (correct + incorrect)\": round(asimov_counts[2] / (asimov_counts[2] + asimov_counts[0]), 2)\n",
"}\n",
"\n",
"\n",
"asimov_hard = asimov[asimov[\"Difficulty\"] >= 4]\n",
"asimov_counts = asimov_hard[\"Correctness\"].value_counts()\n",
"asimov_table[\"Difficult predictions\"] = {\n",
" \"# correct\": asimov_counts[2],\n",
" \"# incorrect\": asimov_counts[0],\n",
" \"# ambiguous/near-miss\": asimov_counts[1],\n",
" \"correct / (correct + incorrect)\": round(asimov_counts[2] / (asimov_counts[2] + asimov_counts[0]), 2)\n",
"}\n",
"\n",
"asimov_hardtech = asimov_tech[asimov_tech[\"Difficulty\"] >= 4]\n",
"asimov_counts = asimov_hardtech[\"Correctness\"].value_counts()\n",
"asimov_table[\"Difficult tech predictions\"] = {\n",
" \"# correct\": asimov_counts[2],\n",
" \"# incorrect\": asimov_counts[0],\n",
" \"# ambiguous/near-miss\": asimov_counts[1],\n",
" \"correct / (correct + incorrect)\": round(asimov_counts[2] / (asimov_counts[2] + asimov_counts[0]), 2)\n",
"}\n",
"\n",
"\n",
"asimov_strict = asimov_hardtech[~asimov_hardtech[\"Target Year\"].isna()] # Definite year: Target Year is not Nan\n",
"asimov_counts = asimov_strict[\"Correctness\"].value_counts()\n",
"asimov_table[\"Difficult + tech + definite date\"] = {\n",
" \"# correct\": asimov_counts[2],\n",
" \"# incorrect\": asimov_counts[0],\n",
" \"# ambiguous/near-miss\": asimov_counts[1],\n",
" \"correct / (correct + incorrect)\": round(asimov_counts[2] / (asimov_counts[2] + asimov_counts[0]), 2)\n",
"}\n",
"\n",
"pd.DataFrame.from_dict(asimov_table).transpose()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 302
},
"id": "vtl21xx9sATr",
"outputId": "376edb23-32a3-437f-bd3a-53a60aa2e54c"
},
"execution_count": 16,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" # correct # incorrect \\\n",
"All predictions 23.0 29.0 \n",
"Tech predictions 11.0 4.0 \n",
"Difficult predictions 10.0 11.0 \n",
"Difficult tech predictions 5.0 1.0 \n",
"Difficult + tech + definite date 5.0 1.0 \n",
"\n",
" # ambiguous/near-miss \\\n",
"All predictions 14.0 \n",
"Tech predictions 8.0 \n",
"Difficult predictions 7.0 \n",
"Difficult tech predictions 4.0 \n",
"Difficult + tech + definite date 4.0 \n",
"\n",
" correct / (correct + incorrect) \n",
"All predictions 0.44 \n",
"Tech predictions 0.73 \n",
"Difficult predictions 0.48 \n",
"Difficult tech predictions 0.83 \n",
"Difficult + tech + definite date 0.83 "
],
"text/html": [
"\n",
" <div id=\"df-a711ba5f-4925-43cc-b62e-c2de6930f220\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th># correct</th>\n",
" <th># incorrect</th>\n",
" <th># ambiguous/near-miss</th>\n",
" <th>correct / (correct + incorrect)</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>All predictions</th>\n",
" <td>23.0</td>\n",
" <td>29.0</td>\n",
" <td>14.0</td>\n",
" <td>0.44</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Tech predictions</th>\n",
" <td>11.0</td>\n",
" <td>4.0</td>\n",
" <td>8.0</td>\n",
" <td>0.73</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Difficult predictions</th>\n",
" <td>10.0</td>\n",
" <td>11.0</td>\n",
" <td>7.0</td>\n",
" <td>0.48</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Difficult tech predictions</th>\n",
" <td>5.0</td>\n",
" <td>1.0</td>\n",
" <td>4.0</td>\n",
" <td>0.83</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Difficult + tech + definite date</th>\n",
" <td>5.0</td>\n",
" <td>1.0</td>\n",
" <td>4.0</td>\n",
" <td>0.83</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-a711ba5f-4925-43cc-b62e-c2de6930f220')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-a711ba5f-4925-43cc-b62e-c2de6930f220 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-a711ba5f-4925-43cc-b62e-c2de6930f220');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 16
}
]
},
{
"cell_type": "code",
"source": [
"clarke_table = {}\n",
"\n",
"clarke = clarke_df[clarke_df[\"Resolved\"] == 1]\n",
"clarke = clarke[clarke[\"Years out\"] >= 30]\n",
"\n",
"clarke_counts = clarke[\"Correctness\"].value_counts()\n",
"clarke_table[\"All predictions\"] = {\n",
" \"# correct\": clarke_counts[2],\n",
" \"# incorrect\": clarke_counts[0],\n",
" \"# ambiguous/near-miss\": clarke_counts[1],\n",
" \"correct / (correct + incorrect)\": round(clarke_counts[2] / (clarke_counts[2] + clarke_counts[0]), 2)\n",
"}\n",
"\n",
"\n",
"clarke_tech = clarke[clarke[\"Category\"] == \"Tech\"]\n",
"clarke_counts = clarke_tech[\"Correctness\"].value_counts()\n",
"clarke_table[\"Tech predictions\"] = {\n",
" \"# correct\": clarke_counts[2],\n",
" \"# incorrect\": clarke_counts[0],\n",
" \"# ambiguous/near-miss\": clarke_counts[1],\n",
" \"correct / (correct + incorrect)\": round(clarke_counts[2] / (clarke_counts[2] + clarke_counts[0]), 2)\n",
"}\n",
"\n",
"\n",
"clarke_hard = clarke[clarke[\"Difficulty\"] >= 4]\n",
"clarke_counts = clarke_hard[\"Correctness\"].value_counts()\n",
"clarke_table[\"Difficult predictions\"] = {\n",
" \"# correct\": clarke_counts[2],\n",
" \"# incorrect\": clarke_counts[0],\n",
" \"# ambiguous/near-miss\": clarke_counts[1],\n",
" \"correct / (correct + incorrect)\": round(clarke_counts[2] / (clarke_counts[2] + clarke_counts[0]), 2)\n",
"}\n",
"\n",
"clarke_hardtech = clarke_tech[clarke_tech[\"Difficulty\"] >= 4]\n",
"clarke_counts = clarke_hardtech[\"Correctness\"].value_counts()\n",
"clarke_table[\"Difficult tech predictions\"] = {\n",
" \"# correct\": clarke_counts[2],\n",
" \"# incorrect\": clarke_counts[0],\n",
" \"# ambiguous/near-miss\": clarke_counts[1],\n",
" \"correct / (correct + incorrect)\": round(clarke_counts[2] / (clarke_counts[2] + clarke_counts[0]), 2)\n",
"}\n",
"\n",
"\n",
"clarke_strict = clarke_hardtech[~clarke_hardtech[\"Target Year\"].isna()] # Definite year: Target Year is not Nan\n",
"clarke_counts = clarke_strict[\"Correctness\"].value_counts()\n",
"clarke_table[\"Difficult + tech + definite date\"] = {\n",
" \"# correct\": clarke_counts[2],\n",
" \"# incorrect\": clarke_counts[0],\n",
" \"# ambiguous/near-miss\": clarke_counts[1],\n",
" \"correct / (correct + incorrect)\": round(clarke_counts[2] / (clarke_counts[2] + clarke_counts[0]), 2)\n",
"}\n",
"\n",
"pd.DataFrame.from_dict(clarke_table).transpose()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 302
},
"id": "XgU-STSrxRwz",
"outputId": "dab94f9f-a551-4753-aa81-e674fbc5641d"
},
"execution_count": 17,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" # correct # incorrect \\\n",
"All predictions 129.0 148.0 \n",
"Tech predictions 85.0 82.0 \n",
"Difficult predictions 14.0 10.0 \n",
"Difficult tech predictions 10.0 6.0 \n",
"Difficult + tech + definite date 6.0 5.0 \n",
"\n",
" # ambiguous/near-miss \\\n",
"All predictions 48.0 \n",
"Tech predictions 29.0 \n",
"Difficult predictions 4.0 \n",
"Difficult tech predictions 2.0 \n",
"Difficult + tech + definite date 2.0 \n",
"\n",
" correct / (correct + incorrect) \n",
"All predictions 0.47 \n",
"Tech predictions 0.51 \n",
"Difficult predictions 0.58 \n",
"Difficult tech predictions 0.62 \n",
"Difficult + tech + definite date 0.55 "
],
"text/html": [
"\n",
" <div id=\"df-773ec3ac-a9e0-4b5f-8c02-24f48f92371b\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th># correct</th>\n",
" <th># incorrect</th>\n",
" <th># ambiguous/near-miss</th>\n",
" <th>correct / (correct + incorrect)</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>All predictions</th>\n",
" <td>129.0</td>\n",
" <td>148.0</td>\n",
" <td>48.0</td>\n",
" <td>0.47</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Tech predictions</th>\n",
" <td>85.0</td>\n",
" <td>82.0</td>\n",
" <td>29.0</td>\n",
" <td>0.51</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Difficult predictions</th>\n",
" <td>14.0</td>\n",
" <td>10.0</td>\n",
" <td>4.0</td>\n",
" <td>0.58</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Difficult tech predictions</th>\n",
" <td>10.0</td>\n",
" <td>6.0</td>\n",
" <td>2.0</td>\n",
" <td>0.62</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Difficult + tech + definite date</th>\n",
" <td>6.0</td>\n",
" <td>5.0</td>\n",
" <td>2.0</td>\n",
" <td>0.55</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-773ec3ac-a9e0-4b5f-8c02-24f48f92371b')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-773ec3ac-a9e0-4b5f-8c02-24f48f92371b button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-773ec3ac-a9e0-4b5f-8c02-24f48f92371b');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 17
}
]
},
{
"cell_type": "code",
"source": [
"heinlein_table = {}\n",
"\n",
"heinlein = heinlein_df[heinlein_df[\"Resolved\"] == 1]\n",
"heinlein = heinlein[heinlein[\"Years out\"] >= 30]\n",
"\n",
"heinlein_counts = heinlein[\"Correctness\"].value_counts()\n",
"heinlein_table[\"All predictions\"] = {\n",
" \"# correct\": heinlein_counts[2],\n",
" \"# incorrect\": heinlein_counts[0],\n",
" \"# ambiguous/near-miss\": heinlein_counts[1],\n",
" \"correct / (correct + incorrect)\": round(heinlein_counts[2] / (heinlein_counts[2] + heinlein_counts[0]), 2)\n",
"}\n",
"\n",
"\n",
"heinlein_tech = heinlein[heinlein[\"Category\"] == \"Tech\"]\n",
"heinlein_counts = heinlein_tech[\"Correctness\"].value_counts()\n",
"heinlein_table[\"Tech predictions\"] = {\n",
" \"# correct\": heinlein_counts[2],\n",
" \"# incorrect\": heinlein_counts[0],\n",
" \"# ambiguous/near-miss\": heinlein_counts[1],\n",
" \"correct / (correct + incorrect)\": round(heinlein_counts[2] / (heinlein_counts[2] + heinlein_counts[0]), 2)\n",
"}\n",
"\n",
"\n",
"heinlein_hard = heinlein[heinlein[\"Difficulty\"] >= 4]\n",
"heinlein_counts = heinlein_hard[\"Correctness\"].value_counts()\n",
"heinlein_table[\"Difficult predictions\"] = {\n",
" \"# correct\": heinlein_counts[2],\n",
" \"# incorrect\": heinlein_counts[0],\n",
" \"# ambiguous/near-miss\": heinlein_counts[1],\n",
" \"correct / (correct + incorrect)\": round(heinlein_counts[2] / (heinlein_counts[2] + heinlein_counts[0]), 2)\n",
"}\n",
"\n",
"heinlein_hardtech = heinlein_tech[heinlein_tech[\"Difficulty\"] >= 4]\n",
"heinlein_counts = heinlein_hardtech[\"Correctness\"].value_counts()\n",
"heinlein_table[\"Difficult tech predictions\"] = {\n",
" \"# correct\": heinlein_counts[2],\n",
" \"# incorrect\": heinlein_counts[0],\n",
" \"# ambiguous/near-miss\": heinlein_counts[1],\n",
" \"correct / (correct + incorrect)\": round(heinlein_counts[2] / (heinlein_counts[2] + heinlein_counts[0]), 2)\n",
"}\n",
"\n",
"\n",
"heinlein_strict = heinlein_hardtech[~heinlein_hardtech[\"Target Year\"].isna()] # Definite year: Target Year is not Nan\n",
"heinlein_counts = heinlein_strict[\"Correctness\"].value_counts()\n",
"heinlein_table[\"Difficult + tech + definite date\"] = {\n",
" \"# correct\": heinlein_counts.get(2, default=0),\n",
" \"# incorrect\": heinlein_counts[0],\n",
" \"# ambiguous/near-miss\": heinlein_counts[1],\n",
" \"correct / (correct + incorrect)\": round(heinlein_counts.get(2, default=0) / \n",
" (heinlein_counts.get(2, default=0) + heinlein_counts[0]), 2)\n",
"}\n",
"\n",
"pd.DataFrame.from_dict(heinlein_table).transpose()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 302
},
"id": "06ijKq9LtehL",
"outputId": "9fcdb968-4fdb-44ec-d994-2c2ab8e69a72"
},
"execution_count": 18,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" # correct # incorrect \\\n",
"All predictions 19.0 41.0 \n",
"Tech predictions 14.0 20.0 \n",
"Difficult predictions 1.0 16.0 \n",
"Difficult tech predictions 1.0 9.0 \n",
"Difficult + tech + definite date 0.0 1.0 \n",
"\n",
" # ambiguous/near-miss \\\n",
"All predictions 7.0 \n",
"Tech predictions 6.0 \n",
"Difficult predictions 1.0 \n",
"Difficult tech predictions 1.0 \n",
"Difficult + tech + definite date 1.0 \n",
"\n",
" correct / (correct + incorrect) \n",
"All predictions 0.32 \n",
"Tech predictions 0.41 \n",
"Difficult predictions 0.06 \n",
"Difficult tech predictions 0.10 \n",
"Difficult + tech + definite date 0.00 "
],
"text/html": [
"\n",
" <div id=\"df-aaee1fdf-0899-48e3-b08a-8d92720b9cba\">\n",
" <div class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th># correct</th>\n",
" <th># incorrect</th>\n",
" <th># ambiguous/near-miss</th>\n",
" <th>correct / (correct + incorrect)</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>All predictions</th>\n",
" <td>19.0</td>\n",
" <td>41.0</td>\n",
" <td>7.0</td>\n",
" <td>0.32</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Tech predictions</th>\n",
" <td>14.0</td>\n",
" <td>20.0</td>\n",
" <td>6.0</td>\n",
" <td>0.41</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Difficult predictions</th>\n",
" <td>1.0</td>\n",
" <td>16.0</td>\n",
" <td>1.0</td>\n",
" <td>0.06</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Difficult tech predictions</th>\n",
" <td>1.0</td>\n",
" <td>9.0</td>\n",
" <td>1.0</td>\n",
" <td>0.10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Difficult + tech + definite date</th>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>0.00</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-aaee1fdf-0899-48e3-b08a-8d92720b9cba')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
" \n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-aaee1fdf-0899-48e3-b08a-8d92720b9cba button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-aaee1fdf-0899-48e3-b08a-8d92720b9cba');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 18
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment