From 24278ec9f94d778bd122e3ed3c18216a8964199d Mon Sep 17 00:00:00 2001 From: Aryan Patil <68490806+realaryanpatil@users.noreply.github.com> Date: Thu, 19 Aug 2021 10:02:26 +0800 Subject: [PATCH] Run this in Google Colaboratory --- Platinum.ipynb | 186 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 Platinum.ipynb diff --git a/Platinum.ipynb b/Platinum.ipynb new file mode 100644 index 0000000..7a86eb8 --- /dev/null +++ b/Platinum.ipynb @@ -0,0 +1,186 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Platinum.ipynb", + "provenance": [], + "collapsed_sections": [], + "authorship_tag": "ABX9TyO1l5XXdyXWCTVcO6/be7EV" + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "sLPCsQmoV8xs" + }, + "source": [ + "# Platinum heart & liver disease predictor\n", + "Class 12 CS project by Aryan Patil, Priyansh Mishra and Rithwik Anand" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "7Dg7a2vVHZos" + }, + "source": [ + "#github.com/realaryanpatil/Platinum" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7XpVe5YIYVJt" + }, + "source": [ + "### This program requires datasets to work. Please download liver.csv and heart.csv from the [repository](https://github.com/realaryanpatil/Platinum) " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "YEWYKEaNY-Ed" + }, + "source": [ + "import pandas as pd\n", + "\n", + "def trainheart(q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11):\n", + " dataset = pd.read_csv('medical.csv')\n", + " X = dataset.iloc[:, :-1].values\n", + " y = dataset.iloc[:, -1].values\n", + " \n", + " from sklearn.model_selection import train_test_split\n", + " X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state = 0)\n", + "\n", + " from sklearn.preprocessing import StandardScaler\n", + " sc = StandardScaler()\n", + " X_train = sc.fit_transform(X_train)\n", + " X_test = sc.transform(X_test)\n", + "\n", + " from sklearn.naive_bayes import GaussianNB\n", + " classifier = GaussianNB()\n", + " classifier.fit(X_train, y_train)\n", + "\n", + " result = classifier.predict(sc.transform([[q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11]]))\n", + " output = int(result)\n", + " if output == 1:\n", + " a1 = \"The patient is at a high risk of heart failure.\"\n", + " else:\n", + " a1 = \"The patient is at a low risk of heart failure.\"\n", + " print(a1)\n", + "\n", + "def livertrain(q1,q2,q3,q4,q5,q6,q7,q8,q9,q10):\n", + " dataset = pd.read_csv('liver.csv')\n", + " X = dataset.iloc[:, :-1].values\n", + " y = dataset.iloc[:, -1].values\n", + " \n", + " from sklearn.model_selection import train_test_split\n", + " X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)\n", + "\n", + " from sklearn.preprocessing import StandardScaler\n", + " sc = StandardScaler()\n", + " X_train = sc.fit_transform(X_train)\n", + " X_test = sc.transform(X_test)\n", + "\n", + " from sklearn.naive_bayes import GaussianNB\n", + " classifier = GaussianNB()\n", + " classifier.fit(X_train, y_train)\n", + "\n", + " result = classifier.predict(sc.transform([[q1,q2,q3,q4,q5,q6,q7,q8,q9,q10]]))\n", + " output = int(result)\n", + " if output == 1:\n", + " a1 = \"The patient is at a high risk of liver disease.\"\n", + " else:\n", + " a1 = \"The patient is at a low risk of liver disease.\"\n", + " print(a1)\n", + "\n", + "question = input(\"\"\"Welcome to Platinum Argos [V1.0], A Naive Bayes classification system to detect heart/liver disease.\n", + "\n", + "Please select your choice below:\n", + "[1] Heart failure risk analysis\n", + "[2] Liver disease risk analysis\n", + "--------------------------------------------------------------------------------------------------\n", + ":\"\"\")\n", + "\n", + "if question == '1' or question == 'heart':\n", + " print('---------------------------------------heart-----------------------------------------------')\n", + " r1 = input(\"Patient age: \")\n", + " r2 = input(\"Is the patient suffering from anemia? (y/n): \")\n", + " if r2 == 'y':\n", + " r2 = 1\n", + " else:\n", + " r2 = 0\n", + " r3 = input(\"Creatine Phosphokinase levels (in micrograms per litre): \")\n", + " r4 = input(\"Is the patient suffering from diabetes? (y/n): \")\n", + " if r4 == 'y':\n", + " r4 = 1\n", + " else:\n", + " r4 = 0\n", + " r5 = input(\"Ejection Fraction (in %): \")\n", + " r6 = input(\"Is the patient suffering from hypertension? (y/n): \")\n", + " if r6 == 'y':\n", + " r6 = 1\n", + " else:\n", + " r6 = 0\n", + " r7 = input(\"Number of platelets: \")\n", + " r8 = input(\"Serum Creatine levels: \")\n", + " r9 = input(\"Serum Sodium levels: \")\n", + " r10 = input(\"Gender (m/f): \")\n", + " if r10 == 'm':\n", + " r10 = 1\n", + " else:\n", + " r10 = 0\n", + " r11 = input(\"Does the patient smoke? (y/n): \")\n", + " if r11 == 'y':\n", + " r11 = 1\n", + " else:\n", + " r11 = 0\n", + "\n", + " trainheart(r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11)\n", + "\n", + "elif question == \"2\" or question == \"liver\":\n", + " print('---------------------------------------liver-----------------------------------------------')\n", + " r1 = input(\"Patient age: \")\n", + " r2 = input(\"Patient gender (m/f): \")\n", + " if r2 == 'm':\n", + " r2 = 1\n", + " else:\n", + " r2 = 0\n", + " r3 = input(\"Total Bilirubin: \")\n", + " r4 = input(\"Direct Bilirubin: \")\n", + " r5 = input(\"Alkaline Phosphotase: \")\n", + " r6 = input(\"Alamine Aminotransferase:\")\n", + " r7 = input(\"Aspartate Aminotransferase: \")\n", + " r8 = input(\"Total Protiens: \")\n", + " r9 = input(\"Albumin levels: \")\n", + " r10 = input(\"Albumin and Globulin Ratio: \")\n", + "\n", + " livertrain(r1,r2,r3,r4,r5,r6,r7,r8,r9,r10)\n", + "\n", + "else:\n", + " print(\"Wrong input. Please try again.\")\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ], + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file