gp-daw.ipynb 26.2 KB
Newer Older
rayfrancogrivera's avatar
rayfrancogrivera committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-30T07:26:28.998072Z",
     "start_time": "2019-12-30T07:25:11.297534Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<a href='http://localhost:9999' target='_blank'>Open in new tab</a>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "        <iframe\n",
       "            width=\"900\"\n",
       "            height=\"700\"\n",
       "            src=\"http://localhost:9999\"\n",
       "            frameborder=\"0\"\n",
       "            allowfullscreen\n",
       "        ></iframe>\n",
       "        "
      ],
      "text/plain": [
       "<IPython.lib.display.IFrame at 0x242072a2c18>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " * Serving Flask app \"__main__\" (lazy loading)\n",
      " * Environment: production\n",
      "   WARNING: This is a development server. Do not use it in a production deployment.\n",
      "   Use a production WSGI server instead.\n",
      " * Debug mode: off\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " * Running on http://localhost:9999/ (Press CTRL+C to quit)\n",
      "127.0.0.1 - - [30/Dec/2019 15:25:13] \"\u001b[37mGET / HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [30/Dec/2019 15:25:13] \"\u001b[37mGET /_dash-component-suites/dash_renderer/react@16.8.6.min.js?v=1.1.2&m=1571341129 HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [30/Dec/2019 15:25:13] \"\u001b[37mGET /_dash-component-suites/dash_renderer/prop-types@15.7.2.min.js?v=1.1.2&m=1571341129 HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [30/Dec/2019 15:25:13] \"\u001b[37mGET /_dash-component-suites/dash_renderer/react-dom@16.8.6.min.js?v=1.1.2&m=1571341129 HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [30/Dec/2019 15:25:13] \"\u001b[37mGET /_dash-component-suites/dash_core_components/highlight.pack.js?v=1.3.1&m=1571359392 HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [30/Dec/2019 15:25:13] \"\u001b[37mGET /_dash-component-suites/dash_core_components/dash_core_components.min.js?v=1.3.1&m=1571359392 HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [30/Dec/2019 15:25:14] \"\u001b[37mGET /_dash-component-suites/dash_core_components/plotly-1.50.1.min.js?v=1.3.1&m=1571359392 HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [30/Dec/2019 15:25:14] \"\u001b[37mGET /_dash-component-suites/dash_html_components/dash_html_components.min.js?v=1.0.1&m=1566962730 HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [30/Dec/2019 15:25:14] \"\u001b[37mGET /_dash-component-suites/dash_renderer/dash_renderer.min.js?v=1.1.2&m=1571341129 HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [30/Dec/2019 15:25:14] \"\u001b[37mGET /_dash-component-suites/dash_table/bundle.js?v=4.4.1&m=1571349949 HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [30/Dec/2019 15:25:14] \"\u001b[37mGET /_dash-dependencies HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [30/Dec/2019 15:25:14] \"\u001b[37mGET /_dash-layout HTTP/1.1\u001b[0m\" 200 -\n",
      "127.0.0.1 - - [30/Dec/2019 15:25:15] \"\u001b[37mPOST /_dash-update-component HTTP/1.1\u001b[0m\" 200 -\n"
     ]
    }
   ],
   "source": [
    "from IPython.display import display, IFrame, HTML\n",
    "import os\n",
    "\n",
    "def show_app(app, port=9999, width=900, height=700):\n",
    "    host = 'localhost'\n",
    "    url = f'http://{host}:{port}'\n",
    "\n",
    "    display(HTML(f\"<a href='{url}' target='_blank'>Open in new tab</a>\"))\n",
    "    display(IFrame(url, width=width, height=height))\n",
    "    app.css.config.serve_locally = True\n",
    "    app.scripts.config.serve_locally = True\n",
    "    return app.run_server(debug=False, host=host, port=port)\n",
    "\n",
    "import dash\n",
    "import dash_core_components as dcc\n",
    "import dash_html_components as html\n",
    "import dash_table as dt\n",
    "import plotly.graph_objs as go\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import pickle\n",
    "\n",
    "from scipy.spatial.distance import euclidean, cityblock, cosine\n",
    "from dash.dependencies import Input, Output, State\n",
    "\n",
    "app = dash.Dash(assets_folder='web/data', assets_url_path='web/data')\n",
    "\n",
    "with open('data/models1daw.pickle', 'rb') as fp:\n",
    "    models1daw = pickle.load(fp)\n",
    "    \n",
    "# Questions mapping\n",
    "# Where do you live?\n",
    "y5_mapping = {'Rural': 0, 'Urban': 1}\n",
    "# What is your marital status?\n",
    "a1_mapping = {'Single': 0, 'Married/Live-in': 1}\n",
    "# Are you religious?\n",
    "a15_mapping = {'Yes': 1, 'No': 0}\n",
    "# Do you get along with your siblings well? (Higher is More Prone)\n",
    "b2_mapping = {'Yes, all of them': 0, 'Yes, at least one but not all': 1, 'No': 2}\n",
    "# Do your parents get along well? (Higher is More Prone)\n",
    "b13_mapping = {'Most of the time': 1, \n",
    "               'Sometimes': 2, \n",
    "               'All the time': 0, \n",
    "               'Never': 3}\n",
    "# How do you get along with your father? (Higher is More Prone)\n",
    "b14_mapping = {'Most of the time': 1, \n",
    "                 'All the time': 0, \n",
    "                 'Sometimes': 2, \n",
    "                 'Never': 3}\n",
    "# How do you get along with your mother? (Higher is More Prone)\n",
    "b15_mapping = {'Most of the time': 1, \n",
    "                 'All the time': 0, \n",
    "                 'Sometimes': 2, \n",
    "                 'Never': 3}\n",
    "# You share your problems more to friends rather than family (Higher is More Prone)\n",
    "b28b_mapping = {'Sometimes': 2, 'Once in a while': 1, 'Frequently': 3, \n",
    "                 'Never': 0, 'Always': 4}\n",
    "# Were you disciplined in the family? (Higher is More Prone)\n",
    "b28d_mapping = {'Sometimes': 2, 'Once in a while': 3, 'Frequently': 1, \n",
    "                 'Never': 4, 'Always': 0}\n",
    "# Were you verbally abused by your family?\n",
    "b31a5_mapping = {'Yes': 1, 'No': 0}\n",
    "# Were you physically abused by your family?\n",
    "b31a6_mapping = {'Yes': 1, 'No': 0}      \n",
    "# How would you rate your happpiness? (Higher is better)\n",
    "c5_mapping = {'Very happy': 10, 'Not happy at all': 1, '2': 2, '3': 3, '4': 4,\n",
    "             '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}\n",
    "# How is your schooling?\n",
    "d1_mapping = {'In school': 0, \n",
    "              'Currently not in school': 1, \n",
    "              'Never been in school': 2}\n",
    "# Are you involved in a fraternity or sorority?\n",
    "d214_mapping = {'Yes': 1, 'No': 0}\n",
    "# Do you read pornography?\n",
    "e18_mapping = {'Yes': 1, 'No': 0}\n",
    "# Do you watch pornography?\n",
    "e21_mapping = {'Yes': 1, 'No': 0}\n",
    "# Do you ever feel depressed?\n",
    "g1802_mapping = {'Sometimes': 1, 'Rarely': 0, 'Often': 2}\n",
    "# Do you smoke?\n",
    "g19_mapping = {'Yes': 1, 'No': 0}\n",
    "# Do you drink?\n",
    "g30_mapping = {'Yes': 1, 'No': 0}\n",
    "# Do you have a family member who uses drugs?\n",
    "g73_mapping = {'Yes': 1, 'No': 0}\n",
    "# Were you physically abused in general?\n",
    "g77_mapping = {'Yes': 1, 'No': 0}\n",
    "# Do you have suicidal thoughts?\n",
    "g83_mapping = {'No': 0, 'Once': 1, 'More than once': 2}\n",
    "# Have you ever been suspended in school?\n",
    "d23_mapping = {'Yes': 1, 'No': 0}\n",
    "    \n",
    "app.callback_map = {}\n",
    "app.layout = html.Div([\n",
    "    # Title\n",
    "    html.Div([\n",
    "        html.Div('Prevention is Better than Cure:', \n",
    "                 style={'color': '#ffc000', 'font-family': 'Arial', \n",
    "                        'text-align': 'center', \n",
    "                        'font-weight': 'bold', 'font-size': '48px', \n",
    "                        'font-size': '3vw', 'width': '75%',\n",
    "                        'margin': 'auto'}),\n",
    "        html.Div('Predicting Illegal Drug Vulnerability among Filipino Youth', \n",
    "                 style={'font-family': 'Arial', 'text-align': 'center', \n",
    "                        'font-weight': 'bold', 'font-size': '42px', \n",
    "                        'font-size': '2.5vw', 'width': '75%',\n",
    "                        'margin': 'auto'})\n",
    "    ], style={'background-image': 'url(web/data/title.JPG)',\n",
    "              'height': '140px',\n",
    "              'margin': 'auto'}),\n",
    "    # Sliders\n",
    "    html.Div([\n",
    "        html.Br(),\n",
    "        html.Br(),\n",
    "        html.Div(['''The problem of illegal drugs is one of the most pressing \n",
    "        issues in the Philippines for many lives are affected by it. This \n",
    "        website aims to estimate the propensity for illegal drug use of a \n",
    "        Filipino young adult using Machine Learning.\n",
    "        '''], style={'font-size': '22px', 'margin': 'auto', \n",
    "                     'text-align': 'justify'}),\n",
    "        html.Br(),\n",
    "        html.Br(),\n",
    "        html.Div(['''The dataset was sourced \n",
    "        from the 2013 Young Adult Fertility and Sexuality Study (YAFS) \n",
    "        with a total of 19,728 respondents. Among the various machine \n",
    "        learning models that we evaluated, we found Gradient Boosting \n",
    "        Classifier to yield the highest accuracy of 95.4%.\n",
    "        '''], style={'font-size': '22px', 'margin': 'auto', \n",
    "                     'text-align': 'justify'}),\n",
    "        html.Br(),\n",
    "        html.Br(),\n",
    "        html.Div(['''We envisage that \n",
    "        with improved identification of vulnerable youth, necessary \n",
    "        interventions can be introduced more quickly and more accurately.\n",
    "        '''], style={'font-size': '22px', 'margin': 'auto', \n",
    "                     'text-align': 'justify'}),\n",
    "        html.Br(),\n",
    "        html.Br(),\n",
    "        html.Div(['''You can now calculate your vulnerability to illegal drugs by\n",
    "        answering the survey below!\n",
    "        '''], style={'font-size': '22px', 'margin': 'auto', \n",
    "                     'text-align': 'justify'}),\n",
    "        html.Br(),\n",
    "        html.Br(),\n",
    "        html.Hr(),\n",
    "        html.Div('Demographic', style={'font-weight': 'bold',\n",
    "                                       'font-size': '24px',\n",
    "                                       'color': '#ffc000'}),\n",
    "        html.Div([\n",
    "            html.Div([\n",
    "                html.Br(),\n",
    "                html.Br(),\n",
    "                html.Label('Are you religious?'),\n",
    "                dcc.Slider(id='c',\n",
    "                min=0,\n",
    "                max=1,\n",
    "                marks={y:x for x, y in a15_mapping.items()},\n",
    "                value=0,\n",
    "                updatemode='mouseup'\n",
    "            )], style={'width': '75%', 'margin': 'auto'}),\n",
    "            html.Div([\n",
    "                html.Br(),\n",
    "                html.Br(),\n",
    "                html.Label('Where do you live?'),\n",
    "                dcc.Slider(id='a',\n",
    "                min=0,\n",
    "                max=1,\n",
    "                marks={y:x for x, y in y5_mapping.items()},\n",
    "                value=0,\n",
    "                updatemode='mouseup'\n",
    "            )], style={'width': '75%', 'margin': 'auto'}),\n",
    "            html.Div([\n",
    "                html.Br(),\n",
    "                html.Br(),\n",
    "                html.Label('What is your marital status?'),\n",
    "                dcc.Slider(id='b',\n",
    "                min=0,\n",
    "                max=1,\n",
    "                marks={y:x for x, y in a1_mapping.items()},\n",
    "                value=0,\n",
    "                updatemode='mouseup'\n",
    "            )], style={'width': '75%', 'margin': 'auto'}),\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "        ])\n",
    "    ], style={'width': '75%', 'margin': 'auto'}),\n",
    "    html.Div([\n",
    "        html.Hr(),\n",
    "        html.Div('Family Relationship', style={'font-weight': 'bold',\n",
    "                                               'font-size': '24px',\n",
    "                                               'color': '#ffc000'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Were you verbally abused by your family?'),\n",
    "            dcc.Slider(id='j',\n",
    "            min=0,\n",
    "            max=1,\n",
    "            marks={y:x for x, y in b31a5_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Were you physically abused by your family?'),\n",
    "            dcc.Slider(id='k',\n",
    "            min=0,\n",
    "            max=1,\n",
    "            marks={y:x for x, y in b31a6_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Do you get along with your siblings well?'),\n",
    "            dcc.Slider(id='d',\n",
    "            min=0,\n",
    "            max=2,\n",
    "            marks={y:x for x, y in b2_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),    \n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Do your parents get along well?'),\n",
    "            dcc.Slider(id='e',\n",
    "            min=0,\n",
    "            max=3,\n",
    "            marks={y:x for x, y in b13_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Do you get along with your father?'),\n",
    "            dcc.Slider(id='f',\n",
    "            min=0,\n",
    "            max=3,\n",
    "            marks={y:x for x, y in b14_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Do you get along with your mother?'),\n",
    "            dcc.Slider(id='g',\n",
    "            min=0,\n",
    "            max=3,\n",
    "            marks={y:x for x, y in b15_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Were you disciplined in the family?'),\n",
    "            dcc.Slider(id='i',\n",
    "            min=0,\n",
    "            max=4,\n",
    "            marks={y:x for x, y in b28d_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('You share your problems more to friends rather than family'),\n",
    "            dcc.Slider(id='h',\n",
    "            min=0,\n",
    "            max=4,\n",
    "            marks={y:x for x, y in b28b_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Br(),\n",
    "        html.Br(),\n",
    "        html.Hr()   \n",
    "    ], style={'width': '75%', 'margin': 'auto'}),\n",
    "    html.Div([\n",
    "        html.Div('Activity', style={'font-weight': 'bold',\n",
    "                                    'font-size': '24px',\n",
    "                                    'color': '#ffc000'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Do you smoke?'),\n",
    "            dcc.Slider(id='r',\n",
    "            min=0,\n",
    "            max=1,\n",
    "            marks={y:x for x, y in g19_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Do you drink?'),\n",
    "            dcc.Slider(id='s',\n",
    "            min=0,\n",
    "            max=1,\n",
    "            marks={y:x for x, y in g30_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Do you read pornography?'),\n",
    "            dcc.Slider(id='o',\n",
    "            min=0,\n",
    "            max=1,\n",
    "            marks={y:x for x, y in e18_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Do you watch pornography?'),\n",
    "            dcc.Slider(id='p',\n",
    "            min=0,\n",
    "            max=1,\n",
    "            marks={y:x for x, y in e21_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Are you involved in a fraternity or sorority?'),\n",
    "            dcc.Slider(id='n',\n",
    "            min=0,\n",
    "            max=1,\n",
    "            marks={y:x for x, y in d214_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('How is your schooling?'),\n",
    "            dcc.Slider(id='m',\n",
    "            min=0,\n",
    "            max=2,\n",
    "            marks={y:x for x, y in d1_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Do you ever feel depressed?'),\n",
    "            dcc.Slider(id='q',\n",
    "            min=0,\n",
    "            max=2,\n",
    "            marks={y:x for x, y in g1802_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('How would you rate your happpiness?'),\n",
    "            dcc.Slider(id='l',\n",
    "            min=1,\n",
    "            max=10,\n",
    "            marks={y:x for x, y in c5_mapping.items()},\n",
    "            value=1,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "    ], style={'width': '75%', 'margin': 'auto'}),\n",
    "    html.Div([\n",
    "        html.Br(),\n",
    "        html.Br(),\n",
    "        html.Hr(),\n",
    "        html.Div('History', style={'font-weight': 'bold',\n",
    "                                   'font-size': '24px',\n",
    "                                   'color': '#ffc000'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Do you have a family member who uses drugs?'),\n",
    "            dcc.Slider(id='t',\n",
    "            min=0,\n",
    "            max=1,\n",
    "            marks={y:x for x, y in g73_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Were you physically abused in general?'),\n",
    "            dcc.Slider(id='u',\n",
    "            min=0,\n",
    "            max=1,\n",
    "            marks={y:x for x, y in g77_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Have you ever been suspended in school?'),\n",
    "            dcc.Slider(id='w',\n",
    "            min=0,\n",
    "            max=1,\n",
    "            marks={y:x for x, y in d23_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "        html.Div([\n",
    "            html.Br(),\n",
    "            html.Br(),\n",
    "            html.Label('Do you have suicidal thoughts?'),\n",
    "            dcc.Slider(id='v',\n",
    "            min=0,\n",
    "            max=2,\n",
    "            marks={y:x for x, y in g83_mapping.items()},\n",
    "            value=0,\n",
    "            updatemode='mouseup'\n",
    "        )], style={'width': '75%', 'margin': 'auto'}),\n",
    "    ], style={'width': '75%', 'margin': 'auto'}),\n",
    "    html.Br(),\n",
    "    html.Br(),\n",
    "    html.Br(),\n",
    "    html.Br(),\n",
    "    # Check button\n",
    "    html.Div(\n",
    "        [html.Button('Calculate!', id='button')], \n",
    "        style={'text-align': 'center'}),\n",
    "    html.Br(),\n",
    "    # Prediction\n",
    "    html.Div(id='pred', style={'text-align': 'center', 'font-size': '36px',\n",
    "                               'font-weight': 'bold', 'color': '#ffc000'}),\n",
    "    html.Br(),\n",
    "    html.Br(),\n",
    "    html.Div(html.Hr(), style={'margin': 'auto', 'width': '75%'}),\n",
    "    html.Br(),\n",
    "    html.Br(),\n",
    "    html.Div('Our Methodology', style={'text-align': 'center',\n",
    "                                       'font-size': '36px',\n",
    "                                       'font-weight': 'bold',\n",
    "                                       'color': 'white'}),\n",
    "    html.Br(),\n",
    "    html.Div([\n",
    "        html.Img(src=app.get_asset_url('methodology.JPG'),\n",
    "                         style={'max-width': '65%', 'max-height': '100%'})\n",
    "    ], style={'text-align': 'center'})\n",
    "    ], style={'font-family': 'Arial', 'color': 'white', \n",
    "              'background-color': 'black', 'padding': '0px'})\n",
    "\n",
    "@app.callback(Output('pred', 'children'),\n",
    "              [Input('button', 'n_clicks')],\n",
    "              [State('a', 'value'), State('b', 'value'), State('c', 'value'), \n",
    "               State('d', 'value'), State('e', 'value'), State('f', 'value'),\n",
    "               State('g', 'value'), State('h', 'value'), State('i', 'value'),\n",
    "               State('j', 'value'), State('k', 'value'), State('l', 'value'),\n",
    "               State('m', 'value'), State('n', 'value'), State('o', 'value'),\n",
    "               State('p', 'value'), State('q', 'value'), State('r', 'value'),\n",
    "               State('s', 'value'), State('t', 'value'), State('u', 'value'),\n",
    "               State('v', 'value'), State('w', 'value')])\n",
    "def display_prediction(n_clicks, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o,\n",
    "                      p, q, r, s, t, u, v, w):\n",
    "    if n_clicks:\n",
    "        return 'You are {:.2f}% vulnerable to drugs!'.format(models1daw['Gradient Boosting Classifier'].best_estimator_.\\\n",
    "                    predict_proba([[a, b, c, d, e, f, g, h, i, j, k, l, m, n, \n",
    "                                    o, p, q, r, s, t, u, v, w]])[0][1]*100)\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    app.run_server(debug=False)\n",
    "    \n",
    "show_app(app)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "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()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}