├── 0. datasets link part 4.txt ├── 8_2_Cross_Validation_Python_Implementation.ipynb ├── 8_6_Model_Selection_in_ML_with_Python.ipynb ├── Precision,_Recall,_F1_Score_Python_implementation.ipynb └── Accuracy_score_and_Confusion_Matrix.ipynb /0. datasets link part 4.txt: -------------------------------------------------------------------------------- 1 | All Datasets link: https://drive.google.com/drive/folders/12DCaNj6JKl2t6mZPwydCsrB2ho7UpiMu?usp=sharing -------------------------------------------------------------------------------- /8_2_Cross_Validation_Python_Implementation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "collapsed_sections": [] 8 | }, 9 | "kernelspec": { 10 | "name": "python3", 11 | "display_name": "Python 3" 12 | }, 13 | "language_info": { 14 | "name": "python" 15 | } 16 | }, 17 | "cells": [ 18 | { 19 | "cell_type": "markdown", 20 | "source": [ 21 | "**Video Link:**\n", 22 | "\n", 23 | "K-Fold cross validation - concept ideo: https://youtu.be/dkd1eeaXbJA" 24 | ], 25 | "metadata": { 26 | "id": "1qbu9h-el72-" 27 | } 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "source": [ 32 | "Importing the Dependencies" 33 | ], 34 | "metadata": { 35 | "id": "bFJFyzowbp1A" 36 | } 37 | }, 38 | { 39 | "cell_type": "code", 40 | "source": [ 41 | "import numpy as np\n", 42 | "import pandas as pd\n", 43 | "from sklearn.model_selection import train_test_split\n", 44 | "from sklearn.model_selection import cross_val_score\n", 45 | "from sklearn.metrics import accuracy_score" 46 | ], 47 | "metadata": { 48 | "id": "cY2Jyn1jbnPb" 49 | }, 50 | "execution_count": null, 51 | "outputs": [] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "source": [ 56 | "Importing the models" 57 | ], 58 | "metadata": { 59 | "id": "t_yFbxn0ci3f" 60 | } 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": null, 65 | "metadata": { 66 | "id": "eq2pMIzlbbqI" 67 | }, 68 | "outputs": [], 69 | "source": [ 70 | "from sklearn.linear_model import LogisticRegression\n", 71 | "from sklearn.svm import SVC\n", 72 | "from sklearn.neighbors import KNeighborsClassifier\n", 73 | "from sklearn.ensemble import RandomForestClassifier" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": { 79 | "id": "egMd5zeurTMR" 80 | }, 81 | "source": [ 82 | "Data Collection and Processing" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "metadata": { 88 | "id": "0q-3-LkQrREV" 89 | }, 90 | "source": [ 91 | "# loading the csv data to a Pandas DataFrame\n", 92 | "heart_data = pd.read_csv('/content/heart.csv')" 93 | ], 94 | "execution_count": null, 95 | "outputs": [] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "metadata": { 100 | "id": "M8dQxSTqriWD", 101 | "colab": { 102 | "base_uri": "https://localhost:8080/", 103 | "height": 206 104 | }, 105 | "outputId": "7ab56250-3739-413e-9f62-09491ddadf89" 106 | }, 107 | "source": [ 108 | "# print first 5 rows of the dataset\n", 109 | "heart_data.head()" 110 | ], 111 | "execution_count": null, 112 | "outputs": [ 113 | { 114 | "output_type": "execute_result", 115 | "data": { 116 | "text/html": [ 117 | "\n", 118 | "
\n", 119 | "
\n", 120 | "
\n", 121 | "\n", 134 | "\n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | " \n", 236 | " \n", 237 | " \n", 238 | " \n", 239 | " \n", 240 | " \n", 241 | "
agesexcptrestbpscholfbsrestecgthalachexangoldpeakslopecathaltarget
063131452331015002.30011
137121302500118703.50021
241011302040017201.42021
356111202360117800.82021
457001203540116310.62021
\n", 242 | "
\n", 243 | " \n", 253 | " \n", 254 | " \n", 291 | "\n", 292 | " \n", 316 | "
\n", 317 | "
\n", 318 | " " 319 | ], 320 | "text/plain": [ 321 | " age sex cp trestbps chol fbs ... exang oldpeak slope ca thal target\n", 322 | "0 63 1 3 145 233 1 ... 0 2.3 0 0 1 1\n", 323 | "1 37 1 2 130 250 0 ... 0 3.5 0 0 2 1\n", 324 | "2 41 0 1 130 204 0 ... 0 1.4 2 0 2 1\n", 325 | "3 56 1 1 120 236 0 ... 0 0.8 2 0 2 1\n", 326 | "4 57 0 0 120 354 0 ... 1 0.6 2 0 2 1\n", 327 | "\n", 328 | "[5 rows x 14 columns]" 329 | ] 330 | }, 331 | "metadata": {}, 332 | "execution_count": 4 333 | } 334 | ] 335 | }, 336 | { 337 | "cell_type": "code", 338 | "metadata": { 339 | "id": "8nX1tIzbrz0u", 340 | "colab": { 341 | "base_uri": "https://localhost:8080/" 342 | }, 343 | "outputId": "f0bfe5c2-e1a7-4694-bba8-f2168ce63928" 344 | }, 345 | "source": [ 346 | "# number of rows and columns in the dataset\n", 347 | "heart_data.shape" 348 | ], 349 | "execution_count": null, 350 | "outputs": [ 351 | { 352 | "output_type": "execute_result", 353 | "data": { 354 | "text/plain": [ 355 | "(303, 14)" 356 | ] 357 | }, 358 | "metadata": {}, 359 | "execution_count": 5 360 | } 361 | ] 362 | }, 363 | { 364 | "cell_type": "code", 365 | "metadata": { 366 | "id": "GjHtW31rsGlb", 367 | "colab": { 368 | "base_uri": "https://localhost:8080/" 369 | }, 370 | "outputId": "f55c6b6d-3cc4-473c-df00-177229a6ec12" 371 | }, 372 | "source": [ 373 | "# checking for missing values\n", 374 | "heart_data.isnull().sum()" 375 | ], 376 | "execution_count": null, 377 | "outputs": [ 378 | { 379 | "output_type": "execute_result", 380 | "data": { 381 | "text/plain": [ 382 | "age 0\n", 383 | "sex 0\n", 384 | "cp 0\n", 385 | "trestbps 0\n", 386 | "chol 0\n", 387 | "fbs 0\n", 388 | "restecg 0\n", 389 | "thalach 0\n", 390 | "exang 0\n", 391 | "oldpeak 0\n", 392 | "slope 0\n", 393 | "ca 0\n", 394 | "thal 0\n", 395 | "target 0\n", 396 | "dtype: int64" 397 | ] 398 | }, 399 | "metadata": {}, 400 | "execution_count": 6 401 | } 402 | ] 403 | }, 404 | { 405 | "cell_type": "code", 406 | "metadata": { 407 | "id": "4InaOSIUsfWP", 408 | "colab": { 409 | "base_uri": "https://localhost:8080/" 410 | }, 411 | "outputId": "a508875a-712b-4987-c459-57efe941bc14" 412 | }, 413 | "source": [ 414 | "# checking the distribution of Target Variable\n", 415 | "heart_data['target'].value_counts()" 416 | ], 417 | "execution_count": null, 418 | "outputs": [ 419 | { 420 | "output_type": "execute_result", 421 | "data": { 422 | "text/plain": [ 423 | "1 165\n", 424 | "0 138\n", 425 | "Name: target, dtype: int64" 426 | ] 427 | }, 428 | "metadata": {}, 429 | "execution_count": 7 430 | } 431 | ] 432 | }, 433 | { 434 | "cell_type": "markdown", 435 | "metadata": { 436 | "id": "aSOBu4qDtJy5" 437 | }, 438 | "source": [ 439 | "1 --> Defective Heart\n", 440 | "\n", 441 | "0 --> Healthy Heart" 442 | ] 443 | }, 444 | { 445 | "cell_type": "markdown", 446 | "metadata": { 447 | "id": "tW8i4igjtPRC" 448 | }, 449 | "source": [ 450 | "Splitting the Features and Target" 451 | ] 452 | }, 453 | { 454 | "cell_type": "code", 455 | "metadata": { 456 | "id": "Q6yfbswrs7m3" 457 | }, 458 | "source": [ 459 | "X = heart_data.drop(columns='target', axis=1)\n", 460 | "Y = heart_data['target']" 461 | ], 462 | "execution_count": null, 463 | "outputs": [] 464 | }, 465 | { 466 | "cell_type": "code", 467 | "metadata": { 468 | "id": "XJoCp4ZKtpZy", 469 | "colab": { 470 | "base_uri": "https://localhost:8080/" 471 | }, 472 | "outputId": "f12ada00-3c4f-4372-b334-72d44bd46abc" 473 | }, 474 | "source": [ 475 | "print(X)" 476 | ], 477 | "execution_count": null, 478 | "outputs": [ 479 | { 480 | "output_type": "stream", 481 | "name": "stdout", 482 | "text": [ 483 | " age sex cp trestbps chol ... exang oldpeak slope ca thal\n", 484 | "0 63 1 3 145 233 ... 0 2.3 0 0 1\n", 485 | "1 37 1 2 130 250 ... 0 3.5 0 0 2\n", 486 | "2 41 0 1 130 204 ... 0 1.4 2 0 2\n", 487 | "3 56 1 1 120 236 ... 0 0.8 2 0 2\n", 488 | "4 57 0 0 120 354 ... 1 0.6 2 0 2\n", 489 | ".. ... ... .. ... ... ... ... ... ... .. ...\n", 490 | "298 57 0 0 140 241 ... 1 0.2 1 0 3\n", 491 | "299 45 1 3 110 264 ... 0 1.2 1 0 3\n", 492 | "300 68 1 0 144 193 ... 0 3.4 1 2 3\n", 493 | "301 57 1 0 130 131 ... 1 1.2 1 1 3\n", 494 | "302 57 0 1 130 236 ... 0 0.0 1 1 2\n", 495 | "\n", 496 | "[303 rows x 13 columns]\n" 497 | ] 498 | } 499 | ] 500 | }, 501 | { 502 | "cell_type": "code", 503 | "metadata": { 504 | "id": "nukuj-YItq1w", 505 | "colab": { 506 | "base_uri": "https://localhost:8080/" 507 | }, 508 | "outputId": "6f3ffab4-3273-4cb3-e28f-4a12bdd57695" 509 | }, 510 | "source": [ 511 | "print(Y)" 512 | ], 513 | "execution_count": null, 514 | "outputs": [ 515 | { 516 | "output_type": "stream", 517 | "name": "stdout", 518 | "text": [ 519 | "0 1\n", 520 | "1 1\n", 521 | "2 1\n", 522 | "3 1\n", 523 | "4 1\n", 524 | " ..\n", 525 | "298 0\n", 526 | "299 0\n", 527 | "300 0\n", 528 | "301 0\n", 529 | "302 0\n", 530 | "Name: target, Length: 303, dtype: int64\n" 531 | ] 532 | } 533 | ] 534 | }, 535 | { 536 | "cell_type": "markdown", 537 | "source": [ 538 | "#**Train Test Split**" 539 | ], 540 | "metadata": { 541 | "id": "aC6gnrWKmLkt" 542 | } 543 | }, 544 | { 545 | "cell_type": "code", 546 | "source": [ 547 | "X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, stratify = Y, random_state=3)" 548 | ], 549 | "metadata": { 550 | "id": "r3YeSH60mNkI" 551 | }, 552 | "execution_count": null, 553 | "outputs": [] 554 | }, 555 | { 556 | "cell_type": "code", 557 | "source": [ 558 | "print(X.shape, X_train.shape, X_test.shape)" 559 | ], 560 | "metadata": { 561 | "colab": { 562 | "base_uri": "https://localhost:8080/" 563 | }, 564 | "id": "Cu0IQu4R5DUi", 565 | "outputId": "e79e8d4e-d001-49ca-8815-f37881c6d3ba" 566 | }, 567 | "execution_count": null, 568 | "outputs": [ 569 | { 570 | "output_type": "stream", 571 | "name": "stdout", 572 | "text": [ 573 | "(303, 13) (242, 13) (61, 13)\n" 574 | ] 575 | } 576 | ] 577 | }, 578 | { 579 | "cell_type": "markdown", 580 | "source": [ 581 | "Comparing the performance of the models" 582 | ], 583 | "metadata": { 584 | "id": "YJGEFKbL6Xgz" 585 | } 586 | }, 587 | { 588 | "cell_type": "code", 589 | "source": [ 590 | "# list of models\n", 591 | "models = [LogisticRegression(max_iter=1000), SVC(kernel='linear'), KNeighborsClassifier(), RandomForestClassifier()]" 592 | ], 593 | "metadata": { 594 | "id": "FFYBrujx6He7" 595 | }, 596 | "execution_count": null, 597 | "outputs": [] 598 | }, 599 | { 600 | "cell_type": "code", 601 | "source": [ 602 | "def compare_models_train_test():\n", 603 | "\n", 604 | " for model in models:\n", 605 | "\n", 606 | " # training the model\n", 607 | " model.fit(X_train, Y_train)\n", 608 | " \n", 609 | " # evaluating the model\n", 610 | " test_data_prediction = model.predict(X_test)\n", 611 | "\n", 612 | " accuracy = accuracy_score(Y_test, test_data_prediction)\n", 613 | "\n", 614 | " print('Accuracy score of the ', model, ' = ', accuracy)\n", 615 | "\n" 616 | ], 617 | "metadata": { 618 | "id": "RBN8lQVj6x0g" 619 | }, 620 | "execution_count": null, 621 | "outputs": [] 622 | }, 623 | { 624 | "cell_type": "code", 625 | "source": [ 626 | "compare_models_train_test()" 627 | ], 628 | "metadata": { 629 | "colab": { 630 | "base_uri": "https://localhost:8080/" 631 | }, 632 | "id": "35fIR_v_7Qt_", 633 | "outputId": "bff483fc-4fbb-417f-90c0-5b11b75dbfa8" 634 | }, 635 | "execution_count": null, 636 | "outputs": [ 637 | { 638 | "output_type": "stream", 639 | "name": "stdout", 640 | "text": [ 641 | "Accuracy score of the LogisticRegression(max_iter=1000) = 0.7704918032786885\n", 642 | "Accuracy score of the SVC(kernel='linear') = 0.7704918032786885\n", 643 | "Accuracy score of the KNeighborsClassifier() = 0.6557377049180327\n", 644 | "Accuracy score of the RandomForestClassifier() = 0.8032786885245902\n" 645 | ] 646 | } 647 | ] 648 | }, 649 | { 650 | "cell_type": "markdown", 651 | "source": [ 652 | "#**Cross Validation**" 653 | ], 654 | "metadata": { 655 | "id": "Wf783hX19fwN" 656 | } 657 | }, 658 | { 659 | "cell_type": "markdown", 660 | "source": [ 661 | "Logistic Regression" 662 | ], 663 | "metadata": { 664 | "id": "cpRlz36P9vfe" 665 | } 666 | }, 667 | { 668 | "cell_type": "code", 669 | "source": [ 670 | "cv_score_lr = cross_val_score(LogisticRegression(max_iter=1000), X, Y, cv=5)\n", 671 | "\n", 672 | "print(cv_score_lr)\n", 673 | "\n", 674 | "mean_accuracy_lr = sum(cv_score_lr)/len(cv_score_lr)\n", 675 | "\n", 676 | "mean_accuracy_lr = mean_accuracy_lr*100\n", 677 | "\n", 678 | "mean_accuracy_lr = round(mean_accuracy_lr, 2)\n", 679 | "\n", 680 | "print(mean_accuracy_lr)" 681 | ], 682 | "metadata": { 683 | "colab": { 684 | "base_uri": "https://localhost:8080/" 685 | }, 686 | "id": "fIkZCHab746J", 687 | "outputId": "891b5b92-0339-4a96-8541-322084317ee3" 688 | }, 689 | "execution_count": null, 690 | "outputs": [ 691 | { 692 | "output_type": "stream", 693 | "name": "stdout", 694 | "text": [ 695 | "[0.80327869 0.86885246 0.85245902 0.86666667 0.75 ]\n", 696 | "82.83\n" 697 | ] 698 | } 699 | ] 700 | }, 701 | { 702 | "cell_type": "markdown", 703 | "source": [ 704 | "Support Vector Classifier" 705 | ], 706 | "metadata": { 707 | "id": "RA7W2es0AFD3" 708 | } 709 | }, 710 | { 711 | "cell_type": "code", 712 | "source": [ 713 | "cv_score_svc = cross_val_score(SVC(kernel='linear'), X, Y, cv=5)\n", 714 | "\n", 715 | "print(cv_score_svc)\n", 716 | "\n", 717 | "mean_accuracy_svc = sum(cv_score_svc)/len(cv_score_svc)\n", 718 | "\n", 719 | "mean_accuracy_svc = mean_accuracy_svc*100\n", 720 | "\n", 721 | "mean_accuracy_svc = round(mean_accuracy_svc, 2)\n", 722 | "\n", 723 | "print(mean_accuracy_svc)" 724 | ], 725 | "metadata": { 726 | "colab": { 727 | "base_uri": "https://localhost:8080/" 728 | }, 729 | "id": "nNCZfeSe-0oZ", 730 | "outputId": "4e79257f-c77f-4d9c-e967-b3641ef86454" 731 | }, 732 | "execution_count": null, 733 | "outputs": [ 734 | { 735 | "output_type": "stream", 736 | "name": "stdout", 737 | "text": [ 738 | "[0.81967213 0.8852459 0.80327869 0.86666667 0.76666667]\n", 739 | "82.83\n" 740 | ] 741 | } 742 | ] 743 | }, 744 | { 745 | "cell_type": "markdown", 746 | "source": [ 747 | "Creating a Function to compare the models" 748 | ], 749 | "metadata": { 750 | "id": "PlM83YyPApq_" 751 | } 752 | }, 753 | { 754 | "cell_type": "code", 755 | "source": [ 756 | "# list of models\n", 757 | "models = [LogisticRegression(max_iter=1000), SVC(kernel='linear'), KNeighborsClassifier(), RandomForestClassifier()]" 758 | ], 759 | "metadata": { 760 | "id": "uyAZczwYAT3f" 761 | }, 762 | "execution_count": null, 763 | "outputs": [] 764 | }, 765 | { 766 | "cell_type": "code", 767 | "source": [ 768 | "def compare_models_cross_validation():\n", 769 | "\n", 770 | " for model in models:\n", 771 | "\n", 772 | " cv_score = cross_val_score(model, X,Y, cv=5)\n", 773 | " \n", 774 | " mean_accuracy = sum(cv_score)/len(cv_score)\n", 775 | "\n", 776 | " mean_accuracy = mean_accuracy*100\n", 777 | "\n", 778 | " mean_accuracy = round(mean_accuracy, 2)\n", 779 | "\n", 780 | " print('Cross Validation accuracies for ', model, '= ', cv_score)\n", 781 | " print('Accuracy % of the ', model, mean_accuracy)\n", 782 | " print('----------------------------------------------')\n" 783 | ], 784 | "metadata": { 785 | "id": "AWfa55OKAygv" 786 | }, 787 | "execution_count": null, 788 | "outputs": [] 789 | }, 790 | { 791 | "cell_type": "code", 792 | "source": [ 793 | "compare_models_cross_validation()" 794 | ], 795 | "metadata": { 796 | "colab": { 797 | "base_uri": "https://localhost:8080/" 798 | }, 799 | "id": "QaCp6U_cBvVM", 800 | "outputId": "0591db43-6a2c-4329-840d-04f3ae721d17" 801 | }, 802 | "execution_count": null, 803 | "outputs": [ 804 | { 805 | "output_type": "stream", 806 | "name": "stdout", 807 | "text": [ 808 | "Cross Validation accuracies for LogisticRegression(max_iter=1000) = [0.80327869 0.86885246 0.85245902 0.86666667 0.75 ]\n", 809 | "Accuracy % of the LogisticRegression(max_iter=1000) 82.83\n", 810 | "----------------------------------------------\n", 811 | "Cross Validation accuracies for SVC(kernel='linear') = [0.81967213 0.8852459 0.80327869 0.86666667 0.76666667]\n", 812 | "Accuracy % of the SVC(kernel='linear') 82.83\n", 813 | "----------------------------------------------\n", 814 | "Cross Validation accuracies for KNeighborsClassifier() = [0.60655738 0.6557377 0.57377049 0.73333333 0.65 ]\n", 815 | "Accuracy % of the KNeighborsClassifier() 64.39\n", 816 | "----------------------------------------------\n", 817 | "Cross Validation accuracies for RandomForestClassifier() = [0.81967213 0.8852459 0.7704918 0.83333333 0.76666667]\n", 818 | "Accuracy % of the RandomForestClassifier() 81.51\n", 819 | "----------------------------------------------\n" 820 | ] 821 | } 822 | ] 823 | }, 824 | { 825 | "cell_type": "code", 826 | "source": [], 827 | "metadata": { 828 | "id": "LRVoaEiLBx7V" 829 | }, 830 | "execution_count": null, 831 | "outputs": [] 832 | } 833 | ] 834 | } -------------------------------------------------------------------------------- /8_6_Model_Selection_in_ML_with_Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "collapsed_sections": [] 8 | }, 9 | "kernelspec": { 10 | "name": "python3", 11 | "display_name": "Python 3" 12 | }, 13 | "language_info": { 14 | "name": "python" 15 | } 16 | }, 17 | "cells": [ 18 | { 19 | "cell_type": "markdown", 20 | "source": [ 21 | "Importing the dependencies" 22 | ], 23 | "metadata": { 24 | "id": "n6aUe4VhqwOj" 25 | } 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": null, 30 | "metadata": { 31 | "id": "6eFgKfedIpHm" 32 | }, 33 | "outputs": [], 34 | "source": [ 35 | "import numpy as np\n", 36 | "import pandas as pd\n", 37 | "from sklearn.model_selection import cross_val_score\n", 38 | "from sklearn.model_selection import GridSearchCV" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "source": [ 44 | "# importing the models\n", 45 | "from sklearn.linear_model import LogisticRegression\n", 46 | "from sklearn.svm import SVC\n", 47 | "from sklearn.neighbors import KNeighborsClassifier\n", 48 | "from sklearn.ensemble import RandomForestClassifier" 49 | ], 50 | "metadata": { 51 | "id": "sHCGhgcErTI0" 52 | }, 53 | "execution_count": null, 54 | "outputs": [] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "source": [ 59 | "We will be working on the Heart Disease dataset" 60 | ], 61 | "metadata": { 62 | "id": "9mJdx-jlKLH4" 63 | } 64 | }, 65 | { 66 | "cell_type": "code", 67 | "source": [ 68 | "# loading the csv data to a Pandas DataFrame\n", 69 | "heart_data = pd.read_csv('/content/heart.csv')" 70 | ], 71 | "metadata": { 72 | "id": "_lmdeZiLJdGm" 73 | }, 74 | "execution_count": null, 75 | "outputs": [] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "source": [ 80 | "# print first 5 rows of the dataset\n", 81 | "heart_data.head()" 82 | ], 83 | "metadata": { 84 | "colab": { 85 | "base_uri": "https://localhost:8080/", 86 | "height": 206 87 | }, 88 | "id": "xeMBIvC_Osi4", 89 | "outputId": "114a150f-83ca-4ebd-81c1-5117db28ed38" 90 | }, 91 | "execution_count": null, 92 | "outputs": [ 93 | { 94 | "output_type": "execute_result", 95 | "data": { 96 | "text/plain": [ 97 | " age sex cp trestbps chol fbs restecg thalach exang oldpeak slope \\\n", 98 | "0 63 1 3 145 233 1 0 150 0 2.3 0 \n", 99 | "1 37 1 2 130 250 0 1 187 0 3.5 0 \n", 100 | "2 41 0 1 130 204 0 0 172 0 1.4 2 \n", 101 | "3 56 1 1 120 236 0 1 178 0 0.8 2 \n", 102 | "4 57 0 0 120 354 0 1 163 1 0.6 2 \n", 103 | "\n", 104 | " ca thal target \n", 105 | "0 0 1 1 \n", 106 | "1 0 2 1 \n", 107 | "2 0 2 1 \n", 108 | "3 0 2 1 \n", 109 | "4 0 2 1 " 110 | ], 111 | "text/html": [ 112 | "\n", 113 | "
\n", 114 | "
\n", 115 | "
\n", 116 | "\n", 129 | "\n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | " \n", 236 | "
agesexcptrestbpscholfbsrestecgthalachexangoldpeakslopecathaltarget
063131452331015002.30011
137121302500118703.50021
241011302040017201.42021
356111202360117800.82021
457001203540116310.62021
\n", 237 | "
\n", 238 | " \n", 248 | " \n", 249 | " \n", 286 | "\n", 287 | " \n", 311 | "
\n", 312 | "
\n", 313 | " " 314 | ] 315 | }, 316 | "metadata": {}, 317 | "execution_count": 4 318 | } 319 | ] 320 | }, 321 | { 322 | "cell_type": "code", 323 | "metadata": { 324 | "colab": { 325 | "base_uri": "https://localhost:8080/" 326 | }, 327 | "id": "8nX1tIzbrz0u", 328 | "outputId": "7918a49e-7797-4657-b74b-236dc43b54f3" 329 | }, 330 | "source": [ 331 | "# number of rows and columns in the dataset\n", 332 | "heart_data.shape" 333 | ], 334 | "execution_count": null, 335 | "outputs": [ 336 | { 337 | "output_type": "execute_result", 338 | "data": { 339 | "text/plain": [ 340 | "(303, 14)" 341 | ] 342 | }, 343 | "metadata": {}, 344 | "execution_count": 5 345 | } 346 | ] 347 | }, 348 | { 349 | "cell_type": "code", 350 | "metadata": { 351 | "colab": { 352 | "base_uri": "https://localhost:8080/" 353 | }, 354 | "id": "GjHtW31rsGlb", 355 | "outputId": "5cd0124d-9f43-4787-8716-44a4bf1541df" 356 | }, 357 | "source": [ 358 | "# checking for missing values\n", 359 | "heart_data.isnull().sum()" 360 | ], 361 | "execution_count": null, 362 | "outputs": [ 363 | { 364 | "output_type": "execute_result", 365 | "data": { 366 | "text/plain": [ 367 | "age 0\n", 368 | "sex 0\n", 369 | "cp 0\n", 370 | "trestbps 0\n", 371 | "chol 0\n", 372 | "fbs 0\n", 373 | "restecg 0\n", 374 | "thalach 0\n", 375 | "exang 0\n", 376 | "oldpeak 0\n", 377 | "slope 0\n", 378 | "ca 0\n", 379 | "thal 0\n", 380 | "target 0\n", 381 | "dtype: int64" 382 | ] 383 | }, 384 | "metadata": {}, 385 | "execution_count": 6 386 | } 387 | ] 388 | }, 389 | { 390 | "cell_type": "code", 391 | "metadata": { 392 | "colab": { 393 | "base_uri": "https://localhost:8080/" 394 | }, 395 | "id": "4InaOSIUsfWP", 396 | "outputId": "ea550fb1-ccf0-427c-c467-2b5d36bf7b72" 397 | }, 398 | "source": [ 399 | "# checking the distribution of Target Variable\n", 400 | "heart_data['target'].value_counts()" 401 | ], 402 | "execution_count": null, 403 | "outputs": [ 404 | { 405 | "output_type": "execute_result", 406 | "data": { 407 | "text/plain": [ 408 | "1 165\n", 409 | "0 138\n", 410 | "Name: target, dtype: int64" 411 | ] 412 | }, 413 | "metadata": {}, 414 | "execution_count": 7 415 | } 416 | ] 417 | }, 418 | { 419 | "cell_type": "markdown", 420 | "metadata": { 421 | "id": "aSOBu4qDtJy5" 422 | }, 423 | "source": [ 424 | "1 --> Defective Heart\n", 425 | "\n", 426 | "0 --> Healthy Heart" 427 | ] 428 | }, 429 | { 430 | "cell_type": "markdown", 431 | "metadata": { 432 | "id": "tW8i4igjtPRC" 433 | }, 434 | "source": [ 435 | "Splitting the Features and Target" 436 | ] 437 | }, 438 | { 439 | "cell_type": "code", 440 | "metadata": { 441 | "id": "Q6yfbswrs7m3" 442 | }, 443 | "source": [ 444 | "X = heart_data.drop(columns='target', axis=1)\n", 445 | "Y = heart_data['target']" 446 | ], 447 | "execution_count": null, 448 | "outputs": [] 449 | }, 450 | { 451 | "cell_type": "code", 452 | "metadata": { 453 | "colab": { 454 | "base_uri": "https://localhost:8080/" 455 | }, 456 | "id": "XJoCp4ZKtpZy", 457 | "outputId": "8ab1fe07-baa7-4c75-ac83-1c62f27e33f6" 458 | }, 459 | "source": [ 460 | "print(X)" 461 | ], 462 | "execution_count": null, 463 | "outputs": [ 464 | { 465 | "output_type": "stream", 466 | "name": "stdout", 467 | "text": [ 468 | " age sex cp trestbps chol fbs restecg thalach exang oldpeak \\\n", 469 | "0 63 1 3 145 233 1 0 150 0 2.3 \n", 470 | "1 37 1 2 130 250 0 1 187 0 3.5 \n", 471 | "2 41 0 1 130 204 0 0 172 0 1.4 \n", 472 | "3 56 1 1 120 236 0 1 178 0 0.8 \n", 473 | "4 57 0 0 120 354 0 1 163 1 0.6 \n", 474 | ".. ... ... .. ... ... ... ... ... ... ... \n", 475 | "298 57 0 0 140 241 0 1 123 1 0.2 \n", 476 | "299 45 1 3 110 264 0 1 132 0 1.2 \n", 477 | "300 68 1 0 144 193 1 1 141 0 3.4 \n", 478 | "301 57 1 0 130 131 0 1 115 1 1.2 \n", 479 | "302 57 0 1 130 236 0 0 174 0 0.0 \n", 480 | "\n", 481 | " slope ca thal \n", 482 | "0 0 0 1 \n", 483 | "1 0 0 2 \n", 484 | "2 2 0 2 \n", 485 | "3 2 0 2 \n", 486 | "4 2 0 2 \n", 487 | ".. ... .. ... \n", 488 | "298 1 0 3 \n", 489 | "299 1 0 3 \n", 490 | "300 1 2 3 \n", 491 | "301 1 1 3 \n", 492 | "302 1 1 2 \n", 493 | "\n", 494 | "[303 rows x 13 columns]\n" 495 | ] 496 | } 497 | ] 498 | }, 499 | { 500 | "cell_type": "code", 501 | "metadata": { 502 | "colab": { 503 | "base_uri": "https://localhost:8080/" 504 | }, 505 | "id": "nukuj-YItq1w", 506 | "outputId": "98f7e5ce-068a-4340-b739-c9b5947b2613" 507 | }, 508 | "source": [ 509 | "print(Y)" 510 | ], 511 | "execution_count": null, 512 | "outputs": [ 513 | { 514 | "output_type": "stream", 515 | "name": "stdout", 516 | "text": [ 517 | "0 1\n", 518 | "1 1\n", 519 | "2 1\n", 520 | "3 1\n", 521 | "4 1\n", 522 | " ..\n", 523 | "298 0\n", 524 | "299 0\n", 525 | "300 0\n", 526 | "301 0\n", 527 | "302 0\n", 528 | "Name: target, Length: 303, dtype: int64\n" 529 | ] 530 | } 531 | ] 532 | }, 533 | { 534 | "cell_type": "code", 535 | "source": [ 536 | " X = np.asarray(X)\n", 537 | " Y = np.asarray(Y)" 538 | ], 539 | "metadata": { 540 | "id": "4OFJBpqfTCjJ" 541 | }, 542 | "execution_count": null, 543 | "outputs": [] 544 | }, 545 | { 546 | "cell_type": "markdown", 547 | "source": [ 548 | "**Model Selection**" 549 | ], 550 | "metadata": { 551 | "id": "BHcyqvzw0c15" 552 | } 553 | }, 554 | { 555 | "cell_type": "markdown", 556 | "source": [ 557 | "1. Comparing the models with default hyperparameter values using Cross Validation" 558 | ], 559 | "metadata": { 560 | "id": "YE4gR8NbCDfz" 561 | } 562 | }, 563 | { 564 | "cell_type": "code", 565 | "source": [ 566 | "# list of models\n", 567 | "models = [LogisticRegression(max_iter=1000), SVC(kernel='linear'), KNeighborsClassifier(), RandomForestClassifier(random_state=0)]" 568 | ], 569 | "metadata": { 570 | "id": "D71G1BFz0emy" 571 | }, 572 | "execution_count": null, 573 | "outputs": [] 574 | }, 575 | { 576 | "cell_type": "code", 577 | "source": [ 578 | "def compare_models_cross_validation():\n", 579 | "\n", 580 | " for model in models:\n", 581 | "\n", 582 | " cv_score = cross_val_score(model, X, Y, cv=5)\n", 583 | " mean_accuracy = sum(cv_score)/len(cv_score)\n", 584 | " mean_accuracy = mean_accuracy*100\n", 585 | " mean_accuracy = round(mean_accuracy, 2)\n", 586 | "\n", 587 | " print('Cross Validation accuracies for the',model,'=', cv_score)\n", 588 | " print('Acccuracy score of the ',model,'=',mean_accuracy,'%')\n", 589 | " print('---------------------------------------------------------------')" 590 | ], 591 | "metadata": { 592 | "id": "rhY3ikQOC3rZ" 593 | }, 594 | "execution_count": null, 595 | "outputs": [] 596 | }, 597 | { 598 | "cell_type": "code", 599 | "source": [ 600 | "compare_models_cross_validation()" 601 | ], 602 | "metadata": { 603 | "colab": { 604 | "base_uri": "https://localhost:8080/" 605 | }, 606 | "id": "17dfatWwEwVW", 607 | "outputId": "b54c7253-ce1c-47d7-c5f3-bc1156943ff2" 608 | }, 609 | "execution_count": null, 610 | "outputs": [ 611 | { 612 | "output_type": "stream", 613 | "name": "stdout", 614 | "text": [ 615 | "Cross Validation accuracies for the LogisticRegression(max_iter=1000) = [0.80327869 0.8852459 0.85245902 0.86666667 0.75 ]\n", 616 | "Acccuracy score of the LogisticRegression(max_iter=1000) = 83.15 %\n", 617 | "---------------------------------------------------------------\n", 618 | "Cross Validation accuracies for the SVC(kernel='linear') = [0.81967213 0.8852459 0.80327869 0.86666667 0.76666667]\n", 619 | "Acccuracy score of the SVC(kernel='linear') = 82.83 %\n", 620 | "---------------------------------------------------------------\n", 621 | "Cross Validation accuracies for the KNeighborsClassifier() = [0.60655738 0.6557377 0.57377049 0.73333333 0.65 ]\n", 622 | "Acccuracy score of the KNeighborsClassifier() = 64.39 %\n", 623 | "---------------------------------------------------------------\n", 624 | "Cross Validation accuracies for the RandomForestClassifier(random_state=0) = [0.85245902 0.90163934 0.81967213 0.81666667 0.8 ]\n", 625 | "Acccuracy score of the RandomForestClassifier(random_state=0) = 83.81 %\n", 626 | "---------------------------------------------------------------\n" 627 | ] 628 | } 629 | ] 630 | }, 631 | { 632 | "cell_type": "markdown", 633 | "source": [ 634 | "Inference: For the Heart Disease dataset, **Random Forest Classifier** has the Highest accuracy value with default hyperparameter values" 635 | ], 636 | "metadata": { 637 | "id": "O-BZYtX6FtwZ" 638 | } 639 | }, 640 | { 641 | "cell_type": "markdown", 642 | "source": [ 643 | "2. Comparing the models with different Hyperparameter values using GridSearchCV" 644 | ], 645 | "metadata": { 646 | "id": "loKdk57gGWmR" 647 | } 648 | }, 649 | { 650 | "cell_type": "code", 651 | "source": [ 652 | "# list of models\n", 653 | "models_list = [LogisticRegression(max_iter=10000), SVC(), KNeighborsClassifier(), RandomForestClassifier(random_state=0)]" 654 | ], 655 | "metadata": { 656 | "id": "43Wq9FXWEzHn" 657 | }, 658 | "execution_count": null, 659 | "outputs": [] 660 | }, 661 | { 662 | "cell_type": "code", 663 | "source": [ 664 | "# creating a dictionary that contains hyperparameter values for the above mentioned models\n", 665 | "\n", 666 | "\n", 667 | "model_hyperparameters = {\n", 668 | " \n", 669 | "\n", 670 | " 'log_reg_hyperparameters': {\n", 671 | " \n", 672 | " 'C' : [1,5,10,20]\n", 673 | " },\n", 674 | "\n", 675 | " 'svc_hyperparameters': {\n", 676 | " \n", 677 | " 'kernel' : ['linear','poly','rbf','sigmoid'],\n", 678 | " 'C' : [1,5,10,20]\n", 679 | " },\n", 680 | "\n", 681 | "\n", 682 | " 'KNN_hyperparameters' : {\n", 683 | " \n", 684 | " 'n_neighbors' : [3,5,10]\n", 685 | " },\n", 686 | "\n", 687 | "\n", 688 | " 'random_forest_hyperparameters' : {\n", 689 | " \n", 690 | " 'n_estimators' : [10, 20, 50, 100]\n", 691 | " }\n", 692 | "}" 693 | ], 694 | "metadata": { 695 | "id": "zfODd_glGxnd" 696 | }, 697 | "execution_count": null, 698 | "outputs": [] 699 | }, 700 | { 701 | "cell_type": "code", 702 | "source": [ 703 | "type(model_hyperparameters)" 704 | ], 705 | "metadata": { 706 | "colab": { 707 | "base_uri": "https://localhost:8080/" 708 | }, 709 | "id": "uj9F-miFJATp", 710 | "outputId": "a5ea0055-e2eb-42fb-a237-a2b3e6a9f5d3" 711 | }, 712 | "execution_count": null, 713 | "outputs": [ 714 | { 715 | "output_type": "execute_result", 716 | "data": { 717 | "text/plain": [ 718 | "dict" 719 | ] 720 | }, 721 | "metadata": {}, 722 | "execution_count": 40 723 | } 724 | ] 725 | }, 726 | { 727 | "cell_type": "code", 728 | "source": [ 729 | "print(model_hyperparameters.keys())" 730 | ], 731 | "metadata": { 732 | "colab": { 733 | "base_uri": "https://localhost:8080/" 734 | }, 735 | "id": "ykAidRlaJrBx", 736 | "outputId": "c8b77598-91a2-4929-f340-8e27a6716c74" 737 | }, 738 | "execution_count": null, 739 | "outputs": [ 740 | { 741 | "output_type": "stream", 742 | "name": "stdout", 743 | "text": [ 744 | "dict_keys(['log_reg_hyperparameters', 'svc_hyperparameters', 'KNN_hyperparameters', 'random_forest_hyperparameters'])\n" 745 | ] 746 | } 747 | ] 748 | }, 749 | { 750 | "cell_type": "code", 751 | "source": [ 752 | "model_hyperparameters['log_reg_hyperparameters']" 753 | ], 754 | "metadata": { 755 | "colab": { 756 | "base_uri": "https://localhost:8080/" 757 | }, 758 | "id": "enerj0PaKDdM", 759 | "outputId": "4865421f-75e0-4b04-a7db-25985e77ba01" 760 | }, 761 | "execution_count": null, 762 | "outputs": [ 763 | { 764 | "output_type": "execute_result", 765 | "data": { 766 | "text/plain": [ 767 | "{'C': [1, 5, 10, 20]}" 768 | ] 769 | }, 770 | "metadata": {}, 771 | "execution_count": 50 772 | } 773 | ] 774 | }, 775 | { 776 | "cell_type": "code", 777 | "source": [ 778 | "model_keys = list(model_hyperparameters.keys())\n", 779 | "print(model_keys)" 780 | ], 781 | "metadata": { 782 | "colab": { 783 | "base_uri": "https://localhost:8080/" 784 | }, 785 | "id": "zYzP9-RzJ1J8", 786 | "outputId": "db1e33bb-a2f4-49e3-836e-91fec83313b9" 787 | }, 788 | "execution_count": null, 789 | "outputs": [ 790 | { 791 | "output_type": "stream", 792 | "name": "stdout", 793 | "text": [ 794 | "['log_reg_hyperparameters', 'svc_hyperparameters', 'KNN_hyperparameters', 'random_forest_hyperparameters']\n" 795 | ] 796 | } 797 | ] 798 | }, 799 | { 800 | "cell_type": "code", 801 | "source": [ 802 | "model_keys[0]" 803 | ], 804 | "metadata": { 805 | "colab": { 806 | "base_uri": "https://localhost:8080/", 807 | "height": 35 808 | }, 809 | "id": "umt2Y6DXKJrd", 810 | "outputId": "860770f2-4a81-466c-ed4f-1723fc9ec6b5" 811 | }, 812 | "execution_count": null, 813 | "outputs": [ 814 | { 815 | "output_type": "execute_result", 816 | "data": { 817 | "text/plain": [ 818 | "'log_reg_hyperparameters'" 819 | ], 820 | "application/vnd.google.colaboratory.intrinsic+json": { 821 | "type": "string" 822 | } 823 | }, 824 | "metadata": {}, 825 | "execution_count": 44 826 | } 827 | ] 828 | }, 829 | { 830 | "cell_type": "code", 831 | "source": [ 832 | "model_hyperparameters[model_keys[0]]" 833 | ], 834 | "metadata": { 835 | "colab": { 836 | "base_uri": "https://localhost:8080/" 837 | }, 838 | "id": "gssFvxkTKYCL", 839 | "outputId": "a44879a7-a7b1-47c9-d938-92d8645dff0e" 840 | }, 841 | "execution_count": null, 842 | "outputs": [ 843 | { 844 | "output_type": "execute_result", 845 | "data": { 846 | "text/plain": [ 847 | "{'C': [1, 5, 10, 20]}" 848 | ] 849 | }, 850 | "metadata": {}, 851 | "execution_count": 45 852 | } 853 | ] 854 | }, 855 | { 856 | "cell_type": "markdown", 857 | "source": [ 858 | "Applying GridSearchCV" 859 | ], 860 | "metadata": { 861 | "id": "F5Kl_MW8K5tr" 862 | } 863 | }, 864 | { 865 | "cell_type": "code", 866 | "source": [ 867 | "def ModelSelection(list_of_models, hyperparameters_dictionary):\n", 868 | "\n", 869 | " result = []\n", 870 | "\n", 871 | " i = 0\n", 872 | "\n", 873 | " for model in list_of_models:\n", 874 | "\n", 875 | " key = model_keys[i]\n", 876 | "\n", 877 | " params = hyperparameters_dictionary[key]\n", 878 | "\n", 879 | " i += 1\n", 880 | "\n", 881 | " print(model)\n", 882 | " print(params)\n", 883 | " print('---------------------------------')\n", 884 | "\n", 885 | "\n", 886 | " classifier = GridSearchCV(model, params, cv=5)\n", 887 | "\n", 888 | " # fitting the data to classifier\n", 889 | " classifier.fit(X,Y)\n", 890 | "\n", 891 | " result.append({\n", 892 | " 'model used' : model,\n", 893 | " 'highest score' : classifier.best_score_,\n", 894 | " 'best hyperparameters' : classifier.best_params_\n", 895 | " })\n", 896 | "\n", 897 | " result_dataframe = pd.DataFrame(result, columns = ['model used','highest score','best hyperparameters'])\n", 898 | "\n", 899 | " return result_dataframe" 900 | ], 901 | "metadata": { 902 | "id": "2x5dWxgaKnmW" 903 | }, 904 | "execution_count": null, 905 | "outputs": [] 906 | }, 907 | { 908 | "cell_type": "code", 909 | "source": [ 910 | "ModelSelection(models_list, model_hyperparameters)" 911 | ], 912 | "metadata": { 913 | "colab": { 914 | "base_uri": "https://localhost:8080/", 915 | "height": 383 916 | }, 917 | "id": "Mtfv4xkwNBd0", 918 | "outputId": "a6bc4fd3-86b2-4ef3-81ff-747944e86f89" 919 | }, 920 | "execution_count": null, 921 | "outputs": [ 922 | { 923 | "output_type": "stream", 924 | "name": "stdout", 925 | "text": [ 926 | "LogisticRegression(max_iter=10000)\n", 927 | "{'C': [1, 5, 10, 20]}\n", 928 | "---------------------------------\n", 929 | "SVC()\n", 930 | "{'kernel': ['linear', 'poly', 'rbf', 'sigmoid'], 'C': [1, 5, 10, 20]}\n", 931 | "---------------------------------\n", 932 | "KNeighborsClassifier()\n", 933 | "{'n_neighbors': [3, 5, 10]}\n", 934 | "---------------------------------\n", 935 | "RandomForestClassifier(random_state=0)\n", 936 | "{'n_estimators': [10, 20, 50, 100]}\n", 937 | "---------------------------------\n" 938 | ] 939 | }, 940 | { 941 | "output_type": "execute_result", 942 | "data": { 943 | "text/plain": [ 944 | " model used highest score \\\n", 945 | "0 LogisticRegression(max_iter=10000) 0.831585 \n", 946 | "1 SVC() 0.828306 \n", 947 | "2 KNeighborsClassifier() 0.643880 \n", 948 | "3 RandomForestClassifier(random_state=0) 0.838087 \n", 949 | "\n", 950 | " best hyperparameters \n", 951 | "0 {'C': 5} \n", 952 | "1 {'C': 1, 'kernel': 'linear'} \n", 953 | "2 {'n_neighbors': 5} \n", 954 | "3 {'n_estimators': 100} " 955 | ], 956 | "text/html": [ 957 | "\n", 958 | "
\n", 959 | "
\n", 960 | "
\n", 961 | "\n", 974 | "\n", 975 | " \n", 976 | " \n", 977 | " \n", 978 | " \n", 979 | " \n", 980 | " \n", 981 | " \n", 982 | " \n", 983 | " \n", 984 | " \n", 985 | " \n", 986 | " \n", 987 | " \n", 988 | " \n", 989 | " \n", 990 | " \n", 991 | " \n", 992 | " \n", 993 | " \n", 994 | " \n", 995 | " \n", 996 | " \n", 997 | " \n", 998 | " \n", 999 | " \n", 1000 | " \n", 1001 | " \n", 1002 | " \n", 1003 | " \n", 1004 | " \n", 1005 | " \n", 1006 | " \n", 1007 | " \n", 1008 | " \n", 1009 | "
model usedhighest scorebest hyperparameters
0LogisticRegression(max_iter=10000)0.831585{'C': 5}
1SVC()0.828306{'C': 1, 'kernel': 'linear'}
2KNeighborsClassifier()0.643880{'n_neighbors': 5}
3RandomForestClassifier(random_state=0)0.838087{'n_estimators': 100}
\n", 1010 | "
\n", 1011 | " \n", 1021 | " \n", 1022 | " \n", 1059 | "\n", 1060 | " \n", 1084 | "
\n", 1085 | "
\n", 1086 | " " 1087 | ] 1088 | }, 1089 | "metadata": {}, 1090 | "execution_count": 52 1091 | } 1092 | ] 1093 | }, 1094 | { 1095 | "cell_type": "markdown", 1096 | "source": [ 1097 | "Random Forest Classifier with n_estimators = 100 has the highest accuracy" 1098 | ], 1099 | "metadata": { 1100 | "id": "7ZOb0iQBPiZ8" 1101 | } 1102 | }, 1103 | { 1104 | "cell_type": "code", 1105 | "source": [], 1106 | "metadata": { 1107 | "id": "0hGHX4uONKgn" 1108 | }, 1109 | "execution_count": null, 1110 | "outputs": [] 1111 | } 1112 | ] 1113 | } -------------------------------------------------------------------------------- /Precision,_Recall,_F1_Score_Python_implementation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "collapsed_sections": [] 8 | }, 9 | "kernelspec": { 10 | "name": "python3", 11 | "display_name": "Python 3" 12 | }, 13 | "language_info": { 14 | "name": "python" 15 | } 16 | }, 17 | "cells": [ 18 | { 19 | "cell_type": "markdown", 20 | "source": [ 21 | "Importing the Dependencies" 22 | ], 23 | "metadata": { 24 | "id": "xgd0kvExWcAm" 25 | } 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": null, 30 | "metadata": { 31 | "id": "Yg0dYZpxUnnH" 32 | }, 33 | "outputs": [], 34 | "source": [ 35 | "import numpy as np\n", 36 | "import pandas as pd\n", 37 | "from sklearn.model_selection import train_test_split\n", 38 | "from sklearn.linear_model import LogisticRegression" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "source": [ 44 | "Data Collection & Processing" 45 | ], 46 | "metadata": { 47 | "id": "6C-ri2RfZINI" 48 | } 49 | }, 50 | { 51 | "cell_type": "code", 52 | "metadata": { 53 | "id": "0q-3-LkQrREV" 54 | }, 55 | "source": [ 56 | "# loading the csv data to a Pandas DataFrame\n", 57 | "heart_data = pd.read_csv('heart.csv')" 58 | ], 59 | "execution_count": null, 60 | "outputs": [] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "metadata": { 65 | "colab": { 66 | "base_uri": "https://localhost:8080/", 67 | "height": 206 68 | }, 69 | "id": "M8dQxSTqriWD", 70 | "outputId": "fb5a61f8-1a7e-48b2-8324-dec8280bde10" 71 | }, 72 | "source": [ 73 | "# print first 5 rows of the dataset\n", 74 | "heart_data.head()" 75 | ], 76 | "execution_count": null, 77 | "outputs": [ 78 | { 79 | "output_type": "execute_result", 80 | "data": { 81 | "text/plain": [ 82 | " age sex cp trestbps chol fbs restecg thalach exang oldpeak slope \\\n", 83 | "0 63 1 3 145 233 1 0 150 0 2.3 0 \n", 84 | "1 37 1 2 130 250 0 1 187 0 3.5 0 \n", 85 | "2 41 0 1 130 204 0 0 172 0 1.4 2 \n", 86 | "3 56 1 1 120 236 0 1 178 0 0.8 2 \n", 87 | "4 57 0 0 120 354 0 1 163 1 0.6 2 \n", 88 | "\n", 89 | " ca thal target \n", 90 | "0 0 1 1 \n", 91 | "1 0 2 1 \n", 92 | "2 0 2 1 \n", 93 | "3 0 2 1 \n", 94 | "4 0 2 1 " 95 | ], 96 | "text/html": [ 97 | "\n", 98 | "
\n", 99 | "
\n", 100 | "
\n", 101 | "\n", 114 | "\n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | "
agesexcptrestbpscholfbsrestecgthalachexangoldpeakslopecathaltarget
063131452331015002.30011
137121302500118703.50021
241011302040017201.42021
356111202360117800.82021
457001203540116310.62021
\n", 222 | "
\n", 223 | " \n", 233 | " \n", 234 | " \n", 271 | "\n", 272 | " \n", 296 | "
\n", 297 | "
\n", 298 | " " 299 | ] 300 | }, 301 | "metadata": {}, 302 | "execution_count": 3 303 | } 304 | ] 305 | }, 306 | { 307 | "cell_type": "code", 308 | "metadata": { 309 | "colab": { 310 | "base_uri": "https://localhost:8080/", 311 | "height": 206 312 | }, 313 | "id": "Fx_aCZDgrqdR", 314 | "outputId": "e4a5c735-f1cb-4a24-d522-66e6fe0181d6" 315 | }, 316 | "source": [ 317 | "# print last 5 rows of the dataset\n", 318 | "heart_data.tail()" 319 | ], 320 | "execution_count": null, 321 | "outputs": [ 322 | { 323 | "output_type": "execute_result", 324 | "data": { 325 | "text/plain": [ 326 | " age sex cp trestbps chol fbs restecg thalach exang oldpeak \\\n", 327 | "298 57 0 0 140 241 0 1 123 1 0.2 \n", 328 | "299 45 1 3 110 264 0 1 132 0 1.2 \n", 329 | "300 68 1 0 144 193 1 1 141 0 3.4 \n", 330 | "301 57 1 0 130 131 0 1 115 1 1.2 \n", 331 | "302 57 0 1 130 236 0 0 174 0 0.0 \n", 332 | "\n", 333 | " slope ca thal target \n", 334 | "298 1 0 3 0 \n", 335 | "299 1 0 3 0 \n", 336 | "300 1 2 3 0 \n", 337 | "301 1 1 3 0 \n", 338 | "302 1 1 2 0 " 339 | ], 340 | "text/html": [ 341 | "\n", 342 | "
\n", 343 | "
\n", 344 | "
\n", 345 | "\n", 358 | "\n", 359 | " \n", 360 | " \n", 361 | " \n", 362 | " \n", 363 | " \n", 364 | " \n", 365 | " \n", 366 | " \n", 367 | " \n", 368 | " \n", 369 | " \n", 370 | " \n", 371 | " \n", 372 | " \n", 373 | " \n", 374 | " \n", 375 | " \n", 376 | " \n", 377 | " \n", 378 | " \n", 379 | " \n", 380 | " \n", 381 | " \n", 382 | " \n", 383 | " \n", 384 | " \n", 385 | " \n", 386 | " \n", 387 | " \n", 388 | " \n", 389 | " \n", 390 | " \n", 391 | " \n", 392 | " \n", 393 | " \n", 394 | " \n", 395 | " \n", 396 | " \n", 397 | " \n", 398 | " \n", 399 | " \n", 400 | " \n", 401 | " \n", 402 | " \n", 403 | " \n", 404 | " \n", 405 | " \n", 406 | " \n", 407 | " \n", 408 | " \n", 409 | " \n", 410 | " \n", 411 | " \n", 412 | " \n", 413 | " \n", 414 | " \n", 415 | " \n", 416 | " \n", 417 | " \n", 418 | " \n", 419 | " \n", 420 | " \n", 421 | " \n", 422 | " \n", 423 | " \n", 424 | " \n", 425 | " \n", 426 | " \n", 427 | " \n", 428 | " \n", 429 | " \n", 430 | " \n", 431 | " \n", 432 | " \n", 433 | " \n", 434 | " \n", 435 | " \n", 436 | " \n", 437 | " \n", 438 | " \n", 439 | " \n", 440 | " \n", 441 | " \n", 442 | " \n", 443 | " \n", 444 | " \n", 445 | " \n", 446 | " \n", 447 | " \n", 448 | " \n", 449 | " \n", 450 | " \n", 451 | " \n", 452 | " \n", 453 | " \n", 454 | " \n", 455 | " \n", 456 | " \n", 457 | " \n", 458 | " \n", 459 | " \n", 460 | " \n", 461 | " \n", 462 | " \n", 463 | " \n", 464 | " \n", 465 | "
agesexcptrestbpscholfbsrestecgthalachexangoldpeakslopecathaltarget
29857001402410112310.21030
29945131102640113201.21030
30068101441931114103.41230
30157101301310111511.21130
30257011302360017400.01120
\n", 466 | "
\n", 467 | " \n", 477 | " \n", 478 | " \n", 515 | "\n", 516 | " \n", 540 | "
\n", 541 | "
\n", 542 | " " 543 | ] 544 | }, 545 | "metadata": {}, 546 | "execution_count": 4 547 | } 548 | ] 549 | }, 550 | { 551 | "cell_type": "code", 552 | "metadata": { 553 | "colab": { 554 | "base_uri": "https://localhost:8080/" 555 | }, 556 | "id": "8nX1tIzbrz0u", 557 | "outputId": "9833ad88-1626-477c-d363-045b919a5589" 558 | }, 559 | "source": [ 560 | "# number of rows and columns in the dataset\n", 561 | "heart_data.shape" 562 | ], 563 | "execution_count": null, 564 | "outputs": [ 565 | { 566 | "output_type": "execute_result", 567 | "data": { 568 | "text/plain": [ 569 | "(303, 14)" 570 | ] 571 | }, 572 | "metadata": {}, 573 | "execution_count": 5 574 | } 575 | ] 576 | }, 577 | { 578 | "cell_type": "code", 579 | "metadata": { 580 | "colab": { 581 | "base_uri": "https://localhost:8080/" 582 | }, 583 | "id": "7_xTcw1Sr6aJ", 584 | "outputId": "10d605fe-bbdd-4084-924f-d228f0b15221" 585 | }, 586 | "source": [ 587 | "# getting some info about the data\n", 588 | "heart_data.info()" 589 | ], 590 | "execution_count": null, 591 | "outputs": [ 592 | { 593 | "output_type": "stream", 594 | "name": "stdout", 595 | "text": [ 596 | "\n", 597 | "RangeIndex: 303 entries, 0 to 302\n", 598 | "Data columns (total 14 columns):\n", 599 | " # Column Non-Null Count Dtype \n", 600 | "--- ------ -------------- ----- \n", 601 | " 0 age 303 non-null int64 \n", 602 | " 1 sex 303 non-null int64 \n", 603 | " 2 cp 303 non-null int64 \n", 604 | " 3 trestbps 303 non-null int64 \n", 605 | " 4 chol 303 non-null int64 \n", 606 | " 5 fbs 303 non-null int64 \n", 607 | " 6 restecg 303 non-null int64 \n", 608 | " 7 thalach 303 non-null int64 \n", 609 | " 8 exang 303 non-null int64 \n", 610 | " 9 oldpeak 303 non-null float64\n", 611 | " 10 slope 303 non-null int64 \n", 612 | " 11 ca 303 non-null int64 \n", 613 | " 12 thal 303 non-null int64 \n", 614 | " 13 target 303 non-null int64 \n", 615 | "dtypes: float64(1), int64(13)\n", 616 | "memory usage: 33.3 KB\n" 617 | ] 618 | } 619 | ] 620 | }, 621 | { 622 | "cell_type": "code", 623 | "metadata": { 624 | "colab": { 625 | "base_uri": "https://localhost:8080/" 626 | }, 627 | "id": "GjHtW31rsGlb", 628 | "outputId": "ce7ae9fd-669e-4ff0-b0a4-59e44865ea16" 629 | }, 630 | "source": [ 631 | "# checking for missing values\n", 632 | "heart_data.isnull().sum()" 633 | ], 634 | "execution_count": null, 635 | "outputs": [ 636 | { 637 | "output_type": "execute_result", 638 | "data": { 639 | "text/plain": [ 640 | "age 0\n", 641 | "sex 0\n", 642 | "cp 0\n", 643 | "trestbps 0\n", 644 | "chol 0\n", 645 | "fbs 0\n", 646 | "restecg 0\n", 647 | "thalach 0\n", 648 | "exang 0\n", 649 | "oldpeak 0\n", 650 | "slope 0\n", 651 | "ca 0\n", 652 | "thal 0\n", 653 | "target 0\n", 654 | "dtype: int64" 655 | ] 656 | }, 657 | "metadata": {}, 658 | "execution_count": 7 659 | } 660 | ] 661 | }, 662 | { 663 | "cell_type": "code", 664 | "metadata": { 665 | "colab": { 666 | "base_uri": "https://localhost:8080/", 667 | "height": 364 668 | }, 669 | "id": "OHmcP7DJsSEP", 670 | "outputId": "6d87c7ab-216f-4abf-a304-84a4ae6a2661" 671 | }, 672 | "source": [ 673 | "# statistical measures about the data\n", 674 | "heart_data.describe()" 675 | ], 676 | "execution_count": null, 677 | "outputs": [ 678 | { 679 | "output_type": "execute_result", 680 | "data": { 681 | "text/plain": [ 682 | " age sex cp trestbps chol fbs \\\n", 683 | "count 303.000000 303.000000 303.000000 303.000000 303.000000 303.000000 \n", 684 | "mean 54.366337 0.683168 0.966997 131.623762 246.264026 0.148515 \n", 685 | "std 9.082101 0.466011 1.032052 17.538143 51.830751 0.356198 \n", 686 | "min 29.000000 0.000000 0.000000 94.000000 126.000000 0.000000 \n", 687 | "25% 47.500000 0.000000 0.000000 120.000000 211.000000 0.000000 \n", 688 | "50% 55.000000 1.000000 1.000000 130.000000 240.000000 0.000000 \n", 689 | "75% 61.000000 1.000000 2.000000 140.000000 274.500000 0.000000 \n", 690 | "max 77.000000 1.000000 3.000000 200.000000 564.000000 1.000000 \n", 691 | "\n", 692 | " restecg thalach exang oldpeak slope ca \\\n", 693 | "count 303.000000 303.000000 303.000000 303.000000 303.000000 303.000000 \n", 694 | "mean 0.528053 149.646865 0.326733 1.039604 1.399340 0.729373 \n", 695 | "std 0.525860 22.905161 0.469794 1.161075 0.616226 1.022606 \n", 696 | "min 0.000000 71.000000 0.000000 0.000000 0.000000 0.000000 \n", 697 | "25% 0.000000 133.500000 0.000000 0.000000 1.000000 0.000000 \n", 698 | "50% 1.000000 153.000000 0.000000 0.800000 1.000000 0.000000 \n", 699 | "75% 1.000000 166.000000 1.000000 1.600000 2.000000 1.000000 \n", 700 | "max 2.000000 202.000000 1.000000 6.200000 2.000000 4.000000 \n", 701 | "\n", 702 | " thal target \n", 703 | "count 303.000000 303.000000 \n", 704 | "mean 2.313531 0.544554 \n", 705 | "std 0.612277 0.498835 \n", 706 | "min 0.000000 0.000000 \n", 707 | "25% 2.000000 0.000000 \n", 708 | "50% 2.000000 1.000000 \n", 709 | "75% 3.000000 1.000000 \n", 710 | "max 3.000000 1.000000 " 711 | ], 712 | "text/html": [ 713 | "\n", 714 | "
\n", 715 | "
\n", 716 | "
\n", 717 | "\n", 730 | "\n", 731 | " \n", 732 | " \n", 733 | " \n", 734 | " \n", 735 | " \n", 736 | " \n", 737 | " \n", 738 | " \n", 739 | " \n", 740 | " \n", 741 | " \n", 742 | " \n", 743 | " \n", 744 | " \n", 745 | " \n", 746 | " \n", 747 | " \n", 748 | " \n", 749 | " \n", 750 | " \n", 751 | " \n", 752 | " \n", 753 | " \n", 754 | " \n", 755 | " \n", 756 | " \n", 757 | " \n", 758 | " \n", 759 | " \n", 760 | " \n", 761 | " \n", 762 | " \n", 763 | " \n", 764 | " \n", 765 | " \n", 766 | " \n", 767 | " \n", 768 | " \n", 769 | " \n", 770 | " \n", 771 | " \n", 772 | " \n", 773 | " \n", 774 | " \n", 775 | " \n", 776 | " \n", 777 | " \n", 778 | " \n", 779 | " \n", 780 | " \n", 781 | " \n", 782 | " \n", 783 | " \n", 784 | " \n", 785 | " \n", 786 | " \n", 787 | " \n", 788 | " \n", 789 | " \n", 790 | " \n", 791 | " \n", 792 | " \n", 793 | " \n", 794 | " \n", 795 | " \n", 796 | " \n", 797 | " \n", 798 | " \n", 799 | " \n", 800 | " \n", 801 | " \n", 802 | " \n", 803 | " \n", 804 | " \n", 805 | " \n", 806 | " \n", 807 | " \n", 808 | " \n", 809 | " \n", 810 | " \n", 811 | " \n", 812 | " \n", 813 | " \n", 814 | " \n", 815 | " \n", 816 | " \n", 817 | " \n", 818 | " \n", 819 | " \n", 820 | " \n", 821 | " \n", 822 | " \n", 823 | " \n", 824 | " \n", 825 | " \n", 826 | " \n", 827 | " \n", 828 | " \n", 829 | " \n", 830 | " \n", 831 | " \n", 832 | " \n", 833 | " \n", 834 | " \n", 835 | " \n", 836 | " \n", 837 | " \n", 838 | " \n", 839 | " \n", 840 | " \n", 841 | " \n", 842 | " \n", 843 | " \n", 844 | " \n", 845 | " \n", 846 | " \n", 847 | " \n", 848 | " \n", 849 | " \n", 850 | " \n", 851 | " \n", 852 | " \n", 853 | " \n", 854 | " \n", 855 | " \n", 856 | " \n", 857 | " \n", 858 | " \n", 859 | " \n", 860 | " \n", 861 | " \n", 862 | " \n", 863 | " \n", 864 | " \n", 865 | " \n", 866 | " \n", 867 | " \n", 868 | " \n", 869 | " \n", 870 | " \n", 871 | " \n", 872 | " \n", 873 | " \n", 874 | " \n", 875 | " \n", 876 | " \n", 877 | " \n", 878 | " \n", 879 | " \n", 880 | " \n", 881 | " \n", 882 | " \n", 883 | " \n", 884 | " \n", 885 | " \n", 886 | " \n", 887 | " \n", 888 | "
agesexcptrestbpscholfbsrestecgthalachexangoldpeakslopecathaltarget
count303.000000303.000000303.000000303.000000303.000000303.000000303.000000303.000000303.000000303.000000303.000000303.000000303.000000303.000000
mean54.3663370.6831680.966997131.623762246.2640260.1485150.528053149.6468650.3267331.0396041.3993400.7293732.3135310.544554
std9.0821010.4660111.03205217.53814351.8307510.3561980.52586022.9051610.4697941.1610750.6162261.0226060.6122770.498835
min29.0000000.0000000.00000094.000000126.0000000.0000000.00000071.0000000.0000000.0000000.0000000.0000000.0000000.000000
25%47.5000000.0000000.000000120.000000211.0000000.0000000.000000133.5000000.0000000.0000001.0000000.0000002.0000000.000000
50%55.0000001.0000001.000000130.000000240.0000000.0000001.000000153.0000000.0000000.8000001.0000000.0000002.0000001.000000
75%61.0000001.0000002.000000140.000000274.5000000.0000001.000000166.0000001.0000001.6000002.0000001.0000003.0000001.000000
max77.0000001.0000003.000000200.000000564.0000001.0000002.000000202.0000001.0000006.2000002.0000004.0000003.0000001.000000
\n", 889 | "
\n", 890 | " \n", 900 | " \n", 901 | " \n", 938 | "\n", 939 | " \n", 963 | "
\n", 964 | "
\n", 965 | " " 966 | ] 967 | }, 968 | "metadata": {}, 969 | "execution_count": 8 970 | } 971 | ] 972 | }, 973 | { 974 | "cell_type": "code", 975 | "metadata": { 976 | "colab": { 977 | "base_uri": "https://localhost:8080/" 978 | }, 979 | "id": "4InaOSIUsfWP", 980 | "outputId": "ad9d637a-8a1a-4435-881d-994f4f788d38" 981 | }, 982 | "source": [ 983 | "# checking the distribution of Target Variable\n", 984 | "heart_data['target'].value_counts()" 985 | ], 986 | "execution_count": null, 987 | "outputs": [ 988 | { 989 | "output_type": "execute_result", 990 | "data": { 991 | "text/plain": [ 992 | "1 165\n", 993 | "0 138\n", 994 | "Name: target, dtype: int64" 995 | ] 996 | }, 997 | "metadata": {}, 998 | "execution_count": 9 999 | } 1000 | ] 1001 | }, 1002 | { 1003 | "cell_type": "markdown", 1004 | "metadata": { 1005 | "id": "aSOBu4qDtJy5" 1006 | }, 1007 | "source": [ 1008 | "1 --> Defective Heart\n", 1009 | "\n", 1010 | "0 --> Healthy Heart" 1011 | ] 1012 | }, 1013 | { 1014 | "cell_type": "markdown", 1015 | "metadata": { 1016 | "id": "tW8i4igjtPRC" 1017 | }, 1018 | "source": [ 1019 | "Splitting the Features and Target" 1020 | ] 1021 | }, 1022 | { 1023 | "cell_type": "code", 1024 | "metadata": { 1025 | "id": "Q6yfbswrs7m3" 1026 | }, 1027 | "source": [ 1028 | "X = heart_data.drop(columns='target', axis=1)\n", 1029 | "Y = heart_data['target']" 1030 | ], 1031 | "execution_count": null, 1032 | "outputs": [] 1033 | }, 1034 | { 1035 | "cell_type": "code", 1036 | "metadata": { 1037 | "colab": { 1038 | "base_uri": "https://localhost:8080/" 1039 | }, 1040 | "id": "XJoCp4ZKtpZy", 1041 | "outputId": "516ecd1a-46a2-416f-9edc-3a05bd425ab9" 1042 | }, 1043 | "source": [ 1044 | "print(X)" 1045 | ], 1046 | "execution_count": null, 1047 | "outputs": [ 1048 | { 1049 | "output_type": "stream", 1050 | "name": "stdout", 1051 | "text": [ 1052 | " age sex cp trestbps chol fbs restecg thalach exang oldpeak \\\n", 1053 | "0 63 1 3 145 233 1 0 150 0 2.3 \n", 1054 | "1 37 1 2 130 250 0 1 187 0 3.5 \n", 1055 | "2 41 0 1 130 204 0 0 172 0 1.4 \n", 1056 | "3 56 1 1 120 236 0 1 178 0 0.8 \n", 1057 | "4 57 0 0 120 354 0 1 163 1 0.6 \n", 1058 | ".. ... ... .. ... ... ... ... ... ... ... \n", 1059 | "298 57 0 0 140 241 0 1 123 1 0.2 \n", 1060 | "299 45 1 3 110 264 0 1 132 0 1.2 \n", 1061 | "300 68 1 0 144 193 1 1 141 0 3.4 \n", 1062 | "301 57 1 0 130 131 0 1 115 1 1.2 \n", 1063 | "302 57 0 1 130 236 0 0 174 0 0.0 \n", 1064 | "\n", 1065 | " slope ca thal \n", 1066 | "0 0 0 1 \n", 1067 | "1 0 0 2 \n", 1068 | "2 2 0 2 \n", 1069 | "3 2 0 2 \n", 1070 | "4 2 0 2 \n", 1071 | ".. ... .. ... \n", 1072 | "298 1 0 3 \n", 1073 | "299 1 0 3 \n", 1074 | "300 1 2 3 \n", 1075 | "301 1 1 3 \n", 1076 | "302 1 1 2 \n", 1077 | "\n", 1078 | "[303 rows x 13 columns]\n" 1079 | ] 1080 | } 1081 | ] 1082 | }, 1083 | { 1084 | "cell_type": "code", 1085 | "metadata": { 1086 | "colab": { 1087 | "base_uri": "https://localhost:8080/" 1088 | }, 1089 | "id": "nukuj-YItq1w", 1090 | "outputId": "3c412e56-1867-42f7-e1d6-ea573b1ef4af" 1091 | }, 1092 | "source": [ 1093 | "print(Y)" 1094 | ], 1095 | "execution_count": null, 1096 | "outputs": [ 1097 | { 1098 | "output_type": "stream", 1099 | "name": "stdout", 1100 | "text": [ 1101 | "0 1\n", 1102 | "1 1\n", 1103 | "2 1\n", 1104 | "3 1\n", 1105 | "4 1\n", 1106 | " ..\n", 1107 | "298 0\n", 1108 | "299 0\n", 1109 | "300 0\n", 1110 | "301 0\n", 1111 | "302 0\n", 1112 | "Name: target, Length: 303, dtype: int64\n" 1113 | ] 1114 | } 1115 | ] 1116 | }, 1117 | { 1118 | "cell_type": "markdown", 1119 | "metadata": { 1120 | "id": "_EcjSE3Et18n" 1121 | }, 1122 | "source": [ 1123 | "Splitting the Data into Training data & Test Data" 1124 | ] 1125 | }, 1126 | { 1127 | "cell_type": "code", 1128 | "metadata": { 1129 | "id": "a-UUfRUxtuga" 1130 | }, 1131 | "source": [ 1132 | "X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, stratify=Y, random_state=2)" 1133 | ], 1134 | "execution_count": null, 1135 | "outputs": [] 1136 | }, 1137 | { 1138 | "cell_type": "code", 1139 | "metadata": { 1140 | "colab": { 1141 | "base_uri": "https://localhost:8080/" 1142 | }, 1143 | "id": "x7PrjC6zuf6X", 1144 | "outputId": "ebc6e966-5cfd-4b84-dd99-eee68f318454" 1145 | }, 1146 | "source": [ 1147 | "print(X.shape, X_train.shape, X_test.shape)" 1148 | ], 1149 | "execution_count": null, 1150 | "outputs": [ 1151 | { 1152 | "output_type": "stream", 1153 | "name": "stdout", 1154 | "text": [ 1155 | "(303, 13) (242, 13) (61, 13)\n" 1156 | ] 1157 | } 1158 | ] 1159 | }, 1160 | { 1161 | "cell_type": "markdown", 1162 | "metadata": { 1163 | "id": "beSkZmpVuvn9" 1164 | }, 1165 | "source": [ 1166 | "Model Training" 1167 | ] 1168 | }, 1169 | { 1170 | "cell_type": "code", 1171 | "metadata": { 1172 | "id": "4-Md74FYuqNL" 1173 | }, 1174 | "source": [ 1175 | "model = LogisticRegression(max_iter=1000)" 1176 | ], 1177 | "execution_count": null, 1178 | "outputs": [] 1179 | }, 1180 | { 1181 | "cell_type": "code", 1182 | "metadata": { 1183 | "colab": { 1184 | "base_uri": "https://localhost:8080/" 1185 | }, 1186 | "id": "kCdHYxGUu7XD", 1187 | "outputId": "88a60b92-f47a-4df2-f6cc-cebe41f33ef8" 1188 | }, 1189 | "source": [ 1190 | "# training the LogisticRegression model with Training data\n", 1191 | "model.fit(X_train, Y_train)" 1192 | ], 1193 | "execution_count": null, 1194 | "outputs": [ 1195 | { 1196 | "output_type": "execute_result", 1197 | "data": { 1198 | "text/plain": [ 1199 | "LogisticRegression(max_iter=1000)" 1200 | ] 1201 | }, 1202 | "metadata": {}, 1203 | "execution_count": 16 1204 | } 1205 | ] 1206 | }, 1207 | { 1208 | "cell_type": "markdown", 1209 | "metadata": { 1210 | "id": "ZYIw8Gi9vXfU" 1211 | }, 1212 | "source": [ 1213 | "Model Evaluation" 1214 | ] 1215 | }, 1216 | { 1217 | "cell_type": "markdown", 1218 | "metadata": { 1219 | "id": "wmxAekfZvZa9" 1220 | }, 1221 | "source": [ 1222 | "**Accuracy Score**" 1223 | ] 1224 | }, 1225 | { 1226 | "cell_type": "code", 1227 | "source": [ 1228 | "from sklearn.metrics import accuracy_score" 1229 | ], 1230 | "metadata": { 1231 | "id": "aMMAnoWYFQY5" 1232 | }, 1233 | "execution_count": null, 1234 | "outputs": [] 1235 | }, 1236 | { 1237 | "cell_type": "code", 1238 | "metadata": { 1239 | "id": "g19JaUTMvPKy", 1240 | "colab": { 1241 | "base_uri": "https://localhost:8080/" 1242 | }, 1243 | "outputId": "bc2da15b-efbe-449e-c1c7-733b11deb097" 1244 | }, 1245 | "source": [ 1246 | "# accuracy on training data\n", 1247 | "X_train_prediction = model.predict(X_train)\n", 1248 | "training_data_accuracy = accuracy_score(Y_train, X_train_prediction)\n", 1249 | "print(training_data_accuracy)" 1250 | ], 1251 | "execution_count": null, 1252 | "outputs": [ 1253 | { 1254 | "output_type": "stream", 1255 | "name": "stdout", 1256 | "text": [ 1257 | "0.8553719008264463\n" 1258 | ] 1259 | } 1260 | ] 1261 | }, 1262 | { 1263 | "cell_type": "code", 1264 | "metadata": { 1265 | "colab": { 1266 | "base_uri": "https://localhost:8080/" 1267 | }, 1268 | "id": "uQBZvBh8v7R_", 1269 | "outputId": "fec6bfaf-83cf-4a6c-e75d-6c91cc256409" 1270 | }, 1271 | "source": [ 1272 | "print('Accuracy on Training data : ', round(training_data_accuracy*100, 2), '%')" 1273 | ], 1274 | "execution_count": null, 1275 | "outputs": [ 1276 | { 1277 | "output_type": "stream", 1278 | "name": "stdout", 1279 | "text": [ 1280 | "Accuracy on Training data : 85.54 %\n" 1281 | ] 1282 | } 1283 | ] 1284 | }, 1285 | { 1286 | "cell_type": "code", 1287 | "metadata": { 1288 | "id": "mDONDJdlwBIO", 1289 | "colab": { 1290 | "base_uri": "https://localhost:8080/" 1291 | }, 1292 | "outputId": "4326f2ea-4f90-4b72-85dd-2d66ad9ff430" 1293 | }, 1294 | "source": [ 1295 | "# accuracy on test data\n", 1296 | "X_test_prediction = model.predict(X_test)\n", 1297 | "test_data_accuracy = accuracy_score(Y_test, X_test_prediction)\n", 1298 | "print(test_data_accuracy)" 1299 | ], 1300 | "execution_count": null, 1301 | "outputs": [ 1302 | { 1303 | "output_type": "stream", 1304 | "name": "stdout", 1305 | "text": [ 1306 | "0.8032786885245902\n" 1307 | ] 1308 | } 1309 | ] 1310 | }, 1311 | { 1312 | "cell_type": "code", 1313 | "metadata": { 1314 | "colab": { 1315 | "base_uri": "https://localhost:8080/" 1316 | }, 1317 | "id": "_MBS-OqdwYpf", 1318 | "outputId": "d001ccf6-78ae-4163-b228-e4447ca18f23" 1319 | }, 1320 | "source": [ 1321 | "print('Accuracy on Test data : ', round(test_data_accuracy*100, 2), '%')" 1322 | ], 1323 | "execution_count": null, 1324 | "outputs": [ 1325 | { 1326 | "output_type": "stream", 1327 | "name": "stdout", 1328 | "text": [ 1329 | "Accuracy on Test data : 80.33 %\n" 1330 | ] 1331 | } 1332 | ] 1333 | }, 1334 | { 1335 | "cell_type": "markdown", 1336 | "source": [ 1337 | "**Precision**" 1338 | ], 1339 | "metadata": { 1340 | "id": "FSTrUVcRZwCw" 1341 | } 1342 | }, 1343 | { 1344 | "cell_type": "markdown", 1345 | "source": [ 1346 | "Precision is the ratio of number of True Positive to the total number of Predicted Positive. It measures, out of the total predicted positive, how many are actually positive." 1347 | ], 1348 | "metadata": { 1349 | "id": "UHh_Fs8FbaaD" 1350 | } 1351 | }, 1352 | { 1353 | "cell_type": "code", 1354 | "source": [ 1355 | "from sklearn.metrics import precision_score" 1356 | ], 1357 | "metadata": { 1358 | "id": "ewiHzUzMTjSy" 1359 | }, 1360 | "execution_count": null, 1361 | "outputs": [] 1362 | }, 1363 | { 1364 | "cell_type": "code", 1365 | "source": [ 1366 | "# precision for training data predictions\n", 1367 | "precision_train = precision_score(Y_train, X_train_prediction)\n", 1368 | "print('Training data Precision =', precision_train)" 1369 | ], 1370 | "metadata": { 1371 | "colab": { 1372 | "base_uri": "https://localhost:8080/" 1373 | }, 1374 | "id": "IgRFBRkqX3HA", 1375 | "outputId": "9805e399-f18b-4c16-b39d-85ef4cbb4c28" 1376 | }, 1377 | "execution_count": null, 1378 | "outputs": [ 1379 | { 1380 | "output_type": "stream", 1381 | "name": "stdout", 1382 | "text": [ 1383 | "Training data Precision = 0.8299319727891157\n" 1384 | ] 1385 | } 1386 | ] 1387 | }, 1388 | { 1389 | "cell_type": "code", 1390 | "source": [ 1391 | "# precision for test data predictions\n", 1392 | "precision_test = precision_score(Y_test, X_test_prediction)\n", 1393 | "print('Test data Precision =', precision_test)" 1394 | ], 1395 | "metadata": { 1396 | "colab": { 1397 | "base_uri": "https://localhost:8080/" 1398 | }, 1399 | "id": "ZwHkEDrvZLVO", 1400 | "outputId": "a31614ba-eba1-4cb1-ccee-c07f01f6b0af" 1401 | }, 1402 | "execution_count": null, 1403 | "outputs": [ 1404 | { 1405 | "output_type": "stream", 1406 | "name": "stdout", 1407 | "text": [ 1408 | "Test data Precision = 0.8181818181818182\n" 1409 | ] 1410 | } 1411 | ] 1412 | }, 1413 | { 1414 | "cell_type": "markdown", 1415 | "source": [ 1416 | "**Recall**" 1417 | ], 1418 | "metadata": { 1419 | "id": "w2ciOBvubQCO" 1420 | } 1421 | }, 1422 | { 1423 | "cell_type": "markdown", 1424 | "source": [ 1425 | "Recall is the ratio of number of True Positive to the total number of Actual Positive. It measures, out of the total actual positive, how many are predicted as True Positive." 1426 | ], 1427 | "metadata": { 1428 | "id": "MmnuwGfibtYV" 1429 | } 1430 | }, 1431 | { 1432 | "cell_type": "code", 1433 | "source": [ 1434 | "from sklearn.metrics import recall_score" 1435 | ], 1436 | "metadata": { 1437 | "id": "T5bYBiioTkwI" 1438 | }, 1439 | "execution_count": null, 1440 | "outputs": [] 1441 | }, 1442 | { 1443 | "cell_type": "code", 1444 | "source": [ 1445 | "# recall for training data predictions\n", 1446 | "recall_train = recall_score(Y_train, X_train_prediction)\n", 1447 | "print('Training data Recall =', recall_train)" 1448 | ], 1449 | "metadata": { 1450 | "colab": { 1451 | "base_uri": "https://localhost:8080/" 1452 | }, 1453 | "id": "70bDi6xmZn14", 1454 | "outputId": "f1968195-cd44-4248-c060-e9565b91185e" 1455 | }, 1456 | "execution_count": null, 1457 | "outputs": [ 1458 | { 1459 | "output_type": "stream", 1460 | "name": "stdout", 1461 | "text": [ 1462 | "Training data Recall = 0.9242424242424242\n" 1463 | ] 1464 | } 1465 | ] 1466 | }, 1467 | { 1468 | "cell_type": "code", 1469 | "source": [ 1470 | "# recall for test data predictions\n", 1471 | "recall_test = recall_score(Y_test, X_test_prediction)\n", 1472 | "print('Test data Recall =', recall_test)" 1473 | ], 1474 | "metadata": { 1475 | "colab": { 1476 | "base_uri": "https://localhost:8080/" 1477 | }, 1478 | "id": "ci9n7r01ZqE5", 1479 | "outputId": "ecea1b81-89a8-402b-a2d7-9ce16bb631d3" 1480 | }, 1481 | "execution_count": null, 1482 | "outputs": [ 1483 | { 1484 | "output_type": "stream", 1485 | "name": "stdout", 1486 | "text": [ 1487 | "Test data Recall = 0.8181818181818182\n" 1488 | ] 1489 | } 1490 | ] 1491 | }, 1492 | { 1493 | "cell_type": "markdown", 1494 | "source": [ 1495 | "**F1 Score**" 1496 | ], 1497 | "metadata": { 1498 | "id": "MBYUgKOLck-_" 1499 | } 1500 | }, 1501 | { 1502 | "cell_type": "markdown", 1503 | "source": [ 1504 | "F1 Score is an important evaluation metric for binary classification that combines Precision & Recall. F1 Score is the harmonic mean of Precision & Recall." 1505 | ], 1506 | "metadata": { 1507 | "id": "YIudfNwmgCjs" 1508 | } 1509 | }, 1510 | { 1511 | "cell_type": "code", 1512 | "source": [ 1513 | "from sklearn.metrics import f1_score" 1514 | ], 1515 | "metadata": { 1516 | "id": "pP9PIZscaFm0" 1517 | }, 1518 | "execution_count": null, 1519 | "outputs": [] 1520 | }, 1521 | { 1522 | "cell_type": "code", 1523 | "source": [ 1524 | "# F1 score for training data predictions\n", 1525 | "f1_score_train = f1_score(Y_train, X_train_prediction)\n", 1526 | "print('Training data F1 Score =', f1_score_train)" 1527 | ], 1528 | "metadata": { 1529 | "colab": { 1530 | "base_uri": "https://localhost:8080/" 1531 | }, 1532 | "outputId": "04695f71-0f67-425c-cca9-2a618ecc43f5", 1533 | "id": "oHwExAAtaFm8" 1534 | }, 1535 | "execution_count": null, 1536 | "outputs": [ 1537 | { 1538 | "output_type": "stream", 1539 | "name": "stdout", 1540 | "text": [ 1541 | "Training data F1 Score = 0.8745519713261649\n" 1542 | ] 1543 | } 1544 | ] 1545 | }, 1546 | { 1547 | "cell_type": "code", 1548 | "source": [ 1549 | "# F1 Score for test data predictions\n", 1550 | "f1_score_test = recall_score(Y_test, X_test_prediction)\n", 1551 | "print('Test data F1 Score =', f1_score_test)" 1552 | ], 1553 | "metadata": { 1554 | "colab": { 1555 | "base_uri": "https://localhost:8080/" 1556 | }, 1557 | "outputId": "13266b05-9f52-41d2-ee43-ba7b3b138809", 1558 | "id": "n628BUyvaFm9" 1559 | }, 1560 | "execution_count": null, 1561 | "outputs": [ 1562 | { 1563 | "output_type": "stream", 1564 | "name": "stdout", 1565 | "text": [ 1566 | "Test data F1 Score = 0.8181818181818182\n" 1567 | ] 1568 | } 1569 | ] 1570 | }, 1571 | { 1572 | "cell_type": "markdown", 1573 | "source": [ 1574 | "**Precision, Recall, & F1 Score - function**" 1575 | ], 1576 | "metadata": { 1577 | "id": "5tH0z-JUa76n" 1578 | } 1579 | }, 1580 | { 1581 | "cell_type": "code", 1582 | "source": [ 1583 | "def precision_recall_f1_score(true_labels, pred_labels):\n", 1584 | "\n", 1585 | " precision_value = precision_score(true_labels, pred_labels)\n", 1586 | " recall_value = recall_score(true_labels, pred_labels)\n", 1587 | " f1_score_value = f1_score(true_labels, pred_labels)\n", 1588 | "\n", 1589 | " print('Precision =',precision_value)\n", 1590 | " print('Recall =',recall_value)\n", 1591 | " print('F1 Score =',f1_score_value)" 1592 | ], 1593 | "metadata": { 1594 | "id": "xGPnMqsdfMay" 1595 | }, 1596 | "execution_count": null, 1597 | "outputs": [] 1598 | }, 1599 | { 1600 | "cell_type": "code", 1601 | "source": [ 1602 | "# classification metrics for training data\n", 1603 | "precision_recall_f1_score(Y_train, X_train_prediction)" 1604 | ], 1605 | "metadata": { 1606 | "colab": { 1607 | "base_uri": "https://localhost:8080/" 1608 | }, 1609 | "id": "hTOAPCDEb5FB", 1610 | "outputId": "dc71c805-de04-4e54-ea1d-3a642853c35f" 1611 | }, 1612 | "execution_count": null, 1613 | "outputs": [ 1614 | { 1615 | "output_type": "stream", 1616 | "name": "stdout", 1617 | "text": [ 1618 | "Precision = 0.8299319727891157\n", 1619 | "Recall = 0.9242424242424242\n", 1620 | "F1 Score = 0.8745519713261649\n" 1621 | ] 1622 | } 1623 | ] 1624 | }, 1625 | { 1626 | "cell_type": "code", 1627 | "source": [ 1628 | "# classification metrics for test data\n", 1629 | "precision_recall_f1_score(Y_test, X_test_prediction)" 1630 | ], 1631 | "metadata": { 1632 | "colab": { 1633 | "base_uri": "https://localhost:8080/" 1634 | }, 1635 | "id": "kr20IWwicIdq", 1636 | "outputId": "e400f2fc-9b8f-4728-f2db-2a22deb9e650" 1637 | }, 1638 | "execution_count": null, 1639 | "outputs": [ 1640 | { 1641 | "output_type": "stream", 1642 | "name": "stdout", 1643 | "text": [ 1644 | "Precision = 0.8181818181818182\n", 1645 | "Recall = 0.8181818181818182\n", 1646 | "F1 Score = 0.8181818181818182\n" 1647 | ] 1648 | } 1649 | ] 1650 | }, 1651 | { 1652 | "cell_type": "code", 1653 | "source": [], 1654 | "metadata": { 1655 | "id": "W6gtqxPkcR01" 1656 | }, 1657 | "execution_count": null, 1658 | "outputs": [] 1659 | } 1660 | ] 1661 | } -------------------------------------------------------------------------------- /Accuracy_score_and_Confusion_Matrix.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "collapsed_sections": [] 8 | }, 9 | "kernelspec": { 10 | "name": "python3", 11 | "display_name": "Python 3" 12 | }, 13 | "language_info": { 14 | "name": "python" 15 | } 16 | }, 17 | "cells": [ 18 | { 19 | "cell_type": "markdown", 20 | "metadata": { 21 | "id": "aTb-9TFFqprC" 22 | }, 23 | "source": [ 24 | "Importing the Dependencies" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "metadata": { 30 | "id": "3q9U3S_whh3-" 31 | }, 32 | "source": [ 33 | "import numpy as np\n", 34 | "import pandas as pd\n", 35 | "from sklearn.model_selection import train_test_split\n", 36 | "from sklearn.linear_model import LogisticRegression" 37 | ], 38 | "execution_count": null, 39 | "outputs": [] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": { 44 | "id": "egMd5zeurTMR" 45 | }, 46 | "source": [ 47 | "Data Collection and Processing" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "metadata": { 53 | "id": "0q-3-LkQrREV" 54 | }, 55 | "source": [ 56 | "# loading the csv data to a Pandas DataFrame\n", 57 | "heart_data = pd.read_csv('heart.csv')" 58 | ], 59 | "execution_count": null, 60 | "outputs": [] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "metadata": { 65 | "colab": { 66 | "base_uri": "https://localhost:8080/", 67 | "height": 206 68 | }, 69 | "id": "M8dQxSTqriWD", 70 | "outputId": "d603ff60-b730-4e5f-dc02-834978b234d9" 71 | }, 72 | "source": [ 73 | "# print first 5 rows of the dataset\n", 74 | "heart_data.head()" 75 | ], 76 | "execution_count": null, 77 | "outputs": [ 78 | { 79 | "output_type": "execute_result", 80 | "data": { 81 | "text/plain": [ 82 | " age sex cp trestbps chol fbs restecg thalach exang oldpeak slope \\\n", 83 | "0 63 1 3 145 233 1 0 150 0 2.3 0 \n", 84 | "1 37 1 2 130 250 0 1 187 0 3.5 0 \n", 85 | "2 41 0 1 130 204 0 0 172 0 1.4 2 \n", 86 | "3 56 1 1 120 236 0 1 178 0 0.8 2 \n", 87 | "4 57 0 0 120 354 0 1 163 1 0.6 2 \n", 88 | "\n", 89 | " ca thal target \n", 90 | "0 0 1 1 \n", 91 | "1 0 2 1 \n", 92 | "2 0 2 1 \n", 93 | "3 0 2 1 \n", 94 | "4 0 2 1 " 95 | ], 96 | "text/html": [ 97 | "\n", 98 | "
\n", 99 | "
\n", 100 | "
\n", 101 | "\n", 114 | "\n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | "
agesexcptrestbpscholfbsrestecgthalachexangoldpeakslopecathaltarget
063131452331015002.30011
137121302500118703.50021
241011302040017201.42021
356111202360117800.82021
457001203540116310.62021
\n", 222 | "
\n", 223 | " \n", 233 | " \n", 234 | " \n", 271 | "\n", 272 | " \n", 296 | "
\n", 297 | "
\n", 298 | " " 299 | ] 300 | }, 301 | "metadata": {}, 302 | "execution_count": 3 303 | } 304 | ] 305 | }, 306 | { 307 | "cell_type": "code", 308 | "metadata": { 309 | "colab": { 310 | "base_uri": "https://localhost:8080/", 311 | "height": 206 312 | }, 313 | "id": "Fx_aCZDgrqdR", 314 | "outputId": "cf89729f-96e1-4087-b473-d164e0583a3b" 315 | }, 316 | "source": [ 317 | "# print last 5 rows of the dataset\n", 318 | "heart_data.tail()" 319 | ], 320 | "execution_count": null, 321 | "outputs": [ 322 | { 323 | "output_type": "execute_result", 324 | "data": { 325 | "text/plain": [ 326 | " age sex cp trestbps chol fbs restecg thalach exang oldpeak \\\n", 327 | "298 57 0 0 140 241 0 1 123 1 0.2 \n", 328 | "299 45 1 3 110 264 0 1 132 0 1.2 \n", 329 | "300 68 1 0 144 193 1 1 141 0 3.4 \n", 330 | "301 57 1 0 130 131 0 1 115 1 1.2 \n", 331 | "302 57 0 1 130 236 0 0 174 0 0.0 \n", 332 | "\n", 333 | " slope ca thal target \n", 334 | "298 1 0 3 0 \n", 335 | "299 1 0 3 0 \n", 336 | "300 1 2 3 0 \n", 337 | "301 1 1 3 0 \n", 338 | "302 1 1 2 0 " 339 | ], 340 | "text/html": [ 341 | "\n", 342 | "
\n", 343 | "
\n", 344 | "
\n", 345 | "\n", 358 | "\n", 359 | " \n", 360 | " \n", 361 | " \n", 362 | " \n", 363 | " \n", 364 | " \n", 365 | " \n", 366 | " \n", 367 | " \n", 368 | " \n", 369 | " \n", 370 | " \n", 371 | " \n", 372 | " \n", 373 | " \n", 374 | " \n", 375 | " \n", 376 | " \n", 377 | " \n", 378 | " \n", 379 | " \n", 380 | " \n", 381 | " \n", 382 | " \n", 383 | " \n", 384 | " \n", 385 | " \n", 386 | " \n", 387 | " \n", 388 | " \n", 389 | " \n", 390 | " \n", 391 | " \n", 392 | " \n", 393 | " \n", 394 | " \n", 395 | " \n", 396 | " \n", 397 | " \n", 398 | " \n", 399 | " \n", 400 | " \n", 401 | " \n", 402 | " \n", 403 | " \n", 404 | " \n", 405 | " \n", 406 | " \n", 407 | " \n", 408 | " \n", 409 | " \n", 410 | " \n", 411 | " \n", 412 | " \n", 413 | " \n", 414 | " \n", 415 | " \n", 416 | " \n", 417 | " \n", 418 | " \n", 419 | " \n", 420 | " \n", 421 | " \n", 422 | " \n", 423 | " \n", 424 | " \n", 425 | " \n", 426 | " \n", 427 | " \n", 428 | " \n", 429 | " \n", 430 | " \n", 431 | " \n", 432 | " \n", 433 | " \n", 434 | " \n", 435 | " \n", 436 | " \n", 437 | " \n", 438 | " \n", 439 | " \n", 440 | " \n", 441 | " \n", 442 | " \n", 443 | " \n", 444 | " \n", 445 | " \n", 446 | " \n", 447 | " \n", 448 | " \n", 449 | " \n", 450 | " \n", 451 | " \n", 452 | " \n", 453 | " \n", 454 | " \n", 455 | " \n", 456 | " \n", 457 | " \n", 458 | " \n", 459 | " \n", 460 | " \n", 461 | " \n", 462 | " \n", 463 | " \n", 464 | " \n", 465 | "
agesexcptrestbpscholfbsrestecgthalachexangoldpeakslopecathaltarget
29857001402410112310.21030
29945131102640113201.21030
30068101441931114103.41230
30157101301310111511.21130
30257011302360017400.01120
\n", 466 | "
\n", 467 | " \n", 477 | " \n", 478 | " \n", 515 | "\n", 516 | " \n", 540 | "
\n", 541 | "
\n", 542 | " " 543 | ] 544 | }, 545 | "metadata": {}, 546 | "execution_count": 4 547 | } 548 | ] 549 | }, 550 | { 551 | "cell_type": "code", 552 | "metadata": { 553 | "colab": { 554 | "base_uri": "https://localhost:8080/" 555 | }, 556 | "id": "8nX1tIzbrz0u", 557 | "outputId": "56f1381e-f062-447b-8507-7aaad7be906f" 558 | }, 559 | "source": [ 560 | "# number of rows and columns in the dataset\n", 561 | "heart_data.shape" 562 | ], 563 | "execution_count": null, 564 | "outputs": [ 565 | { 566 | "output_type": "execute_result", 567 | "data": { 568 | "text/plain": [ 569 | "(303, 14)" 570 | ] 571 | }, 572 | "metadata": {}, 573 | "execution_count": 5 574 | } 575 | ] 576 | }, 577 | { 578 | "cell_type": "code", 579 | "metadata": { 580 | "colab": { 581 | "base_uri": "https://localhost:8080/" 582 | }, 583 | "id": "7_xTcw1Sr6aJ", 584 | "outputId": "02954844-fd60-407f-8bae-1f1fe73ffa16" 585 | }, 586 | "source": [ 587 | "# getting some info about the data\n", 588 | "heart_data.info()" 589 | ], 590 | "execution_count": null, 591 | "outputs": [ 592 | { 593 | "output_type": "stream", 594 | "name": "stdout", 595 | "text": [ 596 | "\n", 597 | "RangeIndex: 303 entries, 0 to 302\n", 598 | "Data columns (total 14 columns):\n", 599 | " # Column Non-Null Count Dtype \n", 600 | "--- ------ -------------- ----- \n", 601 | " 0 age 303 non-null int64 \n", 602 | " 1 sex 303 non-null int64 \n", 603 | " 2 cp 303 non-null int64 \n", 604 | " 3 trestbps 303 non-null int64 \n", 605 | " 4 chol 303 non-null int64 \n", 606 | " 5 fbs 303 non-null int64 \n", 607 | " 6 restecg 303 non-null int64 \n", 608 | " 7 thalach 303 non-null int64 \n", 609 | " 8 exang 303 non-null int64 \n", 610 | " 9 oldpeak 303 non-null float64\n", 611 | " 10 slope 303 non-null int64 \n", 612 | " 11 ca 303 non-null int64 \n", 613 | " 12 thal 303 non-null int64 \n", 614 | " 13 target 303 non-null int64 \n", 615 | "dtypes: float64(1), int64(13)\n", 616 | "memory usage: 33.3 KB\n" 617 | ] 618 | } 619 | ] 620 | }, 621 | { 622 | "cell_type": "code", 623 | "metadata": { 624 | "colab": { 625 | "base_uri": "https://localhost:8080/" 626 | }, 627 | "id": "GjHtW31rsGlb", 628 | "outputId": "d1edce51-05e9-44aa-8d5f-b266fee0b634" 629 | }, 630 | "source": [ 631 | "# checking for missing values\n", 632 | "heart_data.isnull().sum()" 633 | ], 634 | "execution_count": null, 635 | "outputs": [ 636 | { 637 | "output_type": "execute_result", 638 | "data": { 639 | "text/plain": [ 640 | "age 0\n", 641 | "sex 0\n", 642 | "cp 0\n", 643 | "trestbps 0\n", 644 | "chol 0\n", 645 | "fbs 0\n", 646 | "restecg 0\n", 647 | "thalach 0\n", 648 | "exang 0\n", 649 | "oldpeak 0\n", 650 | "slope 0\n", 651 | "ca 0\n", 652 | "thal 0\n", 653 | "target 0\n", 654 | "dtype: int64" 655 | ] 656 | }, 657 | "metadata": {}, 658 | "execution_count": 7 659 | } 660 | ] 661 | }, 662 | { 663 | "cell_type": "code", 664 | "metadata": { 665 | "colab": { 666 | "base_uri": "https://localhost:8080/", 667 | "height": 364 668 | }, 669 | "id": "OHmcP7DJsSEP", 670 | "outputId": "04cf61ff-fd64-4211-b575-6d49d5e566ff" 671 | }, 672 | "source": [ 673 | "# statistical measures about the data\n", 674 | "heart_data.describe()" 675 | ], 676 | "execution_count": null, 677 | "outputs": [ 678 | { 679 | "output_type": "execute_result", 680 | "data": { 681 | "text/plain": [ 682 | " age sex cp trestbps chol fbs \\\n", 683 | "count 303.000000 303.000000 303.000000 303.000000 303.000000 303.000000 \n", 684 | "mean 54.366337 0.683168 0.966997 131.623762 246.264026 0.148515 \n", 685 | "std 9.082101 0.466011 1.032052 17.538143 51.830751 0.356198 \n", 686 | "min 29.000000 0.000000 0.000000 94.000000 126.000000 0.000000 \n", 687 | "25% 47.500000 0.000000 0.000000 120.000000 211.000000 0.000000 \n", 688 | "50% 55.000000 1.000000 1.000000 130.000000 240.000000 0.000000 \n", 689 | "75% 61.000000 1.000000 2.000000 140.000000 274.500000 0.000000 \n", 690 | "max 77.000000 1.000000 3.000000 200.000000 564.000000 1.000000 \n", 691 | "\n", 692 | " restecg thalach exang oldpeak slope ca \\\n", 693 | "count 303.000000 303.000000 303.000000 303.000000 303.000000 303.000000 \n", 694 | "mean 0.528053 149.646865 0.326733 1.039604 1.399340 0.729373 \n", 695 | "std 0.525860 22.905161 0.469794 1.161075 0.616226 1.022606 \n", 696 | "min 0.000000 71.000000 0.000000 0.000000 0.000000 0.000000 \n", 697 | "25% 0.000000 133.500000 0.000000 0.000000 1.000000 0.000000 \n", 698 | "50% 1.000000 153.000000 0.000000 0.800000 1.000000 0.000000 \n", 699 | "75% 1.000000 166.000000 1.000000 1.600000 2.000000 1.000000 \n", 700 | "max 2.000000 202.000000 1.000000 6.200000 2.000000 4.000000 \n", 701 | "\n", 702 | " thal target \n", 703 | "count 303.000000 303.000000 \n", 704 | "mean 2.313531 0.544554 \n", 705 | "std 0.612277 0.498835 \n", 706 | "min 0.000000 0.000000 \n", 707 | "25% 2.000000 0.000000 \n", 708 | "50% 2.000000 1.000000 \n", 709 | "75% 3.000000 1.000000 \n", 710 | "max 3.000000 1.000000 " 711 | ], 712 | "text/html": [ 713 | "\n", 714 | "
\n", 715 | "
\n", 716 | "
\n", 717 | "\n", 730 | "\n", 731 | " \n", 732 | " \n", 733 | " \n", 734 | " \n", 735 | " \n", 736 | " \n", 737 | " \n", 738 | " \n", 739 | " \n", 740 | " \n", 741 | " \n", 742 | " \n", 743 | " \n", 744 | " \n", 745 | " \n", 746 | " \n", 747 | " \n", 748 | " \n", 749 | " \n", 750 | " \n", 751 | " \n", 752 | " \n", 753 | " \n", 754 | " \n", 755 | " \n", 756 | " \n", 757 | " \n", 758 | " \n", 759 | " \n", 760 | " \n", 761 | " \n", 762 | " \n", 763 | " \n", 764 | " \n", 765 | " \n", 766 | " \n", 767 | " \n", 768 | " \n", 769 | " \n", 770 | " \n", 771 | " \n", 772 | " \n", 773 | " \n", 774 | " \n", 775 | " \n", 776 | " \n", 777 | " \n", 778 | " \n", 779 | " \n", 780 | " \n", 781 | " \n", 782 | " \n", 783 | " \n", 784 | " \n", 785 | " \n", 786 | " \n", 787 | " \n", 788 | " \n", 789 | " \n", 790 | " \n", 791 | " \n", 792 | " \n", 793 | " \n", 794 | " \n", 795 | " \n", 796 | " \n", 797 | " \n", 798 | " \n", 799 | " \n", 800 | " \n", 801 | " \n", 802 | " \n", 803 | " \n", 804 | " \n", 805 | " \n", 806 | " \n", 807 | " \n", 808 | " \n", 809 | " \n", 810 | " \n", 811 | " \n", 812 | " \n", 813 | " \n", 814 | " \n", 815 | " \n", 816 | " \n", 817 | " \n", 818 | " \n", 819 | " \n", 820 | " \n", 821 | " \n", 822 | " \n", 823 | " \n", 824 | " \n", 825 | " \n", 826 | " \n", 827 | " \n", 828 | " \n", 829 | " \n", 830 | " \n", 831 | " \n", 832 | " \n", 833 | " \n", 834 | " \n", 835 | " \n", 836 | " \n", 837 | " \n", 838 | " \n", 839 | " \n", 840 | " \n", 841 | " \n", 842 | " \n", 843 | " \n", 844 | " \n", 845 | " \n", 846 | " \n", 847 | " \n", 848 | " \n", 849 | " \n", 850 | " \n", 851 | " \n", 852 | " \n", 853 | " \n", 854 | " \n", 855 | " \n", 856 | " \n", 857 | " \n", 858 | " \n", 859 | " \n", 860 | " \n", 861 | " \n", 862 | " \n", 863 | " \n", 864 | " \n", 865 | " \n", 866 | " \n", 867 | " \n", 868 | " \n", 869 | " \n", 870 | " \n", 871 | " \n", 872 | " \n", 873 | " \n", 874 | " \n", 875 | " \n", 876 | " \n", 877 | " \n", 878 | " \n", 879 | " \n", 880 | " \n", 881 | " \n", 882 | " \n", 883 | " \n", 884 | " \n", 885 | " \n", 886 | " \n", 887 | " \n", 888 | "
agesexcptrestbpscholfbsrestecgthalachexangoldpeakslopecathaltarget
count303.000000303.000000303.000000303.000000303.000000303.000000303.000000303.000000303.000000303.000000303.000000303.000000303.000000303.000000
mean54.3663370.6831680.966997131.623762246.2640260.1485150.528053149.6468650.3267331.0396041.3993400.7293732.3135310.544554
std9.0821010.4660111.03205217.53814351.8307510.3561980.52586022.9051610.4697941.1610750.6162261.0226060.6122770.498835
min29.0000000.0000000.00000094.000000126.0000000.0000000.00000071.0000000.0000000.0000000.0000000.0000000.0000000.000000
25%47.5000000.0000000.000000120.000000211.0000000.0000000.000000133.5000000.0000000.0000001.0000000.0000002.0000000.000000
50%55.0000001.0000001.000000130.000000240.0000000.0000001.000000153.0000000.0000000.8000001.0000000.0000002.0000001.000000
75%61.0000001.0000002.000000140.000000274.5000000.0000001.000000166.0000001.0000001.6000002.0000001.0000003.0000001.000000
max77.0000001.0000003.000000200.000000564.0000001.0000002.000000202.0000001.0000006.2000002.0000004.0000003.0000001.000000
\n", 889 | "
\n", 890 | " \n", 900 | " \n", 901 | " \n", 938 | "\n", 939 | " \n", 963 | "
\n", 964 | "
\n", 965 | " " 966 | ] 967 | }, 968 | "metadata": {}, 969 | "execution_count": 8 970 | } 971 | ] 972 | }, 973 | { 974 | "cell_type": "code", 975 | "metadata": { 976 | "colab": { 977 | "base_uri": "https://localhost:8080/" 978 | }, 979 | "id": "4InaOSIUsfWP", 980 | "outputId": "acf2ef21-c6ef-4d3a-a14c-0399e02bcb6a" 981 | }, 982 | "source": [ 983 | "# checking the distribution of Target Variable\n", 984 | "heart_data['target'].value_counts()" 985 | ], 986 | "execution_count": null, 987 | "outputs": [ 988 | { 989 | "output_type": "execute_result", 990 | "data": { 991 | "text/plain": [ 992 | "1 165\n", 993 | "0 138\n", 994 | "Name: target, dtype: int64" 995 | ] 996 | }, 997 | "metadata": {}, 998 | "execution_count": 9 999 | } 1000 | ] 1001 | }, 1002 | { 1003 | "cell_type": "markdown", 1004 | "metadata": { 1005 | "id": "aSOBu4qDtJy5" 1006 | }, 1007 | "source": [ 1008 | "1 --> Defective Heart\n", 1009 | "\n", 1010 | "0 --> Healthy Heart" 1011 | ] 1012 | }, 1013 | { 1014 | "cell_type": "markdown", 1015 | "metadata": { 1016 | "id": "tW8i4igjtPRC" 1017 | }, 1018 | "source": [ 1019 | "Splitting the Features and Target" 1020 | ] 1021 | }, 1022 | { 1023 | "cell_type": "code", 1024 | "metadata": { 1025 | "id": "Q6yfbswrs7m3" 1026 | }, 1027 | "source": [ 1028 | "X = heart_data.drop(columns='target', axis=1)\n", 1029 | "Y = heart_data['target']" 1030 | ], 1031 | "execution_count": null, 1032 | "outputs": [] 1033 | }, 1034 | { 1035 | "cell_type": "code", 1036 | "metadata": { 1037 | "colab": { 1038 | "base_uri": "https://localhost:8080/" 1039 | }, 1040 | "id": "XJoCp4ZKtpZy", 1041 | "outputId": "aa2ea3a8-6917-4780-bc6f-ccaaf3df6dca" 1042 | }, 1043 | "source": [ 1044 | "print(X)" 1045 | ], 1046 | "execution_count": null, 1047 | "outputs": [ 1048 | { 1049 | "output_type": "stream", 1050 | "name": "stdout", 1051 | "text": [ 1052 | " age sex cp trestbps chol fbs restecg thalach exang oldpeak \\\n", 1053 | "0 63 1 3 145 233 1 0 150 0 2.3 \n", 1054 | "1 37 1 2 130 250 0 1 187 0 3.5 \n", 1055 | "2 41 0 1 130 204 0 0 172 0 1.4 \n", 1056 | "3 56 1 1 120 236 0 1 178 0 0.8 \n", 1057 | "4 57 0 0 120 354 0 1 163 1 0.6 \n", 1058 | ".. ... ... .. ... ... ... ... ... ... ... \n", 1059 | "298 57 0 0 140 241 0 1 123 1 0.2 \n", 1060 | "299 45 1 3 110 264 0 1 132 0 1.2 \n", 1061 | "300 68 1 0 144 193 1 1 141 0 3.4 \n", 1062 | "301 57 1 0 130 131 0 1 115 1 1.2 \n", 1063 | "302 57 0 1 130 236 0 0 174 0 0.0 \n", 1064 | "\n", 1065 | " slope ca thal \n", 1066 | "0 0 0 1 \n", 1067 | "1 0 0 2 \n", 1068 | "2 2 0 2 \n", 1069 | "3 2 0 2 \n", 1070 | "4 2 0 2 \n", 1071 | ".. ... .. ... \n", 1072 | "298 1 0 3 \n", 1073 | "299 1 0 3 \n", 1074 | "300 1 2 3 \n", 1075 | "301 1 1 3 \n", 1076 | "302 1 1 2 \n", 1077 | "\n", 1078 | "[303 rows x 13 columns]\n" 1079 | ] 1080 | } 1081 | ] 1082 | }, 1083 | { 1084 | "cell_type": "code", 1085 | "metadata": { 1086 | "colab": { 1087 | "base_uri": "https://localhost:8080/" 1088 | }, 1089 | "id": "nukuj-YItq1w", 1090 | "outputId": "9329a137-443a-490c-bcf9-20daee07a300" 1091 | }, 1092 | "source": [ 1093 | "print(Y)" 1094 | ], 1095 | "execution_count": null, 1096 | "outputs": [ 1097 | { 1098 | "output_type": "stream", 1099 | "name": "stdout", 1100 | "text": [ 1101 | "0 1\n", 1102 | "1 1\n", 1103 | "2 1\n", 1104 | "3 1\n", 1105 | "4 1\n", 1106 | " ..\n", 1107 | "298 0\n", 1108 | "299 0\n", 1109 | "300 0\n", 1110 | "301 0\n", 1111 | "302 0\n", 1112 | "Name: target, Length: 303, dtype: int64\n" 1113 | ] 1114 | } 1115 | ] 1116 | }, 1117 | { 1118 | "cell_type": "markdown", 1119 | "metadata": { 1120 | "id": "_EcjSE3Et18n" 1121 | }, 1122 | "source": [ 1123 | "Splitting the Data into Training data & Test Data" 1124 | ] 1125 | }, 1126 | { 1127 | "cell_type": "code", 1128 | "metadata": { 1129 | "id": "a-UUfRUxtuga" 1130 | }, 1131 | "source": [ 1132 | "X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, stratify=Y, random_state=2)" 1133 | ], 1134 | "execution_count": null, 1135 | "outputs": [] 1136 | }, 1137 | { 1138 | "cell_type": "code", 1139 | "metadata": { 1140 | "colab": { 1141 | "base_uri": "https://localhost:8080/" 1142 | }, 1143 | "id": "x7PrjC6zuf6X", 1144 | "outputId": "985f083d-068e-49ec-e05d-73ec42da6535" 1145 | }, 1146 | "source": [ 1147 | "print(X.shape, X_train.shape, X_test.shape)" 1148 | ], 1149 | "execution_count": null, 1150 | "outputs": [ 1151 | { 1152 | "output_type": "stream", 1153 | "name": "stdout", 1154 | "text": [ 1155 | "(303, 13) (242, 13) (61, 13)\n" 1156 | ] 1157 | } 1158 | ] 1159 | }, 1160 | { 1161 | "cell_type": "markdown", 1162 | "metadata": { 1163 | "id": "beSkZmpVuvn9" 1164 | }, 1165 | "source": [ 1166 | "Model Training" 1167 | ] 1168 | }, 1169 | { 1170 | "cell_type": "code", 1171 | "metadata": { 1172 | "id": "4-Md74FYuqNL" 1173 | }, 1174 | "source": [ 1175 | "model = LogisticRegression(max_iter=1000)" 1176 | ], 1177 | "execution_count": null, 1178 | "outputs": [] 1179 | }, 1180 | { 1181 | "cell_type": "code", 1182 | "metadata": { 1183 | "colab": { 1184 | "base_uri": "https://localhost:8080/" 1185 | }, 1186 | "id": "kCdHYxGUu7XD", 1187 | "outputId": "9c90961d-3dd0-41ab-e2ff-9d6d58b10d86" 1188 | }, 1189 | "source": [ 1190 | "# training the LogisticRegression model with Training data\n", 1191 | "model.fit(X_train, Y_train)" 1192 | ], 1193 | "execution_count": null, 1194 | "outputs": [ 1195 | { 1196 | "output_type": "execute_result", 1197 | "data": { 1198 | "text/plain": [ 1199 | "LogisticRegression(max_iter=1000)" 1200 | ] 1201 | }, 1202 | "metadata": {}, 1203 | "execution_count": 16 1204 | } 1205 | ] 1206 | }, 1207 | { 1208 | "cell_type": "markdown", 1209 | "metadata": { 1210 | "id": "ZYIw8Gi9vXfU" 1211 | }, 1212 | "source": [ 1213 | "Model Evaluation" 1214 | ] 1215 | }, 1216 | { 1217 | "cell_type": "markdown", 1218 | "metadata": { 1219 | "id": "wmxAekfZvZa9" 1220 | }, 1221 | "source": [ 1222 | "**Accuracy Score**" 1223 | ] 1224 | }, 1225 | { 1226 | "cell_type": "code", 1227 | "source": [ 1228 | "from sklearn.metrics import accuracy_score" 1229 | ], 1230 | "metadata": { 1231 | "id": "aMMAnoWYFQY5" 1232 | }, 1233 | "execution_count": null, 1234 | "outputs": [] 1235 | }, 1236 | { 1237 | "cell_type": "code", 1238 | "metadata": { 1239 | "id": "g19JaUTMvPKy", 1240 | "colab": { 1241 | "base_uri": "https://localhost:8080/" 1242 | }, 1243 | "outputId": "b0767826-8d91-471f-fcbf-a12dce724760" 1244 | }, 1245 | "source": [ 1246 | "# accuracy on training data\n", 1247 | "X_train_prediction = model.predict(X_train)\n", 1248 | "training_data_accuracy = accuracy_score(Y_train, X_train_prediction)\n", 1249 | "print(training_data_accuracy)" 1250 | ], 1251 | "execution_count": null, 1252 | "outputs": [ 1253 | { 1254 | "output_type": "stream", 1255 | "name": "stdout", 1256 | "text": [ 1257 | "0.8553719008264463\n" 1258 | ] 1259 | } 1260 | ] 1261 | }, 1262 | { 1263 | "cell_type": "code", 1264 | "metadata": { 1265 | "colab": { 1266 | "base_uri": "https://localhost:8080/" 1267 | }, 1268 | "id": "uQBZvBh8v7R_", 1269 | "outputId": "1d5402ac-000f-4ba1-dd95-b66c2a9b6994" 1270 | }, 1271 | "source": [ 1272 | "print('Accuracy on Training data : ', round(training_data_accuracy*100, 2), '%')" 1273 | ], 1274 | "execution_count": null, 1275 | "outputs": [ 1276 | { 1277 | "output_type": "stream", 1278 | "name": "stdout", 1279 | "text": [ 1280 | "Accuracy on Training data : 85.54 %\n" 1281 | ] 1282 | } 1283 | ] 1284 | }, 1285 | { 1286 | "cell_type": "code", 1287 | "metadata": { 1288 | "id": "mDONDJdlwBIO", 1289 | "colab": { 1290 | "base_uri": "https://localhost:8080/" 1291 | }, 1292 | "outputId": "458c59fe-e403-4528-e904-6666177cfc9a" 1293 | }, 1294 | "source": [ 1295 | "# accuracy on test data\n", 1296 | "X_test_prediction = model.predict(X_test)\n", 1297 | "test_data_accuracy = accuracy_score(Y_test, X_test_prediction)\n", 1298 | "print(test_data_accuracy)" 1299 | ], 1300 | "execution_count": null, 1301 | "outputs": [ 1302 | { 1303 | "output_type": "stream", 1304 | "name": "stdout", 1305 | "text": [ 1306 | "0.8032786885245902\n" 1307 | ] 1308 | } 1309 | ] 1310 | }, 1311 | { 1312 | "cell_type": "code", 1313 | "metadata": { 1314 | "colab": { 1315 | "base_uri": "https://localhost:8080/" 1316 | }, 1317 | "id": "_MBS-OqdwYpf", 1318 | "outputId": "0b7f8490-91e8-466a-dc5d-b4227452f1c3" 1319 | }, 1320 | "source": [ 1321 | "print('Accuracy on Test data : ', round(test_data_accuracy*100, 2), '%')" 1322 | ], 1323 | "execution_count": null, 1324 | "outputs": [ 1325 | { 1326 | "output_type": "stream", 1327 | "name": "stdout", 1328 | "text": [ 1329 | "Accuracy on Test data : 80.33 %\n" 1330 | ] 1331 | } 1332 | ] 1333 | }, 1334 | { 1335 | "cell_type": "markdown", 1336 | "source": [ 1337 | "**Confuaion Matrix**" 1338 | ], 1339 | "metadata": { 1340 | "id": "hOqOj3xEEqvW" 1341 | } 1342 | }, 1343 | { 1344 | "cell_type": "code", 1345 | "source": [ 1346 | "from sklearn.metrics import confusion_matrix" 1347 | ], 1348 | "metadata": { 1349 | "id": "pZSEUHp7Eqcr" 1350 | }, 1351 | "execution_count": null, 1352 | "outputs": [] 1353 | }, 1354 | { 1355 | "cell_type": "code", 1356 | "source": [ 1357 | "cf_matrix = confusion_matrix(Y_test, X_test_prediction)\n", 1358 | "\n", 1359 | "print(cf_matrix)" 1360 | ], 1361 | "metadata": { 1362 | "colab": { 1363 | "base_uri": "https://localhost:8080/" 1364 | }, 1365 | "id": "cXkoIIujFeQn", 1366 | "outputId": "ef1f91f5-7f29-4500-a649-a119f34fc04f" 1367 | }, 1368 | "execution_count": null, 1369 | "outputs": [ 1370 | { 1371 | "output_type": "stream", 1372 | "name": "stdout", 1373 | "text": [ 1374 | "[[22 6]\n", 1375 | " [ 6 27]]\n" 1376 | ] 1377 | } 1378 | ] 1379 | }, 1380 | { 1381 | "cell_type": "code", 1382 | "source": [ 1383 | "tn, fp, fn, tp = cf_matrix.ravel()\n", 1384 | "\n", 1385 | "print(tn, fp, fn, tp)" 1386 | ], 1387 | "metadata": { 1388 | "colab": { 1389 | "base_uri": "https://localhost:8080/" 1390 | }, 1391 | "id": "tpmo_nY8FyZl", 1392 | "outputId": "34ab13d8-be83-4381-f1f7-17c168e389b3" 1393 | }, 1394 | "execution_count": null, 1395 | "outputs": [ 1396 | { 1397 | "output_type": "stream", 1398 | "name": "stdout", 1399 | "text": [ 1400 | "22 6 6 27\n" 1401 | ] 1402 | } 1403 | ] 1404 | }, 1405 | { 1406 | "cell_type": "code", 1407 | "source": [ 1408 | "import seaborn as sns\n", 1409 | "sns.heatmap(cf_matrix, annot=True)" 1410 | ], 1411 | "metadata": { 1412 | "colab": { 1413 | "base_uri": "https://localhost:8080/", 1414 | "height": 282 1415 | }, 1416 | "id": "i4ffPhNZGBR_", 1417 | "outputId": "f1a0fc3e-8f55-4b19-d6bc-a62518a3c48b" 1418 | }, 1419 | "execution_count": null, 1420 | "outputs": [ 1421 | { 1422 | "output_type": "execute_result", 1423 | "data": { 1424 | "text/plain": [ 1425 | "" 1426 | ] 1427 | }, 1428 | "metadata": {}, 1429 | "execution_count": 25 1430 | }, 1431 | { 1432 | "output_type": "display_data", 1433 | "data": { 1434 | "text/plain": [ 1435 | "
" 1436 | ], 1437 | "image/png": "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\n" 1438 | }, 1439 | "metadata": { 1440 | "needs_background": "light" 1441 | } 1442 | } 1443 | ] 1444 | }, 1445 | { 1446 | "cell_type": "markdown", 1447 | "source": [ 1448 | "confusion matrix for multi class classification: https://colab.research.google.com/drive/17FViiMJbJXQ5s9GOW94emoHcCKUcYr3l?usp=sharing" 1449 | ], 1450 | "metadata": { 1451 | "id": "yFibQac0G4fh" 1452 | } 1453 | }, 1454 | { 1455 | "cell_type": "code", 1456 | "source": [], 1457 | "metadata": { 1458 | "id": "fr6QfOeqGr_3" 1459 | }, 1460 | "execution_count": null, 1461 | "outputs": [] 1462 | } 1463 | ] 1464 | } --------------------------------------------------------------------------------