diff --git a/Heart_Disease_Prediction (2).ipynb b/Heart_Disease_Prediction (2).ipynb deleted file mode 100644 index 314b9652..00000000 --- a/Heart_Disease_Prediction (2).ipynb +++ /dev/null @@ -1,1586 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "Cj2SOXgaZt-Q" - }, - "source": [ - "Importing the Dependencies\n" - ] - }, - { - "cell_type": "code", - "execution_count": 212, - "metadata": { - "id": "k850UGz1Z03B" - }, - "outputs": [], - "source": [ - "# @title\n", - "import numpy as np\n", - "import pandas as pd\n", - "from sklearn.model_selection import train_test_split\n", - "from sklearn.linear_model import LogisticRegression\n", - "from sklearn.metrics import accuracy_score" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "APYsimt8bDoD" - }, - "source": [ - "Data Collection and Processing\n" - ] - }, - { - "cell_type": "code", - "execution_count": 213, - "metadata": { - "id": "RJg3aA91Z0-u" - }, - "outputs": [], - "source": [ - "#loading the csv data to a Pandas DataFrame\n", - "heart_data= pd.read_csv('/content/heart.csv')" - ] - }, - { - "cell_type": "code", - "execution_count": 214, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 394 - }, - "id": "BnoQ8u4hdZ8Z", - "outputId": "452a033e-92bd-4b1e-b754-93d896d0c0a7" - }, - "outputs": [ - { - "data": { - "application/vnd.google.colaboratory.intrinsic+json": { - "type": "dataframe", - "variable_name": "heart_data" - }, - "text/html": [ - "\n", - "
\n", - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Patient IDAgeSexCholesterolBlood PressureHeart RateDiabetesFamily HistorySmokingObesity...Sedentary Hours Per DayIncomeBMITriglyceridesPhysical Activity Days Per WeekSleep Hours Per DayCountryContinentHemisphereHeart Attack Risk
0BMW781267Male208158/88720010...6.61500126140431.25123328606ArgentinaSouth AmericaSouthern Hemisphere0
1CZE111421Male389165/93981111...4.96345928576827.19497323517CanadaNorth AmericaNorthern Hemisphere0
2BNI990621Female324174/99721000...9.46342623528228.17657158744FranceEuropeNorthern Hemisphere0
3JLN349784Male383163/100731110...7.64898112564036.46470437834CanadaNorth AmericaNorthern Hemisphere0
4GFO884766Male31891/88931111...1.51482116055521.80914423115ThailandAsiaNorthern Hemisphere0
\n", - "

5 rows × 26 columns

\n", - "
\n", - "
\n", - "\n", - "
\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "
\n", - "\n", - "\n", - "
\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "
\n", - "\n", - "
\n", - "
\n" - ], - "text/plain": [ - " Patient ID Age Sex Cholesterol Blood Pressure Heart Rate Diabetes \\\n", - "0 BMW7812 67 Male 208 158/88 72 0 \n", - "1 CZE1114 21 Male 389 165/93 98 1 \n", - "2 BNI9906 21 Female 324 174/99 72 1 \n", - "3 JLN3497 84 Male 383 163/100 73 1 \n", - "4 GFO8847 66 Male 318 91/88 93 1 \n", - "\n", - " Family History Smoking Obesity ... Sedentary Hours Per Day Income \\\n", - "0 0 1 0 ... 6.615001 261404 \n", - "1 1 1 1 ... 4.963459 285768 \n", - "2 0 0 0 ... 9.463426 235282 \n", - "3 1 1 0 ... 7.648981 125640 \n", - "4 1 1 1 ... 1.514821 160555 \n", - "\n", - " BMI Triglycerides Physical Activity Days Per Week \\\n", - "0 31.251233 286 0 \n", - "1 27.194973 235 1 \n", - "2 28.176571 587 4 \n", - "3 36.464704 378 3 \n", - "4 21.809144 231 1 \n", - "\n", - " Sleep Hours Per Day Country Continent Hemisphere \\\n", - "0 6 Argentina South America Southern Hemisphere \n", - "1 7 Canada North America Northern Hemisphere \n", - "2 4 France Europe Northern Hemisphere \n", - "3 4 Canada North America Northern Hemisphere \n", - "4 5 Thailand Asia Northern Hemisphere \n", - "\n", - " Heart Attack Risk \n", - "0 0 \n", - "1 0 \n", - "2 0 \n", - "3 0 \n", - "4 0 \n", - "\n", - "[5 rows x 26 columns]" - ] - }, - "execution_count": 214, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "#print first 5 rows of the datase\n", - "heart_data.head()\n" - ] - }, - { - "cell_type": "code", - "execution_count": 215, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 394 - }, - "id": "NQwDjwwGeBF4", - "outputId": "60d69d34-5c6e-4975-c633-13cc786065f6" - }, - "outputs": [ - { - "data": { - "application/vnd.google.colaboratory.intrinsic+json": { - "type": "dataframe" - }, - "text/html": [ - "\n", - "
\n", - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Patient IDAgeSexCholesterolBlood PressureHeart RateDiabetesFamily HistorySmokingObesity...Sedentary Hours Per DayIncomeBMITriglyceridesPhysical Activity Days Per WeekSleep Hours Per DayCountryContinentHemisphereHeart Attack Risk
8758MSV991860Male12194/76611110...10.80637323542019.6558956777ThailandAsiaNorthern Hemisphere0
8759QSV676428Female120157/102731001...3.83303821788123.99386661749CanadaNorth AmericaNorthern Hemisphere0
8760XKA592547Male250161/751050111...2.3752143699835.40614652744BrazilSouth AmericaSouthern Hemisphere1
8761EPE680136Male178119/67601010...0.02910420994327.29402011428BrazilSouth AmericaSouthern Hemisphere0
8762ZWN966625Female356138/67751100...9.00523424733832.91415118074United KingdomEuropeNorthern Hemisphere1
\n", - "

5 rows × 26 columns

\n", - "
\n", - "
\n", - "\n", - "
\n", - " \n", - "\n", - " \n", - "\n", - " \n", - "
\n", - "\n", - "\n", - "
\n", - " \n", - "\n", - "\n", - "\n", - " \n", - "
\n", - "\n", - "
\n", - "
\n" - ], - "text/plain": [ - " Patient ID Age Sex Cholesterol Blood Pressure Heart Rate \\\n", - "8758 MSV9918 60 Male 121 94/76 61 \n", - "8759 QSV6764 28 Female 120 157/102 73 \n", - "8760 XKA5925 47 Male 250 161/75 105 \n", - "8761 EPE6801 36 Male 178 119/67 60 \n", - "8762 ZWN9666 25 Female 356 138/67 75 \n", - "\n", - " Diabetes Family History Smoking Obesity ... \\\n", - "8758 1 1 1 0 ... \n", - "8759 1 0 0 1 ... \n", - "8760 0 1 1 1 ... \n", - "8761 1 0 1 0 ... \n", - "8762 1 1 0 0 ... \n", - "\n", - " Sedentary Hours Per Day Income BMI Triglycerides \\\n", - "8758 10.806373 235420 19.655895 67 \n", - "8759 3.833038 217881 23.993866 617 \n", - "8760 2.375214 36998 35.406146 527 \n", - "8761 0.029104 209943 27.294020 114 \n", - "8762 9.005234 247338 32.914151 180 \n", - "\n", - " Physical Activity Days Per Week Sleep Hours Per Day Country \\\n", - "8758 7 7 Thailand \n", - "8759 4 9 Canada \n", - "8760 4 4 Brazil \n", - "8761 2 8 Brazil \n", - "8762 7 4 United Kingdom \n", - "\n", - " Continent Hemisphere Heart Attack Risk \n", - "8758 Asia Northern Hemisphere 0 \n", - "8759 North America Northern Hemisphere 0 \n", - "8760 South America Southern Hemisphere 1 \n", - "8761 South America Southern Hemisphere 0 \n", - "8762 Europe Northern Hemisphere 1 \n", - "\n", - "[5 rows x 26 columns]" - ] - }, - "execution_count": 215, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "heart_data.tail()\n" - ] - }, - { - "cell_type": "code", - "execution_count": 216, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "Ye8LlTQVeHs1", - "outputId": "e0fb1303-1000-45df-8cbf-49a3322f42b1" - }, - "outputs": [ - { - "data": { - "text/plain": [ - "(8763, 26)" - ] - }, - "execution_count": 216, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# number of rows and columns in the dataset\n", - "heart_data.shape\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 217, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "5YZLMOwFeXF3", - "outputId": "4a322f74-c893-45a0-e4e2-cca32e4d0bd3" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "RangeIndex: 8763 entries, 0 to 8762\n", - "Data columns (total 26 columns):\n", - " # Column Non-Null Count Dtype \n", - "--- ------ -------------- ----- \n", - " 0 Patient ID 8763 non-null object \n", - " 1 Age 8763 non-null int64 \n", - " 2 Sex 8763 non-null object \n", - " 3 Cholesterol 8763 non-null int64 \n", - " 4 Blood Pressure 8763 non-null object \n", - " 5 Heart Rate 8763 non-null int64 \n", - " 6 Diabetes 8763 non-null int64 \n", - " 7 Family History 8763 non-null int64 \n", - " 8 Smoking 8763 non-null int64 \n", - " 9 Obesity 8763 non-null int64 \n", - " 10 Alcohol Consumption 8763 non-null int64 \n", - " 11 Exercise Hours Per Week 8763 non-null float64\n", - " 12 Diet 8763 non-null object \n", - " 13 Previous Heart Problems 8763 non-null int64 \n", - " 14 Medication Use 8763 non-null int64 \n", - " 15 Stress Level 8763 non-null int64 \n", - " 16 Sedentary Hours Per Day 8763 non-null float64\n", - " 17 Income 8763 non-null int64 \n", - " 18 BMI 8763 non-null float64\n", - " 19 Triglycerides 8763 non-null int64 \n", - " 20 Physical Activity Days Per Week 8763 non-null int64 \n", - " 21 Sleep Hours Per Day 8763 non-null int64 \n", - " 22 Country 8763 non-null object \n", - " 23 Continent 8763 non-null object \n", - " 24 Hemisphere 8763 non-null object \n", - " 25 Heart Attack Risk 8763 non-null int64 \n", - "dtypes: float64(3), int64(16), object(7)\n", - "memory usage: 1.7+ MB\n" - ] - } - ], - "source": [ - "# getting some info about the data\n", - "heart_data.info()" - ] - }, - { - "cell_type": "code", - "execution_count": 218, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "QHazm2rze6Oj", - "outputId": "1601115a-a97a-4aa7-b0ca-1d94d09d11fa" - }, - "outputs": [ - { - "data": { - "text/plain": [ - "Patient ID 0\n", - "Age 0\n", - "Sex 0\n", - "Cholesterol 0\n", - "Blood Pressure 0\n", - "Heart Rate 0\n", - "Diabetes 0\n", - "Family History 0\n", - "Smoking 0\n", - "Obesity 0\n", - "Alcohol Consumption 0\n", - "Exercise Hours Per Week 0\n", - "Diet 0\n", - "Previous Heart Problems 0\n", - "Medication Use 0\n", - "Stress Level 0\n", - "Sedentary Hours Per Day 0\n", - "Income 0\n", - "BMI 0\n", - "Triglycerides 0\n", - "Physical Activity Days Per Week 0\n", - "Sleep Hours Per Day 0\n", - "Country 0\n", - "Continent 0\n", - "Hemisphere 0\n", - "Heart Attack Risk 0\n", - "dtype: int64" - ] - }, - "execution_count": 218, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "#checking for missing values\n", - "heart_data.isnull().sum()" - ] - }, - { - "cell_type": "code", - "execution_count": 219, - "metadata": { - "id": "nt15bvuYfBcA" - }, - "outputs": [], - "source": [ - "# statistical measures about the data\n", - "z=heart_data.describe()" - ] - }, - { - "cell_type": "code", - "execution_count": 220, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "NCbxYqqNf2-4", - "outputId": "1e38c06b-606b-4509-8e29-2d249daaf4d0" - }, - "outputs": [ - { - "data": { - "text/plain": [ - "Heart Attack Risk\n", - "0 5624\n", - "1 3139\n", - "Name: count, dtype: int64" - ] - }, - "execution_count": 220, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# checking the distribution of Target Variable\n", - "heart_data['Heart Attack Risk'].value_counts()" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "DvvKtsuILgK1" - }, - "source": [] - }, - { - "cell_type": "code", - "execution_count": 221, - "metadata": { - "id": "mfiZ3MDvIiaV" - }, - "outputs": [], - "source": [ - "heart_data_num = heart_data.select_dtypes(include=[np.float32,np.float64,np.int64])" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "qWNMUL5_CrfC" - }, - "source": [ - "1-->Defective heart\n", - "\n", - "0-->Healthy heart\n", - "\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 222, - "metadata": { - "id": "oSgKSF5-DGVk" - }, - "outputs": [], - "source": [ - "x=heart_data_num.drop(columns='Heart Attack Risk', axis=1)\n", - "y=heart_data_num['Heart Attack Risk']\n" - ] - }, - { - "cell_type": "code", - "execution_count": 223, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "zhiIhyMxDhWF", - "outputId": "5684dc44-c814-4d81-e438-ecc544010d10" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Age Cholesterol Heart Rate Diabetes Family History Smoking \\\n", - "0 67 208 72 0 0 1 \n", - "1 21 389 98 1 1 1 \n", - "2 21 324 72 1 0 0 \n", - "3 84 383 73 1 1 1 \n", - "4 66 318 93 1 1 1 \n", - "... ... ... ... ... ... ... \n", - "8758 60 121 61 1 1 1 \n", - "8759 28 120 73 1 0 0 \n", - "8760 47 250 105 0 1 1 \n", - "8761 36 178 60 1 0 1 \n", - "8762 25 356 75 1 1 0 \n", - "\n", - " Obesity Alcohol Consumption Exercise Hours Per Week \\\n", - "0 0 0 4.168189 \n", - "1 1 1 1.813242 \n", - "2 0 0 2.078353 \n", - "3 0 1 9.828130 \n", - "4 1 0 5.804299 \n", - "... ... ... ... \n", - "8758 0 1 7.917342 \n", - "8759 1 0 16.558426 \n", - "8760 1 1 3.148438 \n", - "8761 0 0 3.789950 \n", - "8762 0 1 18.081748 \n", - "\n", - " Previous Heart Problems Medication Use Stress Level \\\n", - "0 0 0 9 \n", - "1 1 0 1 \n", - "2 1 1 9 \n", - "3 1 0 9 \n", - "4 1 0 6 \n", - "... ... ... ... \n", - "8758 1 1 8 \n", - "8759 0 0 8 \n", - "8760 1 0 5 \n", - "8761 1 1 5 \n", - "8762 0 0 8 \n", - "\n", - " Sedentary Hours Per Day Income BMI Triglycerides \\\n", - "0 6.615001 261404 31.251233 286 \n", - "1 4.963459 285768 27.194973 235 \n", - "2 9.463426 235282 28.176571 587 \n", - "3 7.648981 125640 36.464704 378 \n", - "4 1.514821 160555 21.809144 231 \n", - "... ... ... ... ... \n", - "8758 10.806373 235420 19.655895 67 \n", - "8759 3.833038 217881 23.993866 617 \n", - "8760 2.375214 36998 35.406146 527 \n", - "8761 0.029104 209943 27.294020 114 \n", - "8762 9.005234 247338 32.914151 180 \n", - "\n", - " Physical Activity Days Per Week Sleep Hours Per Day \n", - "0 0 6 \n", - "1 1 7 \n", - "2 4 4 \n", - "3 3 4 \n", - "4 1 5 \n", - "... ... ... \n", - "8758 7 7 \n", - "8759 4 9 \n", - "8760 4 4 \n", - "8761 2 8 \n", - "8762 7 4 \n", - "\n", - "[8763 rows x 18 columns]\n" - ] - } - ], - "source": [ - "print(x)" - ] - }, - { - "cell_type": "code", - "execution_count": 224, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "VpOvdXWgHWmI", - "outputId": "8d0190fe-62af-4d69-9af1-d4ce89b52bc4" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0 0\n", - "1 0\n", - "2 0\n", - "3 0\n", - "4 0\n", - " ..\n", - "8758 0\n", - "8759 0\n", - "8760 1\n", - "8761 0\n", - "8762 1\n", - "Name: Heart Attack Risk, Length: 8763, dtype: int64\n" - ] - } - ], - "source": [ - "print(y)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "5A20XMHYII3T" - }, - "source": [ - "Splitting data into Training data" - ] - }, - { - "cell_type": "code", - "execution_count": 225, - "metadata": { - "id": "SNK4hm8DIPSm" - }, - "outputs": [], - "source": [ - "\n", - "x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,stratify=y,random_state=3)" - ] - }, - { - "cell_type": "code", - "execution_count": 226, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "GyZ6mljEHuVk", - "outputId": "c7c7bb9e-ed30-466a-ea57-88f43a409f0f" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Number of samples in x: 8763\n", - "Number of samples in y: 8763\n" - ] - } - ], - "source": [ - "# Check the number of samples in x and y\n", - "print(f\"Number of samples in x: {len(x)}\")\n", - "print(f\"Number of samples in y: {len(y)}\")\n", - "\n", - "# If the number of samples is different, raise an error\n", - "if len(x) != len(y):\n", - " raise ValueError(\"Input arrays have different number of samples.\")\n", - "\n", - "# Proceed with train_test_split\n", - "x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, stratify=y, random_state=3)" - ] - }, - { - "cell_type": "code", - "execution_count": 227, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "7OTKtdA-JLCV", - "outputId": "a9616ddf-7f61-4f3b-fbe0-6d81ea326287" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(8763, 18) (7010, 18) (1753, 18)\n" - ] - } - ], - "source": [ - "print(x.shape,x_train.shape,x_test.shape)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "ne2RibQaJdNe" - }, - "source": [ - "MODEL TRAINING" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "AUEblGtLJlzD" - }, - "source": [ - "LOGISTIC REGRESSION" - ] - }, - { - "cell_type": "code", - "execution_count": 227, - "metadata": { - "id": "OVQDdrIpHm8P" - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 228, - "metadata": { - "id": "w0CnNIPkHnTT" - }, - "outputs": [], - "source": [ - "model1=LogisticRegression()" - ] - }, - { - "cell_type": "code", - "execution_count": 229, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 74 - }, - "id": "kr84EwGwHqGY", - "outputId": "3a0e56ab-20f9-4584-8e40-c84af8b2c593" - }, - "outputs": [ - { - "data": { - "text/html": [ - "
LogisticRegression()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" - ], - "text/plain": [ - "LogisticRegression()" - ] - }, - "execution_count": 229, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Training the logistic regression model with training data\n", - "model1.fit(x_train,y_train)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "aPahD6MLKaPU" - }, - "source": [ - "Model Evaluation\n", - "\n", - "Accuracy Score" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "FE92kQzZHIIl" - }, - "source": [] - }, - { - "cell_type": "code", - "execution_count": 230, - "metadata": { - "id": "NHy61zdJKDR1" - }, - "outputs": [], - "source": [ - "#accuracy on training data\n", - "x_train_prediction = model1.predict(x_train)\n", - "training_data_accuracy = accuracy_score(x_train_prediction, y_train)" - ] - }, - { - "cell_type": "code", - "execution_count": 231, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "J4XiNRwXLCXf", - "outputId": "ffd6a7b0-f978-4e5f-e677-7dcf55ac39a1" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Accuracy on Training data: 0.6417974322396577\n" - ] - } - ], - "source": [ - "print('Accuracy on Training data:',training_data_accuracy)" - ] - }, - { - "cell_type": "code", - "execution_count": 232, - "metadata": { - "id": "ehbFgWjhLK44" - }, - "outputs": [], - "source": [ - "#accuracy on test data\n", - "x_test_prediction=model1.predict(x_test)\n", - "testing_data_accuracy=accuracy_score(x_test_prediction,y_test)" - ] - }, - { - "cell_type": "code", - "execution_count": 233, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "jYZIcbiVLs0G", - "outputId": "72bb19ec-73e3-437e-a6fb-e055fe2d31d0" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Accuracy on Testing data: 0.6417569880205363\n" - ] - } - ], - "source": [ - "print('Accuracy on Testing data:',testing_data_accuracy)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "rec6Gz8vMP_G" - }, - "source": [ - "BUILDING PREDICTING SYSTEM" - ] - }, - { - "cell_type": "code", - "execution_count": 234, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "Ky2mzQUgL9IU", - "outputId": "72053f1d-55ac-4927-f8d8-1659265bbc5f" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[0]\n", - "The person does not have heart disease\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/usr/local/lib/python3.10/dist-packages/sklearn/base.py:439: UserWarning: X does not have valid feature names, but LogisticRegression was fitted with feature names\n", - " warnings.warn(\n" - ] - } - ], - "source": [ - "input_data=(1,67,208,72,0,0,1,0,0,0,0,31.251233, 286,0,0,6,0,0)\n", - "# change the input data into numpy array\n", - "input_data_as_numpy_array=np.asarray(input_data)\n", - "#reshape the numpy array as we are predicting for only on instance\n", - "input_data_reshaped =input_data_as_numpy_array.reshape(1,-1)\n", - "prediction=model1.predict(input_data_reshaped)\n", - "print(prediction)\n", - "if (prediction[0]==0):\n", - " print(\"The person does not have heart disease\")\n", - "else:\n", - " print(\"the person has heart disease\")\n", - "\n" - ] - } - ], - "metadata": { - "colab": { - "provenance": [] - }, - "kernelspec": { - "display_name": "Python 3", - "name": "python3" - }, - "language_info": { - "name": "python" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -}