Spaces:
Build error
Build error
File size: 50,733 Bytes
7709e78 |
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 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 |
{
"cells": [
{
"cell_type": "markdown",
"source": [
"## Importing modules and Loading dataset.\n",
"This section contains importing the important python modules. Also, the dataset to be used, in this case the \n",
"\n"
],
"metadata": {
"id": "r5yZ0Codo2rF"
}
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true,
"pycharm": {
"name": "#%%\n"
},
"id": "Xfbj4kG4UwcC"
},
"outputs": [],
"source": [
"# importing python module.\n",
"import pandas as pd\n",
"from lightgbm.sklearn import LGBMClassifier\n",
"from sklearn.preprocessing import RobustScaler, OrdinalEncoder\n",
"from sklearn.model_selection import train_test_split, StratifiedShuffleSplit\n",
"from xgboost.sklearn import XGBClassifier\n",
"from sklearn.metrics import f1_score\n",
"\n",
"import warnings\n",
"warnings.filterwarnings(\"ignore\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"outputs": [
{
"data": {
"text/plain": " patient_number cholesterol glucose hdl_chol chol_hdl_ratio age gender \\\n0 1 193 77 49 3,9 19 female \n1 2 146 79 41 3,6 19 female \n2 3 217 75 54 4 20 female \n3 4 226 97 70 3,2 20 female \n4 5 164 91 67 2,4 20 female \n\n height weight bmi systolic_bp diastolic_bp waist hip \\\n0 61 119 22,5 118 70 32 38 \n1 60 135 26,4 108 58 33 40 \n2 67 187 29,3 110 72 40 45 \n3 64 114 19,6 122 64 31 39 \n4 70 141 20,2 122 86 32 39 \n\n waist_hip_ratio diabetes \n0 0,84 No diabetes \n1 0,83 No diabetes \n2 0,89 No diabetes \n3 0,79 No diabetes \n4 0,82 No diabetes ",
"text/html": "<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>patient_number</th>\n <th>cholesterol</th>\n <th>glucose</th>\n <th>hdl_chol</th>\n <th>chol_hdl_ratio</th>\n <th>age</th>\n <th>gender</th>\n <th>height</th>\n <th>weight</th>\n <th>bmi</th>\n <th>systolic_bp</th>\n <th>diastolic_bp</th>\n <th>waist</th>\n <th>hip</th>\n <th>waist_hip_ratio</th>\n <th>diabetes</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1</td>\n <td>193</td>\n <td>77</td>\n <td>49</td>\n <td>3,9</td>\n <td>19</td>\n <td>female</td>\n <td>61</td>\n <td>119</td>\n <td>22,5</td>\n <td>118</td>\n <td>70</td>\n <td>32</td>\n <td>38</td>\n <td>0,84</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2</td>\n <td>146</td>\n <td>79</td>\n <td>41</td>\n <td>3,6</td>\n <td>19</td>\n <td>female</td>\n <td>60</td>\n <td>135</td>\n <td>26,4</td>\n <td>108</td>\n <td>58</td>\n <td>33</td>\n <td>40</td>\n <td>0,83</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>2</th>\n <td>3</td>\n <td>217</td>\n <td>75</td>\n <td>54</td>\n <td>4</td>\n <td>20</td>\n <td>female</td>\n <td>67</td>\n <td>187</td>\n <td>29,3</td>\n <td>110</td>\n <td>72</td>\n <td>40</td>\n <td>45</td>\n <td>0,89</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>3</th>\n <td>4</td>\n <td>226</td>\n <td>97</td>\n <td>70</td>\n <td>3,2</td>\n <td>20</td>\n <td>female</td>\n <td>64</td>\n <td>114</td>\n <td>19,6</td>\n <td>122</td>\n <td>64</td>\n <td>31</td>\n <td>39</td>\n <td>0,79</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>4</th>\n <td>5</td>\n <td>164</td>\n <td>91</td>\n <td>67</td>\n <td>2,4</td>\n <td>20</td>\n <td>female</td>\n <td>70</td>\n <td>141</td>\n <td>20,2</td>\n <td>122</td>\n <td>86</td>\n <td>32</td>\n <td>39</td>\n <td>0,82</td>\n <td>No diabetes</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# loading dataset with pandas\n",
"dia = pd.read_csv(\"./dataset/diabetes.csv\")\n",
"\n",
"dia.head()"
],
"metadata": {
"pycharm": {
"name": "#%%\n"
},
"colab": {
"base_uri": "https://localhost:8080/",
"height": 357
},
"id": "yx869JONUwcJ",
"outputId": "ccdf4d8b-adf1-40b1-fe75-bc8a0dccfa6c"
}
},
{
"cell_type": "code",
"execution_count": 3,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 390 entries, 0 to 389\n",
"Data columns (total 16 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 patient_number 390 non-null int64 \n",
" 1 cholesterol 390 non-null int64 \n",
" 2 glucose 390 non-null int64 \n",
" 3 hdl_chol 390 non-null int64 \n",
" 4 chol_hdl_ratio 390 non-null object\n",
" 5 age 390 non-null int64 \n",
" 6 gender 390 non-null object\n",
" 7 height 390 non-null int64 \n",
" 8 weight 390 non-null int64 \n",
" 9 bmi 390 non-null object\n",
" 10 systolic_bp 390 non-null int64 \n",
" 11 diastolic_bp 390 non-null int64 \n",
" 12 waist 390 non-null int64 \n",
" 13 hip 390 non-null int64 \n",
" 14 waist_hip_ratio 390 non-null object\n",
" 15 diabetes 390 non-null object\n",
"dtypes: int64(11), object(5)\n",
"memory usage: 48.9+ KB\n"
]
}
],
"source": [
"# wrangling datasets with pandas\n",
"dia.info()"
],
"metadata": {
"pycharm": {
"name": "#%%\n"
},
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "rftvNRifUwcL",
"outputId": "d0799384-e171-4bc9-c149-873c22252711"
}
},
{
"cell_type": "code",
"execution_count": 4,
"outputs": [
{
"data": {
"text/plain": " patient_number cholesterol glucose hdl_chol age \\\ncount 390.000000 390.000000 390.000000 390.000000 390.000000 \nmean 195.500000 207.230769 107.338462 50.266667 46.774359 \nstd 112.727548 44.666005 53.798188 17.279069 16.435911 \nmin 1.000000 78.000000 48.000000 12.000000 19.000000 \n25% 98.250000 179.000000 81.000000 38.000000 34.000000 \n50% 195.500000 203.000000 90.000000 46.000000 44.500000 \n75% 292.750000 229.000000 107.750000 59.000000 60.000000 \nmax 390.000000 443.000000 385.000000 120.000000 92.000000 \n\n height weight systolic_bp diastolic_bp waist \\\ncount 390.000000 390.000000 390.000000 390.000000 390.000000 \nmean 65.951282 177.407692 137.133333 83.289744 37.869231 \nstd 3.918867 40.407824 22.859528 13.498192 5.760947 \nmin 52.000000 99.000000 90.000000 48.000000 26.000000 \n25% 63.000000 150.250000 122.000000 75.000000 33.000000 \n50% 66.000000 173.000000 136.000000 82.000000 37.000000 \n75% 69.000000 200.000000 148.000000 90.000000 41.000000 \nmax 76.000000 325.000000 250.000000 124.000000 56.000000 \n\n hip \ncount 390.000000 \nmean 42.992308 \nstd 5.664342 \nmin 30.000000 \n25% 39.000000 \n50% 42.000000 \n75% 46.000000 \nmax 64.000000 ",
"text/html": "<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>patient_number</th>\n <th>cholesterol</th>\n <th>glucose</th>\n <th>hdl_chol</th>\n <th>age</th>\n <th>height</th>\n <th>weight</th>\n <th>systolic_bp</th>\n <th>diastolic_bp</th>\n <th>waist</th>\n <th>hip</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>count</th>\n <td>390.000000</td>\n <td>390.000000</td>\n <td>390.000000</td>\n <td>390.000000</td>\n <td>390.000000</td>\n <td>390.000000</td>\n <td>390.000000</td>\n <td>390.000000</td>\n <td>390.000000</td>\n <td>390.000000</td>\n <td>390.000000</td>\n </tr>\n <tr>\n <th>mean</th>\n <td>195.500000</td>\n <td>207.230769</td>\n <td>107.338462</td>\n <td>50.266667</td>\n <td>46.774359</td>\n <td>65.951282</td>\n <td>177.407692</td>\n <td>137.133333</td>\n <td>83.289744</td>\n <td>37.869231</td>\n <td>42.992308</td>\n </tr>\n <tr>\n <th>std</th>\n <td>112.727548</td>\n <td>44.666005</td>\n <td>53.798188</td>\n <td>17.279069</td>\n <td>16.435911</td>\n <td>3.918867</td>\n <td>40.407824</td>\n <td>22.859528</td>\n <td>13.498192</td>\n <td>5.760947</td>\n <td>5.664342</td>\n </tr>\n <tr>\n <th>min</th>\n <td>1.000000</td>\n <td>78.000000</td>\n <td>48.000000</td>\n <td>12.000000</td>\n <td>19.000000</td>\n <td>52.000000</td>\n <td>99.000000</td>\n <td>90.000000</td>\n <td>48.000000</td>\n <td>26.000000</td>\n <td>30.000000</td>\n </tr>\n <tr>\n <th>25%</th>\n <td>98.250000</td>\n <td>179.000000</td>\n <td>81.000000</td>\n <td>38.000000</td>\n <td>34.000000</td>\n <td>63.000000</td>\n <td>150.250000</td>\n <td>122.000000</td>\n <td>75.000000</td>\n <td>33.000000</td>\n <td>39.000000</td>\n </tr>\n <tr>\n <th>50%</th>\n <td>195.500000</td>\n <td>203.000000</td>\n <td>90.000000</td>\n <td>46.000000</td>\n <td>44.500000</td>\n <td>66.000000</td>\n <td>173.000000</td>\n <td>136.000000</td>\n <td>82.000000</td>\n <td>37.000000</td>\n <td>42.000000</td>\n </tr>\n <tr>\n <th>75%</th>\n <td>292.750000</td>\n <td>229.000000</td>\n <td>107.750000</td>\n <td>59.000000</td>\n <td>60.000000</td>\n <td>69.000000</td>\n <td>200.000000</td>\n <td>148.000000</td>\n <td>90.000000</td>\n <td>41.000000</td>\n <td>46.000000</td>\n </tr>\n <tr>\n <th>max</th>\n <td>390.000000</td>\n <td>443.000000</td>\n <td>385.000000</td>\n <td>120.000000</td>\n <td>92.000000</td>\n <td>76.000000</td>\n <td>325.000000</td>\n <td>250.000000</td>\n <td>124.000000</td>\n <td>56.000000</td>\n <td>64.000000</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dia.describe()"
],
"metadata": {
"pycharm": {
"name": "#%%\n"
},
"colab": {
"base_uri": "https://localhost:8080/",
"height": 364
},
"id": "mPXcxzuwUwcN",
"outputId": "a1107ea3-215d-4400-e6ff-2d8fd7ff8b55"
}
},
{
"cell_type": "markdown",
"source": [
"## Wrangling dataset."
],
"metadata": {
"id": "S2hRdWcPqcrP"
}
},
{
"cell_type": "code",
"execution_count": 5,
"outputs": [],
"source": [
"dia.chol_hdl_ratio = round(dia.cholesterol / dia.hdl_chol,2)"
],
"metadata": {
"pycharm": {
"name": "#%%\n"
},
"id": "DCl3woxiUwcO"
}
},
{
"cell_type": "code",
"execution_count": 6,
"outputs": [
{
"data": {
"text/plain": " patient_number cholesterol glucose hdl_chol chol_hdl_ratio age \\\n0 1 193 77 49 3.94 19 \n1 2 146 79 41 3.56 19 \n2 3 217 75 54 4.02 20 \n3 4 226 97 70 3.23 20 \n4 5 164 91 67 2.45 20 \n\n gender height weight bmi systolic_bp diastolic_bp waist hip \\\n0 female 61 119 22,5 118 70 32 38 \n1 female 60 135 26,4 108 58 33 40 \n2 female 67 187 29,3 110 72 40 45 \n3 female 64 114 19,6 122 64 31 39 \n4 female 70 141 20,2 122 86 32 39 \n\n waist_hip_ratio diabetes \n0 0,84 No diabetes \n1 0,83 No diabetes \n2 0,89 No diabetes \n3 0,79 No diabetes \n4 0,82 No diabetes ",
"text/html": "<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>patient_number</th>\n <th>cholesterol</th>\n <th>glucose</th>\n <th>hdl_chol</th>\n <th>chol_hdl_ratio</th>\n <th>age</th>\n <th>gender</th>\n <th>height</th>\n <th>weight</th>\n <th>bmi</th>\n <th>systolic_bp</th>\n <th>diastolic_bp</th>\n <th>waist</th>\n <th>hip</th>\n <th>waist_hip_ratio</th>\n <th>diabetes</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1</td>\n <td>193</td>\n <td>77</td>\n <td>49</td>\n <td>3.94</td>\n <td>19</td>\n <td>female</td>\n <td>61</td>\n <td>119</td>\n <td>22,5</td>\n <td>118</td>\n <td>70</td>\n <td>32</td>\n <td>38</td>\n <td>0,84</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2</td>\n <td>146</td>\n <td>79</td>\n <td>41</td>\n <td>3.56</td>\n <td>19</td>\n <td>female</td>\n <td>60</td>\n <td>135</td>\n <td>26,4</td>\n <td>108</td>\n <td>58</td>\n <td>33</td>\n <td>40</td>\n <td>0,83</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>2</th>\n <td>3</td>\n <td>217</td>\n <td>75</td>\n <td>54</td>\n <td>4.02</td>\n <td>20</td>\n <td>female</td>\n <td>67</td>\n <td>187</td>\n <td>29,3</td>\n <td>110</td>\n <td>72</td>\n <td>40</td>\n <td>45</td>\n <td>0,89</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>3</th>\n <td>4</td>\n <td>226</td>\n <td>97</td>\n <td>70</td>\n <td>3.23</td>\n <td>20</td>\n <td>female</td>\n <td>64</td>\n <td>114</td>\n <td>19,6</td>\n <td>122</td>\n <td>64</td>\n <td>31</td>\n <td>39</td>\n <td>0,79</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>4</th>\n <td>5</td>\n <td>164</td>\n <td>91</td>\n <td>67</td>\n <td>2.45</td>\n <td>20</td>\n <td>female</td>\n <td>70</td>\n <td>141</td>\n <td>20,2</td>\n <td>122</td>\n <td>86</td>\n <td>32</td>\n <td>39</td>\n <td>0,82</td>\n <td>No diabetes</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dia.head()"
],
"metadata": {
"pycharm": {
"name": "#%%\n"
},
"colab": {
"base_uri": "https://localhost:8080/",
"height": 357
},
"id": "QNlQedszUwcP",
"outputId": "63231eb5-798a-4c07-8aae-851004ab3787"
}
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"collapsed": false,
"id": "SFHdSj2YUwcQ"
}
},
{
"cell_type": "code",
"execution_count": 7,
"outputs": [],
"source": [
"dia.waist_hip_ratio= round(dia.waist/dia.hip,2)"
],
"metadata": {
"pycharm": {
"name": "#%%\n"
},
"id": "ovJyqVa2UwcX"
}
},
{
"cell_type": "code",
"execution_count": 8,
"outputs": [
{
"data": {
"text/plain": " patient_number cholesterol glucose hdl_chol chol_hdl_ratio age \\\n0 1 193 77 49 3.94 19 \n1 2 146 79 41 3.56 19 \n2 3 217 75 54 4.02 20 \n3 4 226 97 70 3.23 20 \n4 5 164 91 67 2.45 20 \n\n gender height weight bmi systolic_bp diastolic_bp waist hip \\\n0 female 61 119 22,5 118 70 32 38 \n1 female 60 135 26,4 108 58 33 40 \n2 female 67 187 29,3 110 72 40 45 \n3 female 64 114 19,6 122 64 31 39 \n4 female 70 141 20,2 122 86 32 39 \n\n waist_hip_ratio diabetes \n0 0.84 No diabetes \n1 0.82 No diabetes \n2 0.89 No diabetes \n3 0.79 No diabetes \n4 0.82 No diabetes ",
"text/html": "<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>patient_number</th>\n <th>cholesterol</th>\n <th>glucose</th>\n <th>hdl_chol</th>\n <th>chol_hdl_ratio</th>\n <th>age</th>\n <th>gender</th>\n <th>height</th>\n <th>weight</th>\n <th>bmi</th>\n <th>systolic_bp</th>\n <th>diastolic_bp</th>\n <th>waist</th>\n <th>hip</th>\n <th>waist_hip_ratio</th>\n <th>diabetes</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1</td>\n <td>193</td>\n <td>77</td>\n <td>49</td>\n <td>3.94</td>\n <td>19</td>\n <td>female</td>\n <td>61</td>\n <td>119</td>\n <td>22,5</td>\n <td>118</td>\n <td>70</td>\n <td>32</td>\n <td>38</td>\n <td>0.84</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2</td>\n <td>146</td>\n <td>79</td>\n <td>41</td>\n <td>3.56</td>\n <td>19</td>\n <td>female</td>\n <td>60</td>\n <td>135</td>\n <td>26,4</td>\n <td>108</td>\n <td>58</td>\n <td>33</td>\n <td>40</td>\n <td>0.82</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>2</th>\n <td>3</td>\n <td>217</td>\n <td>75</td>\n <td>54</td>\n <td>4.02</td>\n <td>20</td>\n <td>female</td>\n <td>67</td>\n <td>187</td>\n <td>29,3</td>\n <td>110</td>\n <td>72</td>\n <td>40</td>\n <td>45</td>\n <td>0.89</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>3</th>\n <td>4</td>\n <td>226</td>\n <td>97</td>\n <td>70</td>\n <td>3.23</td>\n <td>20</td>\n <td>female</td>\n <td>64</td>\n <td>114</td>\n <td>19,6</td>\n <td>122</td>\n <td>64</td>\n <td>31</td>\n <td>39</td>\n <td>0.79</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>4</th>\n <td>5</td>\n <td>164</td>\n <td>91</td>\n <td>67</td>\n <td>2.45</td>\n <td>20</td>\n <td>female</td>\n <td>70</td>\n <td>141</td>\n <td>20,2</td>\n <td>122</td>\n <td>86</td>\n <td>32</td>\n <td>39</td>\n <td>0.82</td>\n <td>No diabetes</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dia.head()"
],
"metadata": {
"pycharm": {
"name": "#%%\n"
},
"colab": {
"base_uri": "https://localhost:8080/",
"height": 357
},
"id": "PWqYDcnYUwcZ",
"outputId": "d0e278d1-d7ed-4503-ee2b-5f94661e56e5"
}
},
{
"cell_type": "code",
"execution_count": 9,
"outputs": [],
"source": [
"dia.bmi = pd.to_numeric(dia.bmi.str.replace(\",\",\".\"))"
],
"metadata": {
"pycharm": {
"name": "#%%\n"
},
"id": "CXAX15VHUwce"
}
},
{
"cell_type": "code",
"execution_count": 10,
"outputs": [
{
"data": {
"text/plain": " patient_number cholesterol glucose hdl_chol chol_hdl_ratio age \\\n0 1 193 77 49 3.94 19 \n1 2 146 79 41 3.56 19 \n2 3 217 75 54 4.02 20 \n3 4 226 97 70 3.23 20 \n4 5 164 91 67 2.45 20 \n\n gender height weight bmi systolic_bp diastolic_bp waist hip \\\n0 female 61 119 22.5 118 70 32 38 \n1 female 60 135 26.4 108 58 33 40 \n2 female 67 187 29.3 110 72 40 45 \n3 female 64 114 19.6 122 64 31 39 \n4 female 70 141 20.2 122 86 32 39 \n\n waist_hip_ratio diabetes \n0 0.84 No diabetes \n1 0.82 No diabetes \n2 0.89 No diabetes \n3 0.79 No diabetes \n4 0.82 No diabetes ",
"text/html": "<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>patient_number</th>\n <th>cholesterol</th>\n <th>glucose</th>\n <th>hdl_chol</th>\n <th>chol_hdl_ratio</th>\n <th>age</th>\n <th>gender</th>\n <th>height</th>\n <th>weight</th>\n <th>bmi</th>\n <th>systolic_bp</th>\n <th>diastolic_bp</th>\n <th>waist</th>\n <th>hip</th>\n <th>waist_hip_ratio</th>\n <th>diabetes</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1</td>\n <td>193</td>\n <td>77</td>\n <td>49</td>\n <td>3.94</td>\n <td>19</td>\n <td>female</td>\n <td>61</td>\n <td>119</td>\n <td>22.5</td>\n <td>118</td>\n <td>70</td>\n <td>32</td>\n <td>38</td>\n <td>0.84</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2</td>\n <td>146</td>\n <td>79</td>\n <td>41</td>\n <td>3.56</td>\n <td>19</td>\n <td>female</td>\n <td>60</td>\n <td>135</td>\n <td>26.4</td>\n <td>108</td>\n <td>58</td>\n <td>33</td>\n <td>40</td>\n <td>0.82</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>2</th>\n <td>3</td>\n <td>217</td>\n <td>75</td>\n <td>54</td>\n <td>4.02</td>\n <td>20</td>\n <td>female</td>\n <td>67</td>\n <td>187</td>\n <td>29.3</td>\n <td>110</td>\n <td>72</td>\n <td>40</td>\n <td>45</td>\n <td>0.89</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>3</th>\n <td>4</td>\n <td>226</td>\n <td>97</td>\n <td>70</td>\n <td>3.23</td>\n <td>20</td>\n <td>female</td>\n <td>64</td>\n <td>114</td>\n <td>19.6</td>\n <td>122</td>\n <td>64</td>\n <td>31</td>\n <td>39</td>\n <td>0.79</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>4</th>\n <td>5</td>\n <td>164</td>\n <td>91</td>\n <td>67</td>\n <td>2.45</td>\n <td>20</td>\n <td>female</td>\n <td>70</td>\n <td>141</td>\n <td>20.2</td>\n <td>122</td>\n <td>86</td>\n <td>32</td>\n <td>39</td>\n <td>0.82</td>\n <td>No diabetes</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dia.head()"
],
"metadata": {
"pycharm": {
"name": "#%%\n"
},
"colab": {
"base_uri": "https://localhost:8080/",
"height": 357
},
"id": "Y9Rg5DkoUwcf",
"outputId": "de5133be-4736-4098-c94c-300eaac58f7d"
}
},
{
"cell_type": "code",
"source": [
"dia.weight.describe()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "PglRQVOhWq6F",
"outputId": "9e50d452-d5c4-41f0-a632-f148bb85c44f"
},
"execution_count": 11,
"outputs": [
{
"data": {
"text/plain": "count 390.000000\nmean 177.407692\nstd 40.407824\nmin 99.000000\n25% 150.250000\n50% 173.000000\n75% 200.000000\nmax 325.000000\nName: weight, dtype: float64"
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"cell_type": "code",
"execution_count": 12,
"outputs": [
{
"data": {
"text/plain": "patient_number 0\ncholesterol 0\nglucose 0\nhdl_chol 0\nchol_hdl_ratio 0\nage 0\ngender 0\nheight 0\nweight 0\nbmi 0\nsystolic_bp 0\ndiastolic_bp 0\nwaist 0\nhip 0\nwaist_hip_ratio 0\ndiabetes 0\ndtype: int64"
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dia.isnull().sum()"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"source": [
"dia.head()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 357
},
"id": "GY9af0LOoUrQ",
"outputId": "5cb087ef-8459-40e3-c65d-515007489006"
},
"execution_count": 13,
"outputs": [
{
"data": {
"text/plain": " patient_number cholesterol glucose hdl_chol chol_hdl_ratio age \\\n0 1 193 77 49 3.94 19 \n1 2 146 79 41 3.56 19 \n2 3 217 75 54 4.02 20 \n3 4 226 97 70 3.23 20 \n4 5 164 91 67 2.45 20 \n\n gender height weight bmi systolic_bp diastolic_bp waist hip \\\n0 female 61 119 22.5 118 70 32 38 \n1 female 60 135 26.4 108 58 33 40 \n2 female 67 187 29.3 110 72 40 45 \n3 female 64 114 19.6 122 64 31 39 \n4 female 70 141 20.2 122 86 32 39 \n\n waist_hip_ratio diabetes \n0 0.84 No diabetes \n1 0.82 No diabetes \n2 0.89 No diabetes \n3 0.79 No diabetes \n4 0.82 No diabetes ",
"text/html": "<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>patient_number</th>\n <th>cholesterol</th>\n <th>glucose</th>\n <th>hdl_chol</th>\n <th>chol_hdl_ratio</th>\n <th>age</th>\n <th>gender</th>\n <th>height</th>\n <th>weight</th>\n <th>bmi</th>\n <th>systolic_bp</th>\n <th>diastolic_bp</th>\n <th>waist</th>\n <th>hip</th>\n <th>waist_hip_ratio</th>\n <th>diabetes</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1</td>\n <td>193</td>\n <td>77</td>\n <td>49</td>\n <td>3.94</td>\n <td>19</td>\n <td>female</td>\n <td>61</td>\n <td>119</td>\n <td>22.5</td>\n <td>118</td>\n <td>70</td>\n <td>32</td>\n <td>38</td>\n <td>0.84</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2</td>\n <td>146</td>\n <td>79</td>\n <td>41</td>\n <td>3.56</td>\n <td>19</td>\n <td>female</td>\n <td>60</td>\n <td>135</td>\n <td>26.4</td>\n <td>108</td>\n <td>58</td>\n <td>33</td>\n <td>40</td>\n <td>0.82</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>2</th>\n <td>3</td>\n <td>217</td>\n <td>75</td>\n <td>54</td>\n <td>4.02</td>\n <td>20</td>\n <td>female</td>\n <td>67</td>\n <td>187</td>\n <td>29.3</td>\n <td>110</td>\n <td>72</td>\n <td>40</td>\n <td>45</td>\n <td>0.89</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>3</th>\n <td>4</td>\n <td>226</td>\n <td>97</td>\n <td>70</td>\n <td>3.23</td>\n <td>20</td>\n <td>female</td>\n <td>64</td>\n <td>114</td>\n <td>19.6</td>\n <td>122</td>\n <td>64</td>\n <td>31</td>\n <td>39</td>\n <td>0.79</td>\n <td>No diabetes</td>\n </tr>\n <tr>\n <th>4</th>\n <td>5</td>\n <td>164</td>\n <td>91</td>\n <td>67</td>\n <td>2.45</td>\n <td>20</td>\n <td>female</td>\n <td>70</td>\n <td>141</td>\n <td>20.2</td>\n <td>122</td>\n <td>86</td>\n <td>32</td>\n <td>39</td>\n <td>0.82</td>\n <td>No diabetes</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"cell_type": "code",
"source": [
"s= (dia.dtypes == \"object\")\n",
"obj_col= list(s[s].index)"
],
"metadata": {
"id": "cKtpXdi6pwdJ"
},
"execution_count": 14,
"outputs": []
},
{
"cell_type": "code",
"source": [
"obj_col"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "_jnwJCli1cA6",
"outputId": "563aa279-aae2-4d4e-d5c8-f8d668946539"
},
"execution_count": 15,
"outputs": [
{
"data": {
"text/plain": "['gender', 'diabetes']"
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"cell_type": "code",
"source": [
"orde = OrdinalEncoder()\n",
"dia[obj_col] = orde.fit_transform(dia[obj_col])"
],
"metadata": {
"id": "KvSeVC8K2FvU"
},
"execution_count": 16,
"outputs": []
},
{
"cell_type": "code",
"source": [
"dia.head()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 270
},
"id": "bY5dg9H53eVS",
"outputId": "27963a81-6560-455f-8d8d-10240bc5dc33"
},
"execution_count": 17,
"outputs": [
{
"data": {
"text/plain": " patient_number cholesterol glucose hdl_chol chol_hdl_ratio age \\\n0 1 193 77 49 3.94 19 \n1 2 146 79 41 3.56 19 \n2 3 217 75 54 4.02 20 \n3 4 226 97 70 3.23 20 \n4 5 164 91 67 2.45 20 \n\n gender height weight bmi systolic_bp diastolic_bp waist hip \\\n0 0.0 61 119 22.5 118 70 32 38 \n1 0.0 60 135 26.4 108 58 33 40 \n2 0.0 67 187 29.3 110 72 40 45 \n3 0.0 64 114 19.6 122 64 31 39 \n4 0.0 70 141 20.2 122 86 32 39 \n\n waist_hip_ratio diabetes \n0 0.84 1.0 \n1 0.82 1.0 \n2 0.89 1.0 \n3 0.79 1.0 \n4 0.82 1.0 ",
"text/html": "<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>patient_number</th>\n <th>cholesterol</th>\n <th>glucose</th>\n <th>hdl_chol</th>\n <th>chol_hdl_ratio</th>\n <th>age</th>\n <th>gender</th>\n <th>height</th>\n <th>weight</th>\n <th>bmi</th>\n <th>systolic_bp</th>\n <th>diastolic_bp</th>\n <th>waist</th>\n <th>hip</th>\n <th>waist_hip_ratio</th>\n <th>diabetes</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1</td>\n <td>193</td>\n <td>77</td>\n <td>49</td>\n <td>3.94</td>\n <td>19</td>\n <td>0.0</td>\n <td>61</td>\n <td>119</td>\n <td>22.5</td>\n <td>118</td>\n <td>70</td>\n <td>32</td>\n <td>38</td>\n <td>0.84</td>\n <td>1.0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2</td>\n <td>146</td>\n <td>79</td>\n <td>41</td>\n <td>3.56</td>\n <td>19</td>\n <td>0.0</td>\n <td>60</td>\n <td>135</td>\n <td>26.4</td>\n <td>108</td>\n <td>58</td>\n <td>33</td>\n <td>40</td>\n <td>0.82</td>\n <td>1.0</td>\n </tr>\n <tr>\n <th>2</th>\n <td>3</td>\n <td>217</td>\n <td>75</td>\n <td>54</td>\n <td>4.02</td>\n <td>20</td>\n <td>0.0</td>\n <td>67</td>\n <td>187</td>\n <td>29.3</td>\n <td>110</td>\n <td>72</td>\n <td>40</td>\n <td>45</td>\n <td>0.89</td>\n <td>1.0</td>\n </tr>\n <tr>\n <th>3</th>\n <td>4</td>\n <td>226</td>\n <td>97</td>\n <td>70</td>\n <td>3.23</td>\n <td>20</td>\n <td>0.0</td>\n <td>64</td>\n <td>114</td>\n <td>19.6</td>\n <td>122</td>\n <td>64</td>\n <td>31</td>\n <td>39</td>\n <td>0.79</td>\n <td>1.0</td>\n </tr>\n <tr>\n <th>4</th>\n <td>5</td>\n <td>164</td>\n <td>91</td>\n <td>67</td>\n <td>2.45</td>\n <td>20</td>\n <td>0.0</td>\n <td>70</td>\n <td>141</td>\n <td>20.2</td>\n <td>122</td>\n <td>86</td>\n <td>32</td>\n <td>39</td>\n <td>0.82</td>\n <td>1.0</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"cell_type": "code",
"source": [
"X = dia.drop([\"patient_number\", \"diabetes\"], axis= 1)\n",
"y= dia.diabetes"
],
"metadata": {
"id": "ZbHayB553gRB"
},
"execution_count": 18,
"outputs": []
},
{
"cell_type": "code",
"source": [
"scale = RobustScaler()\n",
"scaled_x = scale.fit_transform(X, y=y)"
],
"metadata": {
"id": "GpABdNvA3_8-"
},
"execution_count": 19,
"outputs": []
},
{
"cell_type": "code",
"source": [
"scaled_x"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "qgImunKB4r2i",
"outputId": "76b3b342-70c9-4aee-b3b6-1c21b9aac379"
},
"execution_count": 20,
"outputs": [
{
"data": {
"text/plain": "array([[-0.2 , -0.48598131, 0.14285714, ..., -0.625 ,\n -0.57142857, -0.41025641],\n [-1.14 , -0.41121495, -0.23809524, ..., -0.5 ,\n -0.28571429, -0.61538462],\n [ 0.28 , -0.56074766, 0.38095238, ..., 0.375 ,\n 0.42857143, 0.1025641 ],\n ...,\n [ 1.96 , 0. , 3.42857143, ..., -0.75 ,\n -0.14285714, -1.23076923],\n [ 0.58 , 3.51401869, 3.23809524, ..., -0.25 ,\n -0.57142857, 0.41025641],\n [-0.76 , 0.14953271, 1.0952381 , ..., 1.75 ,\n 1.28571429, 1.23076923]])"
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"cell_type": "code",
"source": [
"X_train, X_test, y_train, y_test = train_test_split(scaled_x, y, test_size= 0.2, random_state=42)"
],
"metadata": {
"id": "ZECN7XuJ4uAR"
},
"execution_count": 21,
"outputs": []
},
{
"cell_type": "code",
"execution_count": 22,
"outputs": [],
"source": [
"split = StratifiedShuffleSplit(n_splits=4, random_state=42 )\n",
"\n",
"for train_index, test_index in split.split(scaled_x, y):\n",
" strat_X, strat_test = scaled_x[train_index], scaled_x[test_index]\n",
" strat_y, strat_ytest = y[train_index], y[test_index]"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"source": [
"X_train"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Zo2R6TH55gTW",
"outputId": "b12de013-4626-4a0e-aaac-f16281bd50b6"
},
"execution_count": 23,
"outputs": [
{
"data": {
"text/plain": "array([[-0.22 , -1.27102804, -0.19047619, ..., -0.75 ,\n -0.28571429, -1.02564103],\n [-0.44 , 0.41121495, -0.0952381 , ..., 0.125 ,\n 0. , 0.20512821],\n [ 0.18 , -0.41121495, 0.14285714, ..., 0.125 ,\n 0. , 0.20512821],\n ...,\n [-1.48 , 0.74766355, -0.19047619, ..., -0.375 ,\n -0.57142857, 0.1025641 ],\n [ 0.66 , 0.78504673, 1.71428571, ..., -1. ,\n -0.71428571, -1.02564103],\n [ 2.68 , -0.18691589, 0.76190476, ..., -0.125 ,\n 0.28571429, -0.61538462]])"
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"cell_type": "code",
"source": [
"lgbm_model = LGBMClassifier(n_estimators=200, max_depth=-2, random_state=42)"
],
"metadata": {
"id": "S9cGQrMp5iug"
},
"execution_count": 24,
"outputs": []
},
{
"cell_type": "code",
"source": [
"lgbm_model.fit(X_train, y_train)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "SWj3o6Cg6nUD",
"outputId": "b64a97a4-1f1d-46c3-c11e-e429feedd6db"
},
"execution_count": 25,
"outputs": [
{
"data": {
"text/plain": "LGBMClassifier(max_depth=-2, n_estimators=200, random_state=42)"
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"cell_type": "code",
"source": [
"y_pred=lgbm_model.predict(X_test)"
],
"metadata": {
"id": "8LFEmpW16yNk"
},
"execution_count": 26,
"outputs": []
},
{
"cell_type": "code",
"source": [
"f1_score(y_pred, y_test)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "I1pWPR0x6_r9",
"outputId": "4ecaee82-9c32-4ca2-f71a-c376ea853419"
},
"execution_count": 27,
"outputs": [
{
"data": {
"text/plain": "0.9354838709677419"
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"cell_type": "code",
"source": [
"xg_model= XGBClassifier(n_estimators=200, max_depth=4, scale_pos_weight=5.5)"
],
"metadata": {
"id": "e6JqauyE7Luq"
},
"execution_count": 28,
"outputs": []
},
{
"cell_type": "code",
"execution_count": 29,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[23:22:04] WARNING: C:/Users/Administrator/workspace/xgboost-win64_release_1.4.0/src/learner.cc:1095: Starting in XGBoost 1.3.0, the default evaluation metric used with the objective 'binary:logistic' was changed from 'error' to 'logloss'. Explicitly set eval_metric if you'd like to restore the old behavior.\n"
]
},
{
"data": {
"text/plain": "XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,\n colsample_bynode=1, colsample_bytree=1, gamma=0, gpu_id=-1,\n importance_type='gain', interaction_constraints='',\n learning_rate=0.300000012, max_delta_step=0, max_depth=4,\n min_child_weight=1, missing=nan, monotone_constraints='()',\n n_estimators=200, n_jobs=4, num_parallel_tree=1, random_state=0,\n reg_alpha=0, reg_lambda=1, scale_pos_weight=5.5, subsample=1,\n tree_method='exact', validate_parameters=1, verbosity=None)"
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xg_model.fit(X_train, y_train)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 30,
"outputs": [],
"source": [
"xg_pred = xg_model.predict(X_test)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 31,
"outputs": [
{
"data": {
"text/plain": "0.943089430894309"
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f1_score(y_test, xg_pred)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "markdown",
"source": [
"## Stratified Shuffle Test"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
}
},
{
"cell_type": "code",
"execution_count": 32,
"outputs": [],
"source": [
"lgbm_strat = LGBMClassifier(n_estimators=200, learning_rate=0.0099, max_depth=-2, )"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 33,
"outputs": [
{
"data": {
"text/plain": "LGBMClassifier(learning_rate=0.0099, max_depth=-2, n_estimators=200)"
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lgbm_strat.fit(strat_X, strat_y)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 34,
"outputs": [],
"source": [
"strat_pred = lgbm_strat.predict(strat_test)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 35,
"outputs": [
{
"data": {
"text/plain": "0.955223880597015"
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f1_score(strat_pred, strat_ytest)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 38,
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"def predict(var_name):\n",
" pred = [var_name]\n",
" np_pred = np.array(pred)\n",
" score = lgbm_strat.predict(np_pred)\n",
" return score"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 39,
"outputs": [
{
"data": {
"text/plain": "1.0 330\n0.0 60\nName: diabetes, dtype: int64"
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dia.diabetes.value_counts()"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 40,
"outputs": [
{
"data": {
"text/plain": "5.5"
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"330/60"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 41,
"outputs": [],
"source": [
"xgb= XGBClassifier(max_depth=7, n_estimators=1000, scale_pos_weight=5.5)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 42,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[00:36:49] WARNING: C:/Users/Administrator/workspace/xgboost-win64_release_1.4.0/src/learner.cc:1095: Starting in XGBoost 1.3.0, the default evaluation metric used with the objective 'binary:logistic' was changed from 'error' to 'logloss'. Explicitly set eval_metric if you'd like to restore the old behavior.\n"
]
},
{
"data": {
"text/plain": "XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,\n colsample_bynode=1, colsample_bytree=1, gamma=0, gpu_id=-1,\n importance_type='gain', interaction_constraints='',\n learning_rate=0.300000012, max_delta_step=0, max_depth=7,\n min_child_weight=1, missing=nan, monotone_constraints='()',\n n_estimators=1000, n_jobs=4, num_parallel_tree=1, random_state=0,\n reg_alpha=0, reg_lambda=1, scale_pos_weight=5.5, subsample=1,\n tree_method='exact', validate_parameters=1, verbosity=None)"
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xgb.fit(strat_X, strat_y)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 43,
"outputs": [],
"source": [
"y=xgb.predict(strat_test)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 44,
"outputs": [
{
"data": {
"text/plain": "0.955223880597015"
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f1_score(y, strat_ytest)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 45,
"outputs": [],
"source": [
"import sqlite3"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 46,
"outputs": [],
"source": [
"conn = sqlite3.connect(\"diabetes.db\")\n",
"c = conn.cursor()"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 47,
"outputs": [
{
"data": {
"text/plain": "('patient_number',\n 'cholesterol',\n 'glucose',\n 'hdl_chol',\n 'chol_hdl_ratio',\n 'age',\n 'gender',\n 'height',\n 'weight',\n 'bmi',\n 'systolic_bp',\n 'diastolic_bp',\n 'waist',\n 'hip',\n 'waist_hip_ratio',\n 'diabetes')"
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"col= tuple(dia.columns)\n",
"col"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 48,
"outputs": [],
"source": [
"conn.commit()"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "code",
"execution_count": 49,
"outputs": [],
"source": [
"dia.to_sql(name=\"diabetes.db\", con=conn, if_exists= \"replace\", index=False)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
},
"colab": {
"provenance": []
}
},
"nbformat": 4,
"nbformat_minor": 0
} |