Skip to content
Snippets Groups Projects
Analysis_07MAY2019_new.ipynb 173 KiB
Newer Older
  • Learn to ignore specific revisions
  • Riku-Laine's avatar
    Riku-Laine committed
        "\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "        #released = cdf(s_test.X, s_logreg, 0) < r/10\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "        s_f_rate_caus[i] = np.mean(s_test.B_prob_0_logreg * released)\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "\n",
        "        ########################\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "        #percentiles = estimatePercentiles(s_train_labeled.X, s_logreg)\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "        #def releaseProbability(x):\n",
        "        #    return calcReleaseProbabilities(r * 10,\n",
        "        #                                     s_train_labeled.X,\n",
        "        #                                     x,\n",
        "        #                                     s_logreg,\n",
        "        #                                     percentileMatrix=percentiles)\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "        #def integrand(x):\n",
        "        #    p_y0 = s_logreg.predict_proba(x.reshape(-1, 1))[:, 0]\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "        #    p_t1 = releaseProbability(x)\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "        #    p_x = scs.norm.pdf(x)\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "        #    return p_y0 * p_t1 * p_x\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "        #s_f_rate_caus[i] = si.quad(lambda x: integrand(np.ones((1, 1)) * x),\n",
        "        #                           -10, 10)[0]\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "\n",
    
        "    f_rates[r - 1, 0] = np.mean(s_f_rate_true)\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "    f_rates[r - 1, 1] = np.mean(s_f_rate_labeled)\n",
    
        "    f_rates[r - 1, 2] = np.mean(s_f_rate_human)\n",
        "    f_rates[r - 1, 3] = np.mean(s_f_rate_cont)\n",
        "    f_rates[r - 1, 4] = np.mean(s_f_rate_caus)\n",
        "\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "    f_sems[r - 1, 0] = scs.sem(s_f_rate_true)\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "    f_sems[r - 1, 1] = scs.sem(s_f_rate_labeled)\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "    f_sems[r - 1, 2] = scs.sem(s_f_rate_human)\n",
        "    f_sems[r - 1, 3] = scs.sem(s_f_rate_cont)\n",
        "    f_sems[r - 1, 4] = scs.sem(s_f_rate_caus)\n",
    
        "\n",
        "x_ax = np.arange(0.1, 0.9, 0.1)\n",
        "\n",
        "plt.figure(figsize=(14, 8))\n",
        "plt.errorbar(x_ax,\n",
        "             f_rates[:, 0],\n",
        "             label='True Evaluation',\n",
        "             c='green',\n",
        "             yerr=f_sems[:, 0])\n",
        "plt.errorbar(x_ax,\n",
    
        "             f_rates[:, 1],\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "             label='Labeled outcomes',\n",
    
        "             c='magenta',\n",
    
        "             yerr=f_sems[:, 1])\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "plt.errorbar(x_ax,\n",
    
        "             f_rates[:, 2],\n",
        "             label='Human evaluation',\n",
        "             c='red',\n",
        "             yerr=f_sems[:, 2])\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "plt.errorbar(x_ax,\n",
        "             f_rates[:, 3],\n",
        "             label='Contraction, log.',\n",
        "             c='blue',\n",
        "             yerr=f_sems[:, 3])\n",
        "plt.errorbar(x_ax,\n",
        "             f_rates[:, 4],\n",
        "             label='Causal model, ep',\n",
    
        "             c='black',\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "             yerr=f_sems[:, 4])\n",
        "\n",
        "plt.title('Failure rate vs. Acceptance rate without unobservables')\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "plt.xlabel('Acceptance rate')\n",
        "plt.ylabel('Failure rate')\n",
        "plt.legend()\n",
        "plt.grid()\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "plt.show()\n",
    
        "\n",
    
    Riku-Laine's avatar
    Riku-Laine committed
        "print(f_rates)\n",
        "print(\"\\nMean absolute errors:\")\n",
        "for i in range(1, f_rates.shape[1]):\n",
        "    print(np.mean(np.abs(f_rates[:, 0] - f_rates[:, i])))"
    
    Riku-Laine's avatar
    Riku-Laine committed
       ]
    
    Riku-Laine's avatar
    Riku-Laine committed
      }
     ],
     "metadata": {
      "kernelspec": {
       "display_name": "Python 3",
       "language": "python",
       "name": "python3"
      },
      "language_info": {
       "codemirror_mode": {
        "name": "ipython",
        "version": 3
       },
       "file_extension": ".py",
       "mimetype": "text/x-python",
       "name": "python",
       "nbconvert_exporter": "python",
       "pygments_lexer": "ipython3",
    
    Riku-Laine's avatar
    Riku-Laine committed
       "version": "3.7.3"
    
    Riku-Laine's avatar
    Riku-Laine committed
      },
      "toc": {
       "base_numbering": 1,
       "nav_menu": {},
       "number_sections": true,
       "sideBar": true,
       "skip_h1_title": true,
       "title_cell": "Table of Contents",
       "title_sidebar": "Contents",
       "toc_cell": true,
    
    Riku-Laine's avatar
    Riku-Laine committed
       "toc_position": {
        "height": "calc(100% - 180px)",
        "left": "10px",
        "top": "150px",
        "width": "300.7px"
       },
    
    Riku-Laine's avatar
    Riku-Laine committed
       "toc_section_display": true,
    
    Riku-Laine's avatar
    Riku-Laine committed
       "toc_window_display": true
    
    Riku-Laine's avatar
    Riku-Laine committed
      },
      "varInspector": {
       "cols": {
        "lenName": 16,
        "lenType": 16,
        "lenVar": 40
       },
       "kernels_config": {
        "python": {
         "delete_cmd_postfix": "",
         "delete_cmd_prefix": "del ",
         "library": "var_list.py",
         "varRefreshCmd": "print(var_dic_list())"
        },
        "r": {
         "delete_cmd_postfix": ") ",
         "delete_cmd_prefix": "rm(",
         "library": "var_list.r",
         "varRefreshCmd": "cat(var_dic_list()) "
        }
       },
    
    Riku-Laine's avatar
    Riku-Laine committed
       "position": {
        "height": "352.85px",
        "left": "1070px",
        "right": "20px",
        "top": "120px",
        "width": "350px"
       },
    
    Riku-Laine's avatar
    Riku-Laine committed
       "types_to_exclude": [
        "module",
        "function",
        "builtin_function_or_method",
        "instance",
        "_Feature"
       ],
       "window_display": false
      }
     },
     "nbformat": 4,
     "nbformat_minor": 2
    }