diff --git a/.ipynb_checkpoints/botty-checkpoint.ipynb b/.ipynb_checkpoints/botty-checkpoint.ipynb new file mode 100644 index 0000000..ff5d78a --- /dev/null +++ b/.ipynb_checkpoints/botty-checkpoint.ipynb @@ -0,0 +1,1396 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 4, + "id": "36cf8e1d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.9747551911748323\n", + "for svm: \n", + "1.0\n", + "-----------------------------------HealthCare ChatBot-----------------------------------\n", + "\n", + "Your Name? \t\t\t\t->soham\n", + "Hello, .!ctkentry\n" + ] + }, + { + "ename": "TypeError", + "evalue": "can only concatenate str (not \"CTkEntry\") to str", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[4], line 303\u001b[0m\n\u001b[0;32m 301\u001b[0m getprecautionDict()\n\u001b[0;32m 302\u001b[0m \u001b[38;5;66;03m#getInfo()\u001b[39;00m\n\u001b[1;32m--> 303\u001b[0m \u001b[43mtree_to_code\u001b[49m\u001b[43m(\u001b[49m\u001b[43mclf\u001b[49m\u001b[43m,\u001b[49m\u001b[43mcols\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 304\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m----------------------------------------------------------------------------------------\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 305\u001b[0m root\u001b[38;5;241m.\u001b[39mmainloop()\n", + "Cell \u001b[1;32mIn[4], line 189\u001b[0m, in \u001b[0;36mtree_to_code\u001b[1;34m(tree, feature_names)\u001b[0m\n\u001b[0;32m 187\u001b[0m name\u001b[38;5;241m.\u001b[39mpack()\n\u001b[0;32m 188\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mHello, \u001b[39m\u001b[38;5;124m\"\u001b[39m,name)\n\u001b[1;32m--> 189\u001b[0m CTkLabel(root,text\u001b[38;5;241m=\u001b[39m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mHello, \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43mname\u001b[49m)\u001b[38;5;241m.\u001b[39mpack()\n\u001b[0;32m 191\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[0;32m 193\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mEnter the symptom you are experiencing \u001b[39m\u001b[38;5;130;01m\\t\u001b[39;00m\u001b[38;5;130;01m\\t\u001b[39;00m\u001b[38;5;124m\"\u001b[39m,end\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m->\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"CTkEntry\") to str" + ] + } + ], + "source": [ + "import re\n", + "import pandas as pd\n", + "import pyttsx3\n", + "from sklearn import preprocessing\n", + "from sklearn.tree import DecisionTreeClassifier,_tree\n", + "import numpy as np\n", + "from sklearn.model_selection import train_test_split\n", + "from sklearn.model_selection import cross_val_score\n", + "from sklearn.svm import SVC\n", + "import csv\n", + "import warnings\n", + "from tkinter import *\n", + "from customtkinter import *\n", + "from PIL import ImageTk,Image\n", + "warnings.filterwarnings(\"ignore\", category=DeprecationWarning)\n", + "\n", + "\n", + "root=CTk()\n", + "root.geometry(\"400x700\")\n", + "root.title(\"A.I.D.A.\")\n", + "CTkLabel(root,text=\"Hello I am AIDA!!\").pack()\n", + "# root.mainloop()\n", + "\n", + "\n", + "\n", + "\n", + "training = pd.read_csv('Data/Training.csv')\n", + "testing= pd.read_csv('Data/Testing.csv')\n", + "cols= training.columns\n", + "cols= cols[:-1]\n", + "x = training[cols]\n", + "y = training['prognosis']\n", + "y1= y\n", + "\n", + "\n", + "reduced_data = training.groupby(training['prognosis']).max()\n", + "\n", + "#mapping strings to numbers\n", + "le = preprocessing.LabelEncoder()\n", + "le.fit(y)\n", + "y = le.transform(y)\n", + "\n", + "\n", + "x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.33, random_state=42)\n", + "testx = testing[cols]\n", + "testy = testing['prognosis'] \n", + "testy = le.transform(testy)\n", + "\n", + "\n", + "clf1 = DecisionTreeClassifier()\n", + "clf = clf1.fit(x_train,y_train)\n", + "# print(clf.score(x_train,y_train))\n", + "# print (\"cross result========\")\n", + "scores = cross_val_score(clf, x_test, y_test, cv=3)\n", + "# print (scores)\n", + "print (scores.mean())\n", + "\n", + "\n", + "model=SVC()\n", + "model.fit(x_train,y_train)\n", + "print(\"for svm: \")\n", + "print(model.score(x_test,y_test))\n", + "\n", + "importances = clf.feature_importances_\n", + "indices = np.argsort(importances)[::-1]\n", + "features = cols\n", + "\n", + "def readn(nstr):\n", + " engine = pyttsx3.init()\n", + "\n", + " engine.setProperty('voice', \"english+f5\")\n", + " engine.setProperty('rate', 130)\n", + "\n", + " engine.say(nstr)\n", + " engine.runAndWait()\n", + " engine.stop()\n", + "\n", + "\n", + "severityDictionary=dict()\n", + "description_list = dict()\n", + "precautionDictionary=dict()\n", + "\n", + "symptoms_dict = {}\n", + "\n", + "for index, symptom in enumerate(x):\n", + " symptoms_dict[symptom] = index\n", + "def calc_condition(exp,days):\n", + " sum=0\n", + " for item in exp:\n", + " sum=sum+severityDictionary[item]\n", + " if((sum*days)/(len(exp)+1)>13):\n", + " print(\"You should take the consultation from doctor. \")\n", + " CTkLabel(root,text=\"You should take the consultation from doctor. \").pack()\n", + " else:\n", + " print(\"It might not be that bad but you should take precautions.\")\n", + " CTkLabel(root,text=\"It might not be that bad but you should take precautions.\").pack()\n", + "\n", + "\n", + "def getDescription():\n", + " global description_list\n", + " with open('MasterData/symptom_Description.csv') as csv_file:\n", + " csv_reader = csv.reader(csv_file, delimiter=',')\n", + " line_count = 0\n", + " for row in csv_reader:\n", + " _description={row[0]:row[1]}\n", + " description_list.update(_description)\n", + "\n", + "\n", + "\n", + "\n", + "def getSeverityDict():\n", + " global severityDictionary\n", + " with open('MasterData/symptom_severity.csv') as csv_file:\n", + "\n", + " csv_reader = csv.reader(csv_file, delimiter=',')\n", + " line_count = 0\n", + " try:\n", + " for row in csv_reader:\n", + " _diction={row[0]:int(row[1])}\n", + " severityDictionary.update(_diction)\n", + " except:\n", + " pass\n", + "\n", + "\n", + "def getprecautionDict():\n", + " global precautionDictionary\n", + " with open('MasterData/symptom_precaution.csv') as csv_file:\n", + "\n", + " csv_reader = csv.reader(csv_file, delimiter=',')\n", + " line_count = 0\n", + " for row in csv_reader:\n", + " _prec={row[0]:[row[1],row[2],row[3],row[4]]}\n", + " precautionDictionary.update(_prec)\n", + "\n", + "\n", + "\"\"\"def getInfo():\n", + " print(\"-----------------------------------HealthCare ChatBot-----------------------------------\")\n", + " print(\"\\nYour Name? \\t\\t\\t\\t\",end=\"->\")\n", + " name=input(\"\")\n", + " print(\"Hello, \",name)\"\"\"\n", + "\n", + "def check_pattern(dis_list,inp):\n", + " pred_list=[]\n", + " inp=inp.replace(' ','_')\n", + " patt = f\"{inp}\"\n", + " regexp = re.compile(patt)\n", + " pred_list=[item for item in dis_list if regexp.search(item)]\n", + " if(len(pred_list)>0):\n", + " return 1,pred_list\n", + " else:\n", + " return 0,[]\n", + "def sec_predict(symptoms_exp):\n", + " df = pd.read_csv('Data/Training.csv')\n", + " X = df.iloc[:, :-1]\n", + " y = df['prognosis']\n", + " X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=20)\n", + " rf_clf = DecisionTreeClassifier()\n", + " rf_clf.fit(X_train, y_train)\n", + "\n", + " symptoms_dict = {symptom: index for index, symptom in enumerate(X)}\n", + " input_vector = np.zeros(len(symptoms_dict))\n", + " for item in symptoms_exp:\n", + " input_vector[[symptoms_dict[item]]] = 1\n", + "\n", + " return rf_clf.predict([input_vector])\n", + "\n", + "\n", + "def print_disease(node):\n", + " node = node[0]\n", + " val = node.nonzero() \n", + " disease = le.inverse_transform(val[0])\n", + " return list(map(lambda x:x.strip(),list(disease)))\n", + "\n", + "def tree_to_code(tree, feature_names):\n", + " tree_ = tree.tree_\n", + " feature_name = [\n", + " feature_names[i] if i != _tree.TREE_UNDEFINED else \"undefined!\"\n", + " for i in tree_.feature\n", + " ]\n", + "\n", + " chk_dis=\",\".join(feature_names).split(\",\")\n", + " symptoms_present = []\n", + " print(\"-----------------------------------HealthCare ChatBot-----------------------------------\")\n", + " print(\"\\nYour Name? \\t\\t\\t\\t\",end=\"->\")\n", + " name=input(\"\")\n", + " print(\"Hello, \",name)\n", + "\n", + " while True:\n", + "\n", + " print(\"\\nEnter the symptom you are experiencing \\t\\t\",end=\"->\")\n", + " CTkLabel(root,text=\"Enter the symptom you are experiencing\").pack()\n", + " disease_input = input(\"\")\n", + " conf,cnf_dis=check_pattern(chk_dis,disease_input)\n", + " if conf==1:\n", + " print(\"searches related to input: \")\n", + " for num,it in enumerate(cnf_dis):\n", + " print(num,\")\",it)\n", + " if num!=0:\n", + " print(f\"Select the one you meant (0 - {num}): \", end=\"\")\n", + " conf_inp = int(input(\"\"))\n", + " else:\n", + " conf_inp=0\n", + "\n", + " disease_input=cnf_dis[conf_inp]\n", + " break\n", + " # print(\"Did you mean: \",cnf_dis,\"?(yes/no) :\",end=\"\")\n", + " # conf_inp = input(\"\")\n", + " # if(conf_inp==\"yes\"):\n", + " # break\n", + " else:\n", + " print(\"Enter valid symptom.\")\n", + "\n", + " while True:\n", + " try:\n", + " CTkLabel(root,text=\"Okay. From how many days ? : \").pack()\n", + " num_days=int(input(\"Okay. From how many days ? : \"))\n", + " break\n", + " except:\n", + " print(\"Enter valid input.\")\n", + " CTkLabel(root,text=\"Enter valid input. \").pack()\n", + " def recurse(node, depth):\n", + " indent = \" \" * depth\n", + " if tree_.feature[node] != _tree.TREE_UNDEFINED:\n", + " name = feature_name[node]\n", + " threshold = tree_.threshold[node]\n", + "\n", + " if name == disease_input:\n", + " val = 1\n", + " else:\n", + " val = 0\n", + " if val <= threshold:\n", + " recurse(tree_.children_left[node], depth + 1)\n", + " else:\n", + " symptoms_present.append(name)\n", + " recurse(tree_.children_right[node], depth + 1)\n", + " else:\n", + " present_disease = print_disease(tree_.value[node])\n", + " # print( \"You may have \" + present_disease )\n", + " red_cols = reduced_data.columns \n", + " symptoms_given = red_cols[reduced_data.loc[present_disease].values[0].nonzero()]\n", + " # dis_list=list(symptoms_present)\n", + " # if len(dis_list)!=0:\n", + " # print(\"symptoms present \" + str(list(symptoms_present)))\n", + " # print(\"symptoms given \" + str(list(symptoms_given)) )\n", + " print(\"Are you experiencing any \")\n", + " CTkLabel(root,text=\"Are you experiencing any \").pack()\n", + " symptoms_exp=[]\n", + " for syms in list(symptoms_given):\n", + " inp=\"\"\n", + " print(syms,\"? : \",end='')\n", + " CTkLabel(root,text=syms).pack()\n", + " while True:\n", + " inp=input(\"\")\n", + " if(inp==\"yes\" or inp==\"no\"):\n", + " break\n", + " else:\n", + " print(\"provide proper answers i.e. (yes/no) : \",end=\"\")\n", + " CTkLabel(root,text=\"provide proper answers i.e. (yes/no) : \").pack()\n", + " if(inp==\"yes\"):\n", + " symptoms_exp.append(syms)\n", + "\n", + " second_prediction=sec_predict(symptoms_exp)\n", + " # print(second_prediction)\n", + " calc_condition(symptoms_exp,num_days)\n", + " if(present_disease[0]==second_prediction[0]):\n", + " print(\"You may have \", present_disease[0])\n", + " CTkLabel(root, text=\"You may have \" + present_disease[0]).pack()\n", + " print(description_list[present_disease[0]])\n", + " CTkLabel(root,text=description_list[present_disease[0]]).pack()\n", + "\n", + " # readn(f\"You may have {present_disease[0]}\")\n", + " # readn(f\"{description_list[present_disease[0]]}\")\n", + "\n", + " else:\n", + " print(\"You may have \", present_disease[0], \"or \", second_prediction[0])\n", + " CTkLabel(root, text=\"You may have \" + present_disease[0] + \" or \" + second_prediction[0]).pack()\n", + " print(description_list[present_disease[0]])\n", + " CTkLabel(root,text=description_list[present_disease[0]]).pack()\n", + " print(description_list[second_prediction[0]])\n", + " CTkLabel(root,text=description_list[second_prediction[0]]).pack()\n", + "\n", + " # print(description_list[present_disease[0]])\n", + " precution_list=precautionDictionary[present_disease[0]]\n", + " print(\"Take following measures : \")\n", + " CTkLabel(root,text=\"Take following measures : \").pack()\n", + " for i,j in enumerate(precution_list):\n", + " print(i+1,\")\",j)\n", + " CTkLabel(root, text=str(i+1) + \")\" + j).pack()\n", + "\n", + " # confidence_level = (1.0*len(symptoms_present))/len(symptoms_given)\n", + " # print(\"confidence level is \" + str(confidence_level))\n", + "\n", + " recurse(0, 1)\n", + "getSeverityDict()\n", + "getDescription()\n", + "getprecautionDict()\n", + "#getInfo()\n", + "tree_to_code(clf,cols)\n", + "print(\"----------------------------------------------------------------------------------------\")\n", + "root.mainloop()\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "33356b87", + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ef5690a3", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f2d9076c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8da9b836", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "692fc2bd", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6df23640", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "73656cd0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "99b80946", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "22915c77", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "99f4268c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "26bd4243", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b8536727", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "040a5238", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "057b703f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3c5cb9b7", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "17ff2ef0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0413475c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "11108558", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b89387c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f26c8793", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d9ae7758", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f982b6ce", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c5a59435", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6016454c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cfdb314f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f33128a5", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4e929f29", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bb0d24c1", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e3a79bef", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "56490227", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8e5d2abd", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a907f0e5", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9076896e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "50497f6f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "17003184", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "31a63d8f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f4e2e464", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ca3d4e43", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b49ab223", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ed61f368", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "81229a84", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "696b07b9", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47e87abb", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fa51a573", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "565866d0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "40bd7b20", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5f066347", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1db54f9e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eeda3dfd", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "09c9a00e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "04e8d95b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "038a446c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "abda2d7c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e24ae74b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "13923adb", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3d747318", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e72165ec", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b15dec7b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dd89d4aa", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f972bb8e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1af5105f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "88f01100", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0df9375a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9966a474", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "69306d0e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "caba5c9d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1754a8fe", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6c3f56f0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3a3f372e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9ebb9c25", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "055efe1a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "86867f78", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63b607b1", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "77c442bb", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b65e9a90", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "15c8f1a7", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e91f9264", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cdcbb7e3", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "307aa1e7", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b0358205", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6dc329a8", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0ef3301d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "678d62d0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "90b07348", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9b0bd16b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4344bf97", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b70d6471", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d54b1c77", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "52d7450c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "16a710cb", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "56cf61fd", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "69924d0e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "41b9883f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aff0f483", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "65ef9f4a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bc2d99a9", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "38198973", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7d16d1a7", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5e7e055b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "86f1c86a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d8c3fb0c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "49fbca4e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "076037fb", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3f4f884e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "837ebbd2", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2938bc4c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f9dc8a82", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "693eda76", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2a5ed572", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3074f79b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c4c557e0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c08557e8", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "86498931", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9d06f490", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2c6ce44c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "666e89f4", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "781fbbf0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dd4a6186", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "30b8d70d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0da7dc5a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ca01a51d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8bc5e502", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d400bfac", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e0713b39", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e22e5aa0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e510d538", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c5d076cd", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0ac2d344", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "83de60d6", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/bg.png b/bg.png new file mode 100644 index 0000000..dd5ed2e Binary files /dev/null and b/bg.png differ diff --git a/botty.ipynb b/botty.ipynb new file mode 100644 index 0000000..c427097 --- /dev/null +++ b/botty.ipynb @@ -0,0 +1,2199 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "36cf8e1d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.9741413218198726\n", + "for svm: \n", + "1.0\n", + "-----------------------------------HealthCare ChatBot-----------------------------------\n", + "\n", + "Your Name? \t\t\t\t->Soham\n", + "Hello, Soham\n", + "\n", + "Enter the symptom you are experiencing \t\t->fever\n", + "searches related to input: \n", + "0 ) high_fever\n", + "1 ) mild_fever\n", + "Select the one you meant (0 - 1): 0\n", + "Okay. From how many days ? : 4\n", + "Are you experiencing any \n", + "back_pain ? : no\n", + "weakness_in_limbs ? : no\n", + "neck_pain ? : no\n", + "dizziness ? : no\n", + "loss_of_balance ? : no\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\soham\\anaconda3\\envs\\healthbot\\lib\\site-packages\\sklearn\\base.py:439: UserWarning: X does not have valid feature names, but DecisionTreeClassifier was fitted with feature names\n", + " warnings.warn(\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "It might not be that bad but you should take precautions.\n", + "You may have Cervical spondylosis or Impetigo\n", + "Cervical spondylosis is a general term for age-related wear and tear affecting the spinal disks in your neck. As the disks dehydrate and shrink, signs of osteoarthritis develop, including bony projections along the edges of bones (bone spurs).\n", + "Impetigo (im-puh-TIE-go) is a common and highly contagious skin infection that mainly affects infants and children. Impetigo usually appears as red sores on the face, especially around a child's nose and mouth, and on hands and feet. The sores burst and develop honey-colored crusts.\n", + "Take following measures : \n", + "1 ) use heating pad or cold pack\n", + "2 ) exercise\n", + "3 ) take otc pain reliver\n", + "4 ) consult doctor\n", + "----------------------------------------------------------------------------------------\n", + "0.9766013464201185\n", + "for svm: \n", + "1.0\n", + "-----------------------------------HealthCare ChatBot-----------------------------------\n", + "\n", + "Your Name? \t\t\t\t->" + ] + } + ], + "source": [ + "import re\n", + "import pandas as pd\n", + "import pyttsx3\n", + "from sklearn import preprocessing\n", + "from sklearn.tree import DecisionTreeClassifier,_tree\n", + "import numpy as np\n", + "from sklearn.model_selection import train_test_split\n", + "from sklearn.model_selection import cross_val_score\n", + "from sklearn.svm import SVC\n", + "import csv\n", + "import warnings\n", + "warnings.filterwarnings(\"ignore\", category=DeprecationWarning)\n", + "\n", + "\n", + "training = pd.read_csv('Data/Training.csv')\n", + "testing= pd.read_csv('Data/Testing.csv')\n", + "cols= training.columns\n", + "cols= cols[:-1]\n", + "x = training[cols]\n", + "y = training['prognosis']\n", + "y1= y\n", + "\n", + "\n", + "reduced_data = training.groupby(training['prognosis']).max()\n", + "\n", + "#mapping strings to numbers\n", + "le = preprocessing.LabelEncoder()\n", + "le.fit(y)\n", + "y = le.transform(y)\n", + "\n", + "\n", + "x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.33, random_state=42)\n", + "testx = testing[cols]\n", + "testy = testing['prognosis'] \n", + "testy = le.transform(testy)\n", + "\n", + "\n", + "clf1 = DecisionTreeClassifier()\n", + "clf = clf1.fit(x_train,y_train)\n", + "# print(clf.score(x_train,y_train))\n", + "# print (\"cross result========\")\n", + "scores = cross_val_score(clf, x_test, y_test, cv=3)\n", + "# print (scores)\n", + "print (scores.mean())\n", + "\n", + "\n", + "model=SVC()\n", + "model.fit(x_train,y_train)\n", + "print(\"for svm: \")\n", + "print(model.score(x_test,y_test))\n", + "\n", + "importances = clf.feature_importances_\n", + "indices = np.argsort(importances)[::-1]\n", + "features = cols\n", + "\n", + "def readn(nstr):\n", + " engine = pyttsx3.init()\n", + "\n", + " engine.setProperty('voice', \"english+f5\")\n", + " engine.setProperty('rate', 130)\n", + "\n", + " engine.say(nstr)\n", + " engine.runAndWait()\n", + " engine.stop()\n", + "\n", + "\n", + "severityDictionary=dict()\n", + "description_list = dict()\n", + "precautionDictionary=dict()\n", + "\n", + "symptoms_dict = {}\n", + "\n", + "for index, symptom in enumerate(x):\n", + " symptoms_dict[symptom] = index\n", + "def calc_condition(exp,days):\n", + " sum=0\n", + " for item in exp:\n", + " sum=sum+severityDictionary[item]\n", + " if((sum*days)/(len(exp)+1)>13):\n", + " print(\"You should take the consultation from doctor. \")\n", + " else:\n", + " print(\"It might not be that bad but you should take precautions.\")\n", + "\n", + "\n", + "def getDescription():\n", + " global description_list\n", + " with open('MasterData/symptom_Description.csv') as csv_file:\n", + " csv_reader = csv.reader(csv_file, delimiter=',')\n", + " line_count = 0\n", + " for row in csv_reader:\n", + " _description={row[0]:row[1]}\n", + " description_list.update(_description)\n", + "\n", + "\n", + "\n", + "\n", + "def getSeverityDict():\n", + " global severityDictionary\n", + " with open('MasterData/symptom_severity.csv') as csv_file:\n", + "\n", + " csv_reader = csv.reader(csv_file, delimiter=',')\n", + " line_count = 0\n", + " try:\n", + " for row in csv_reader:\n", + " _diction={row[0]:int(row[1])}\n", + " severityDictionary.update(_diction)\n", + " except:\n", + " pass\n", + "\n", + "\n", + "def getprecautionDict():\n", + " global precautionDictionary\n", + " with open('MasterData/symptom_precaution.csv') as csv_file:\n", + "\n", + " csv_reader = csv.reader(csv_file, delimiter=',')\n", + " line_count = 0\n", + " for row in csv_reader:\n", + " _prec={row[0]:[row[1],row[2],row[3],row[4]]}\n", + " precautionDictionary.update(_prec)\n", + "\n", + "\n", + "def getInfo():\n", + " print(\"-----------------------------------HealthCare ChatBot-----------------------------------\")\n", + " print(\"\\nYour Name? \\t\\t\\t\\t\",end=\"->\")\n", + " name=input(\"\")\n", + " print(\"Hello, \",name)\n", + "\n", + "def check_pattern(dis_list,inp):\n", + " pred_list=[]\n", + " inp=inp.replace(' ','_')\n", + " patt = f\"{inp}\"\n", + " regexp = re.compile(patt)\n", + " pred_list=[item for item in dis_list if regexp.search(item)]\n", + " if(len(pred_list)>0):\n", + " return 1,pred_list\n", + " else:\n", + " return 0,[]\n", + "def sec_predict(symptoms_exp):\n", + " df = pd.read_csv('Data/Training.csv')\n", + " X = df.iloc[:, :-1]\n", + " y = df['prognosis']\n", + " X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=20)\n", + " rf_clf = DecisionTreeClassifier()\n", + " rf_clf.fit(X_train, y_train)\n", + "\n", + " symptoms_dict = {symptom: index for index, symptom in enumerate(X)}\n", + " input_vector = np.zeros(len(symptoms_dict))\n", + " for item in symptoms_exp:\n", + " input_vector[[symptoms_dict[item]]] = 1\n", + "\n", + " return rf_clf.predict([input_vector])\n", + "\n", + "\n", + "def print_disease(node):\n", + " node = node[0]\n", + " val = node.nonzero() \n", + " disease = le.inverse_transform(val[0])\n", + " return list(map(lambda x:x.strip(),list(disease)))\n", + "\n", + "def tree_to_code(tree, feature_names):\n", + " tree_ = tree.tree_\n", + " feature_name = [\n", + " feature_names[i] if i != _tree.TREE_UNDEFINED else \"undefined!\"\n", + " for i in tree_.feature\n", + " ]\n", + "\n", + " chk_dis=\",\".join(feature_names).split(\",\")\n", + " symptoms_present = []\n", + "\n", + " while True:\n", + "\n", + " print(\"\\nEnter the symptom you are experiencing \\t\\t\",end=\"->\")\n", + " disease_input = input(\"\")\n", + " conf,cnf_dis=check_pattern(chk_dis,disease_input)\n", + " if conf==1:\n", + " print(\"searches related to input: \")\n", + " for num,it in enumerate(cnf_dis):\n", + " print(num,\")\",it)\n", + " if num!=0:\n", + " print(f\"Select the one you meant (0 - {num}): \", end=\"\")\n", + " conf_inp = int(input(\"\"))\n", + " else:\n", + " conf_inp=0\n", + "\n", + " disease_input=cnf_dis[conf_inp]\n", + " break\n", + " # print(\"Did you mean: \",cnf_dis,\"?(yes/no) :\",end=\"\")\n", + " # conf_inp = input(\"\")\n", + " # if(conf_inp==\"yes\"):\n", + " # break\n", + " else:\n", + " print(\"Enter valid symptom.\")\n", + "\n", + " while True:\n", + " try:\n", + " num_days=int(input(\"Okay. From how many days ? : \"))\n", + " break\n", + " except:\n", + " print(\"Enter valid input.\")\n", + " def recurse(node, depth):\n", + " indent = \" \" * depth\n", + " if tree_.feature[node] != _tree.TREE_UNDEFINED:\n", + " name = feature_name[node]\n", + " threshold = tree_.threshold[node]\n", + "\n", + " if name == disease_input:\n", + " val = 1\n", + " else:\n", + " val = 0\n", + " if val <= threshold:\n", + " recurse(tree_.children_left[node], depth + 1)\n", + " else:\n", + " symptoms_present.append(name)\n", + " recurse(tree_.children_right[node], depth + 1)\n", + " else:\n", + " present_disease = print_disease(tree_.value[node])\n", + " # print( \"You may have \" + present_disease )\n", + " red_cols = reduced_data.columns \n", + " symptoms_given = red_cols[reduced_data.loc[present_disease].values[0].nonzero()]\n", + " # dis_list=list(symptoms_present)\n", + " # if len(dis_list)!=0:\n", + " # print(\"symptoms present \" + str(list(symptoms_present)))\n", + " # print(\"symptoms given \" + str(list(symptoms_given)) )\n", + " print(\"Are you experiencing any \")\n", + " symptoms_exp=[]\n", + " for syms in list(symptoms_given):\n", + " inp=\"\"\n", + " print(syms,\"? : \",end='')\n", + " while True:\n", + " inp=input(\"\")\n", + " if(inp==\"yes\" or inp==\"no\"):\n", + " break\n", + " else:\n", + " print(\"provide proper answers i.e. (yes/no) : \",end=\"\")\n", + " if(inp==\"yes\"):\n", + " symptoms_exp.append(syms)\n", + "\n", + " second_prediction=sec_predict(symptoms_exp)\n", + " # print(second_prediction)\n", + " calc_condition(symptoms_exp,num_days)\n", + " if(present_disease[0]==second_prediction[0]):\n", + " print(\"You may have \", present_disease[0])\n", + " print(description_list[present_disease[0]])\n", + "\n", + " # readn(f\"You may have {present_disease[0]}\")\n", + " # readn(f\"{description_list[present_disease[0]]}\")\n", + "\n", + " else:\n", + " print(\"You may have \", present_disease[0], \"or \", second_prediction[0])\n", + " print(description_list[present_disease[0]])\n", + " print(description_list[second_prediction[0]])\n", + "\n", + " # print(description_list[present_disease[0]])\n", + " precution_list=precautionDictionary[present_disease[0]]\n", + " print(\"Take following measures : \")\n", + " for i,j in enumerate(precution_list):\n", + " print(i+1,\")\",j)\n", + "\n", + " # confidence_level = (1.0*len(symptoms_present))/len(symptoms_given)\n", + " # print(\"confidence level is \" + str(confidence_level))\n", + "\n", + " recurse(0, 1)\n", + "getSeverityDict()\n", + "getDescription()\n", + "getprecautionDict()\n", + "getInfo()\n", + "tree_to_code(clf,cols)\n", + "print(\"----------------------------------------------------------------------------------------\")\n", + "\n", + "import re\n", + "import pandas as pd\n", + "import pyttsx3\n", + "from sklearn import preprocessing\n", + "from sklearn.tree import DecisionTreeClassifier,_tree\n", + "import numpy as np\n", + "from sklearn.model_selection import train_test_split\n", + "from sklearn.model_selection import cross_val_score\n", + "from sklearn.svm import SVC\n", + "import csv\n", + "import warnings\n", + "warnings.filterwarnings(\"ignore\", category=DeprecationWarning)\n", + "\n", + "\n", + "training = pd.read_csv('Data/Training.csv')\n", + "testing= pd.read_csv('Data/Testing.csv')\n", + "cols= training.columns\n", + "cols= cols[:-1]\n", + "x = training[cols]\n", + "y = training['prognosis']\n", + "y1= y\n", + "\n", + "\n", + "reduced_data = training.groupby(training['prognosis']).max()\n", + "\n", + "#mapping strings to numbers\n", + "le = preprocessing.LabelEncoder()\n", + "le.fit(y)\n", + "y = le.transform(y)\n", + "\n", + "\n", + "x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.33, random_state=42)\n", + "testx = testing[cols]\n", + "testy = testing['prognosis'] \n", + "testy = le.transform(testy)\n", + "\n", + "\n", + "clf1 = DecisionTreeClassifier()\n", + "clf = clf1.fit(x_train,y_train)\n", + "# print(clf.score(x_train,y_train))\n", + "# print (\"cross result========\")\n", + "scores = cross_val_score(clf, x_test, y_test, cv=3)\n", + "# print (scores)\n", + "print (scores.mean())\n", + "\n", + "\n", + "model=SVC()\n", + "model.fit(x_train,y_train)\n", + "print(\"for svm: \")\n", + "print(model.score(x_test,y_test))\n", + "\n", + "importances = clf.feature_importances_\n", + "indices = np.argsort(importances)[::-1]\n", + "features = cols\n", + "\n", + "def readn(nstr):\n", + " engine = pyttsx3.init()\n", + "\n", + " engine.setProperty('voice', \"english+f5\")\n", + " engine.setProperty('rate', 130)\n", + "\n", + " engine.say(nstr)\n", + " engine.runAndWait()\n", + " engine.stop()\n", + "\n", + "\n", + "severityDictionary=dict()\n", + "description_list = dict()\n", + "precautionDictionary=dict()\n", + "\n", + "symptoms_dict = {}\n", + "\n", + "for index, symptom in enumerate(x):\n", + " symptoms_dict[symptom] = index\n", + "def calc_condition(exp,days):\n", + " sum=0\n", + " for item in exp:\n", + " sum=sum+severityDictionary[item]\n", + " if((sum*days)/(len(exp)+1)>13):\n", + " print(\"You should take the consultation from doctor. \")\n", + " else:\n", + " print(\"It might not be that bad but you should take precautions.\")\n", + "\n", + "\n", + "def getDescription():\n", + " global description_list\n", + " with open('MasterData/symptom_Description.csv') as csv_file:\n", + " csv_reader = csv.reader(csv_file, delimiter=',')\n", + " line_count = 0\n", + " for row in csv_reader:\n", + " _description={row[0]:row[1]}\n", + " description_list.update(_description)\n", + "\n", + "\n", + "\n", + "\n", + "def getSeverityDict():\n", + " global severityDictionary\n", + " with open('MasterData/symptom_severity.csv') as csv_file:\n", + "\n", + " csv_reader = csv.reader(csv_file, delimiter=',')\n", + " line_count = 0\n", + " try:\n", + " for row in csv_reader:\n", + " _diction={row[0]:int(row[1])}\n", + " severityDictionary.update(_diction)\n", + " except:\n", + " pass\n", + "\n", + "\n", + "def getprecautionDict():\n", + " global precautionDictionary\n", + " with open('MasterData/symptom_precaution.csv') as csv_file:\n", + "\n", + " csv_reader = csv.reader(csv_file, delimiter=',')\n", + " line_count = 0\n", + " for row in csv_reader:\n", + " _prec={row[0]:[row[1],row[2],row[3],row[4]]}\n", + " precautionDictionary.update(_prec)\n", + "\n", + "\n", + "def getInfo():\n", + " print(\"-----------------------------------HealthCare ChatBot-----------------------------------\")\n", + " print(\"\\nYour Name? \\t\\t\\t\\t\",end=\"->\")\n", + " name=input(\"\")\n", + " print(\"Hello, \",name)\n", + "\n", + "def check_pattern(dis_list,inp):\n", + " pred_list=[]\n", + " inp=inp.replace(' ','_')\n", + " patt = f\"{inp}\"\n", + " regexp = re.compile(patt)\n", + " pred_list=[item for item in dis_list if regexp.search(item)]\n", + " if(len(pred_list)>0):\n", + " return 1,pred_list\n", + " else:\n", + " return 0,[]\n", + "def sec_predict(symptoms_exp):\n", + " df = pd.read_csv('Data/Training.csv')\n", + " X = df.iloc[:, :-1]\n", + " y = df['prognosis']\n", + " X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=20)\n", + " rf_clf = DecisionTreeClassifier()\n", + " rf_clf.fit(X_train, y_train)\n", + "\n", + " symptoms_dict = {symptom: index for index, symptom in enumerate(X)}\n", + " input_vector = np.zeros(len(symptoms_dict))\n", + " for item in symptoms_exp:\n", + " input_vector[[symptoms_dict[item]]] = 1\n", + "\n", + " return rf_clf.predict([input_vector])\n", + "\n", + "\n", + "def print_disease(node):\n", + " node = node[0]\n", + " val = node.nonzero() \n", + " disease = le.inverse_transform(val[0])\n", + " return list(map(lambda x:x.strip(),list(disease)))\n", + "\n", + "def tree_to_code(tree, feature_names):\n", + " tree_ = tree.tree_\n", + " feature_name = [\n", + " feature_names[i] if i != _tree.TREE_UNDEFINED else \"undefined!\"\n", + " for i in tree_.feature\n", + " ]\n", + "\n", + " chk_dis=\",\".join(feature_names).split(\",\")\n", + " symptoms_present = []\n", + "\n", + " while True:\n", + "\n", + " print(\"\\nEnter the symptom you are experiencing \\t\\t\",end=\"->\")\n", + " disease_input = input(\"\")\n", + " conf,cnf_dis=check_pattern(chk_dis,disease_input)\n", + " if conf==1:\n", + " print(\"searches related to input: \")\n", + " for num,it in enumerate(cnf_dis):\n", + " print(num,\")\",it)\n", + " if num!=0:\n", + " print(f\"Select the one you meant (0 - {num}): \", end=\"\")\n", + " conf_inp = int(input(\"\"))\n", + " else:\n", + " conf_inp=0\n", + "\n", + " disease_input=cnf_dis[conf_inp]\n", + " break\n", + " # print(\"Did you mean: \",cnf_dis,\"?(yes/no) :\",end=\"\")\n", + " # conf_inp = input(\"\")\n", + " # if(conf_inp==\"yes\"):\n", + " # break\n", + " else:\n", + " print(\"Enter valid symptom.\")\n", + "\n", + " while True:\n", + " try:\n", + " num_days=int(input(\"Okay. From how many days ? : \"))\n", + " break\n", + " except:\n", + " print(\"Enter valid input.\")\n", + " def recurse(node, depth):\n", + " indent = \" \" * depth\n", + " if tree_.feature[node] != _tree.TREE_UNDEFINED:\n", + " name = feature_name[node]\n", + " threshold = tree_.threshold[node]\n", + "\n", + " if name == disease_input:\n", + " val = 1\n", + " else:\n", + " val = 0\n", + " if val <= threshold:\n", + " recurse(tree_.children_left[node], depth + 1)\n", + " else:\n", + " symptoms_present.append(name)\n", + " recurse(tree_.children_right[node], depth + 1)\n", + " else:\n", + " present_disease = print_disease(tree_.value[node])\n", + " # print( \"You may have \" + present_disease )\n", + " red_cols = reduced_data.columns \n", + " symptoms_given = red_cols[reduced_data.loc[present_disease].values[0].nonzero()]\n", + " # dis_list=list(symptoms_present)\n", + " # if len(dis_list)!=0:\n", + " # print(\"symptoms present \" + str(list(symptoms_present)))\n", + " # print(\"symptoms given \" + str(list(symptoms_given)) )\n", + " print(\"Are you experiencing any \")\n", + " symptoms_exp=[]\n", + " for syms in list(symptoms_given):\n", + " inp=\"\"\n", + " print(syms,\"? : \",end='')\n", + " while True:\n", + " inp=input(\"\")\n", + " if(inp==\"yes\" or inp==\"no\"):\n", + " break\n", + " else:\n", + " print(\"provide proper answers i.e. (yes/no) : \",end=\"\")\n", + " if(inp==\"yes\"):\n", + " symptoms_exp.append(syms)\n", + "\n", + " second_prediction=sec_predict(symptoms_exp)\n", + " # print(second_prediction)\n", + " calc_condition(symptoms_exp,num_days)\n", + " if(present_disease[0]==second_prediction[0]):\n", + " print(\"You may have \", present_disease[0])\n", + " print(description_list[present_disease[0]])\n", + "\n", + " # readn(f\"You may have {present_disease[0]}\")\n", + " # readn(f\"{description_list[present_disease[0]]}\")\n", + "\n", + " else:\n", + " print(\"You may have \", present_disease[0], \"or \", second_prediction[0])\n", + " print(description_list[present_disease[0]])\n", + " print(description_list[second_prediction[0]])\n", + "\n", + " # print(description_list[present_disease[0]])\n", + " precution_list=precautionDictionary[present_disease[0]]\n", + " print(\"Take following measures : \")\n", + " for i,j in enumerate(precution_list):\n", + " print(i+1,\")\",j)\n", + "\n", + " # confidence_level = (1.0*len(symptoms_present))/len(symptoms_given)\n", + " # print(\"confidence level is \" + str(confidence_level))\n", + "\n", + " recurse(0, 1)\n", + "getSeverityDict()\n", + "getDescription()\n", + "getprecautionDict()\n", + "getInfo()\n", + "tree_to_code(clf,cols)\n", + "print(\"----------------------------------------------------------------------------------------\")\n", + "\n", + "import re\n", + "import pandas as pd\n", + "import pyttsx3\n", + "from sklearn import preprocessing\n", + "from sklearn.tree import DecisionTreeClassifier,_tree\n", + "import numpy as np\n", + "from sklearn.model_selection import train_test_split\n", + "from sklearn.model_selection import cross_val_score\n", + "from sklearn.svm import SVC\n", + "import csv\n", + "import warnings\n", + "warnings.filterwarnings(\"ignore\", category=DeprecationWarning)\n", + "\n", + "\n", + "training = pd.read_csv('Data/Training.csv')\n", + "testing= pd.read_csv('Data/Testing.csv')\n", + "cols= training.columns\n", + "cols= cols[:-1]\n", + "x = training[cols]\n", + "y = training['prognosis']\n", + "y1= y\n", + "\n", + "\n", + "reduced_data = training.groupby(training['prognosis']).max()\n", + "\n", + "#mapping strings to numbers\n", + "le = preprocessing.LabelEncoder()\n", + "le.fit(y)\n", + "y = le.transform(y)\n", + "\n", + "\n", + "x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.33, random_state=42)\n", + "testx = testing[cols]\n", + "testy = testing['prognosis'] \n", + "testy = le.transform(testy)\n", + "\n", + "\n", + "clf1 = DecisionTreeClassifier()\n", + "clf = clf1.fit(x_train,y_train)\n", + "# print(clf.score(x_train,y_train))\n", + "# print (\"cross result========\")\n", + "scores = cross_val_score(clf, x_test, y_test, cv=3)\n", + "# print (scores)\n", + "print (scores.mean())\n", + "\n", + "\n", + "model=SVC()\n", + "model.fit(x_train,y_train)\n", + "print(\"for svm: \")\n", + "print(model.score(x_test,y_test))\n", + "\n", + "importances = clf.feature_importances_\n", + "indices = np.argsort(importances)[::-1]\n", + "features = cols\n", + "\n", + "def readn(nstr):\n", + " engine = pyttsx3.init()\n", + "\n", + " engine.setProperty('voice', \"english+f5\")\n", + " engine.setProperty('rate', 130)\n", + "\n", + " engine.say(nstr)\n", + " engine.runAndWait()\n", + " engine.stop()\n", + "\n", + "\n", + "severityDictionary=dict()\n", + "description_list = dict()\n", + "precautionDictionary=dict()\n", + "\n", + "symptoms_dict = {}\n", + "\n", + "for index, symptom in enumerate(x):\n", + " symptoms_dict[symptom] = index\n", + "def calc_condition(exp,days):\n", + " sum=0\n", + " for item in exp:\n", + " sum=sum+severityDictionary[item]\n", + " if((sum*days)/(len(exp)+1)>13):\n", + " print(\"You should take the consultation from doctor. \")\n", + " else:\n", + " print(\"It might not be that bad but you should take precautions.\")\n", + "\n", + "\n", + "def getDescription():\n", + " global description_list\n", + " with open('MasterData/symptom_Description.csv') as csv_file:\n", + " csv_reader = csv.reader(csv_file, delimiter=',')\n", + " line_count = 0\n", + " for row in csv_reader:\n", + " _description={row[0]:row[1]}\n", + " description_list.update(_description)\n", + "\n", + "\n", + "\n", + "\n", + "def getSeverityDict():\n", + " global severityDictionary\n", + " with open('MasterData/symptom_severity.csv') as csv_file:\n", + "\n", + " csv_reader = csv.reader(csv_file, delimiter=',')\n", + " line_count = 0\n", + " try:\n", + " for row in csv_reader:\n", + " _diction={row[0]:int(row[1])}\n", + " severityDictionary.update(_diction)\n", + " except:\n", + " pass\n", + "\n", + "\n", + "def getprecautionDict():\n", + " global precautionDictionary\n", + " with open('MasterData/symptom_precaution.csv') as csv_file:\n", + "\n", + " csv_reader = csv.reader(csv_file, delimiter=',')\n", + " line_count = 0\n", + " for row in csv_reader:\n", + " _prec={row[0]:[row[1],row[2],row[3],row[4]]}\n", + " precautionDictionary.update(_prec)\n", + "\n", + "\n", + "def getInfo():\n", + " print(\"-----------------------------------HealthCare ChatBot-----------------------------------\")\n", + " print(\"\\nYour Name? \\t\\t\\t\\t\",end=\"->\")\n", + " name=input(\"\")\n", + " print(\"Hello, \",name)\n", + "\n", + "def check_pattern(dis_list,inp):\n", + " pred_list=[]\n", + " inp=inp.replace(' ','_')\n", + " patt = f\"{inp}\"\n", + " regexp = re.compile(patt)\n", + " pred_list=[item for item in dis_list if regexp.search(item)]\n", + " if(len(pred_list)>0):\n", + " return 1,pred_list\n", + " else:\n", + " return 0,[]\n", + "def sec_predict(symptoms_exp):\n", + " df = pd.read_csv('Data/Training.csv')\n", + " X = df.iloc[:, :-1]\n", + " y = df['prognosis']\n", + " X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=20)\n", + " rf_clf = DecisionTreeClassifier()\n", + " rf_clf.fit(X_train, y_train)\n", + "\n", + " symptoms_dict = {symptom: index for index, symptom in enumerate(X)}\n", + " input_vector = np.zeros(len(symptoms_dict))\n", + " for item in symptoms_exp:\n", + " input_vector[[symptoms_dict[item]]] = 1\n", + "\n", + " return rf_clf.predict([input_vector])\n", + "\n", + "\n", + "def print_disease(node):\n", + " node = node[0]\n", + " val = node.nonzero() \n", + " disease = le.inverse_transform(val[0])\n", + " return list(map(lambda x:x.strip(),list(disease)))\n", + "\n", + "def tree_to_code(tree, feature_names):\n", + " tree_ = tree.tree_\n", + " feature_name = [\n", + " feature_names[i] if i != _tree.TREE_UNDEFINED else \"undefined!\"\n", + " for i in tree_.feature\n", + " ]\n", + "\n", + " chk_dis=\",\".join(feature_names).split(\",\")\n", + " symptoms_present = []\n", + "\n", + " while True:\n", + "\n", + " print(\"\\nEnter the symptom you are experiencing \\t\\t\",end=\"->\")\n", + " disease_input = input(\"\")\n", + " conf,cnf_dis=check_pattern(chk_dis,disease_input)\n", + " if conf==1:\n", + " print(\"searches related to input: \")\n", + " for num,it in enumerate(cnf_dis):\n", + " print(num,\")\",it)\n", + " if num!=0:\n", + " print(f\"Select the one you meant (0 - {num}): \", end=\"\")\n", + " conf_inp = int(input(\"\"))\n", + " else:\n", + " conf_inp=0\n", + "\n", + " disease_input=cnf_dis[conf_inp]\n", + " break\n", + " # print(\"Did you mean: \",cnf_dis,\"?(yes/no) :\",end=\"\")\n", + " # conf_inp = input(\"\")\n", + " # if(conf_inp==\"yes\"):\n", + " # break\n", + " else:\n", + " print(\"Enter valid symptom.\")\n", + "\n", + " while True:\n", + " try:\n", + " num_days=int(input(\"Okay. From how many days ? : \"))\n", + " break\n", + " except:\n", + " print(\"Enter valid input.\")\n", + " def recurse(node, depth):\n", + " indent = \" \" * depth\n", + " if tree_.feature[node] != _tree.TREE_UNDEFINED:\n", + " name = feature_name[node]\n", + " threshold = tree_.threshold[node]\n", + "\n", + " if name == disease_input:\n", + " val = 1\n", + " else:\n", + " val = 0\n", + " if val <= threshold:\n", + " recurse(tree_.children_left[node], depth + 1)\n", + " else:\n", + " symptoms_present.append(name)\n", + " recurse(tree_.children_right[node], depth + 1)\n", + " else:\n", + " present_disease = print_disease(tree_.value[node])\n", + " # print( \"You may have \" + present_disease )\n", + " red_cols = reduced_data.columns \n", + " symptoms_given = red_cols[reduced_data.loc[present_disease].values[0].nonzero()]\n", + " # dis_list=list(symptoms_present)\n", + " # if len(dis_list)!=0:\n", + " # print(\"symptoms present \" + str(list(symptoms_present)))\n", + " # print(\"symptoms given \" + str(list(symptoms_given)) )\n", + " print(\"Are you experiencing any \")\n", + " symptoms_exp=[]\n", + " for syms in list(symptoms_given):\n", + " inp=\"\"\n", + " print(syms,\"? : \",end='')\n", + " while True:\n", + " inp=input(\"\")\n", + " if(inp==\"yes\" or inp==\"no\"):\n", + " break\n", + " else:\n", + " print(\"provide proper answers i.e. (yes/no) : \",end=\"\")\n", + " if(inp==\"yes\"):\n", + " symptoms_exp.append(syms)\n", + "\n", + " second_prediction=sec_predict(symptoms_exp)\n", + " # print(second_prediction)\n", + " calc_condition(symptoms_exp,num_days)\n", + " if(present_disease[0]==second_prediction[0]):\n", + " print(\"You may have \", present_disease[0])\n", + " print(description_list[present_disease[0]])\n", + "\n", + " # readn(f\"You may have {present_disease[0]}\")\n", + " # readn(f\"{description_list[present_disease[0]]}\")\n", + "\n", + " else:\n", + " print(\"You may have \", present_disease[0], \"or \", second_prediction[0])\n", + " print(description_list[present_disease[0]])\n", + " print(description_list[second_prediction[0]])\n", + "\n", + " # print(description_list[present_disease[0]])\n", + " precution_list=precautionDictionary[present_disease[0]]\n", + " print(\"Take following measures : \")\n", + " for i,j in enumerate(precution_list):\n", + " print(i+1,\")\",j)\n", + "\n", + " # confidence_level = (1.0*len(symptoms_present))/len(symptoms_given)\n", + " # print(\"confidence level is \" + str(confidence_level))\n", + "\n", + " recurse(0, 1)\n", + "getSeverityDict()\n", + "getDescription()\n", + "getprecautionDict()\n", + "getInfo()\n", + "tree_to_code(clf,cols)\n", + "print(\"----------------------------------------------------------------------------------------\")\n", + "\n", + "import re\n", + "import pandas as pd\n", + "import pyttsx3\n", + "from sklearn import preprocessing\n", + "from sklearn.tree import DecisionTreeClassifier,_tree\n", + "import numpy as np\n", + "from sklearn.model_selection import train_test_split\n", + "from sklearn.model_selection import cross_val_score\n", + "from sklearn.svm import SVC\n", + "import csv\n", + "import warnings\n", + "warnings.filterwarnings(\"ignore\", category=DeprecationWarning)\n", + "\n", + "\n", + "training = pd.read_csv('Data/Training.csv')\n", + "testing= pd.read_csv('Data/Testing.csv')\n", + "cols= training.columns\n", + "cols= cols[:-1]\n", + "x = training[cols]\n", + "y = training['prognosis']\n", + "y1= y\n", + "\n", + "\n", + "reduced_data = training.groupby(training['prognosis']).max()\n", + "\n", + "#mapping strings to numbers\n", + "le = preprocessing.LabelEncoder()\n", + "le.fit(y)\n", + "y = le.transform(y)\n", + "\n", + "\n", + "x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.33, random_state=42)\n", + "testx = testing[cols]\n", + "testy = testing['prognosis'] \n", + "testy = le.transform(testy)\n", + "\n", + "\n", + "clf1 = DecisionTreeClassifier()\n", + "clf = clf1.fit(x_train,y_train)\n", + "# print(clf.score(x_train,y_train))\n", + "# print (\"cross result========\")\n", + "scores = cross_val_score(clf, x_test, y_test, cv=3)\n", + "# print (scores)\n", + "print (scores.mean())\n", + "\n", + "\n", + "model=SVC()\n", + "model.fit(x_train,y_train)\n", + "print(\"for svm: \")\n", + "print(model.score(x_test,y_test))\n", + "\n", + "importances = clf.feature_importances_\n", + "indices = np.argsort(importances)[::-1]\n", + "features = cols\n", + "\n", + "def readn(nstr):\n", + " engine = pyttsx3.init()\n", + "\n", + " engine.setProperty('voice', \"english+f5\")\n", + " engine.setProperty('rate', 130)\n", + "\n", + " engine.say(nstr)\n", + " engine.runAndWait()\n", + " engine.stop()\n", + "\n", + "\n", + "severityDictionary=dict()\n", + "description_list = dict()\n", + "precautionDictionary=dict()\n", + "\n", + "symptoms_dict = {}\n", + "\n", + "for index, symptom in enumerate(x):\n", + " symptoms_dict[symptom] = index\n", + "def calc_condition(exp,days):\n", + " sum=0\n", + " for item in exp:\n", + " sum=sum+severityDictionary[item]\n", + " if((sum*days)/(len(exp)+1)>13):\n", + " print(\"You should take the consultation from doctor. \")\n", + " else:\n", + " print(\"It might not be that bad but you should take precautions.\")\n", + "\n", + "\n", + "def getDescription():\n", + " global description_list\n", + " with open('MasterData/symptom_Description.csv') as csv_file:\n", + " csv_reader = csv.reader(csv_file, delimiter=',')\n", + " line_count = 0\n", + " for row in csv_reader:\n", + " _description={row[0]:row[1]}\n", + " description_list.update(_description)\n", + "\n", + "\n", + "\n", + "\n", + "def getSeverityDict():\n", + " global severityDictionary\n", + " with open('MasterData/symptom_severity.csv') as csv_file:\n", + "\n", + " csv_reader = csv.reader(csv_file, delimiter=',')\n", + " line_count = 0\n", + " try:\n", + " for row in csv_reader:\n", + " _diction={row[0]:int(row[1])}\n", + " severityDictionary.update(_diction)\n", + " except:\n", + " pass\n", + "\n", + "\n", + "def getprecautionDict():\n", + " global precautionDictionary\n", + " with open('MasterData/symptom_precaution.csv') as csv_file:\n", + "\n", + " csv_reader = csv.reader(csv_file, delimiter=',')\n", + " line_count = 0\n", + " for row in csv_reader:\n", + " _prec={row[0]:[row[1],row[2],row[3],row[4]]}\n", + " precautionDictionary.update(_prec)\n", + "\n", + "\n", + "def getInfo():\n", + " print(\"-----------------------------------HealthCare ChatBot-----------------------------------\")\n", + " print(\"\\nYour Name? \\t\\t\\t\\t\",end=\"->\")\n", + " name=input(\"\")\n", + " print(\"Hello, \",name)\n", + "\n", + "def check_pattern(dis_list,inp):\n", + " pred_list=[]\n", + " inp=inp.replace(' ','_')\n", + " patt = f\"{inp}\"\n", + " regexp = re.compile(patt)\n", + " pred_list=[item for item in dis_list if regexp.search(item)]\n", + " if(len(pred_list)>0):\n", + " return 1,pred_list\n", + " else:\n", + " return 0,[]\n", + "def sec_predict(symptoms_exp):\n", + " df = pd.read_csv('Data/Training.csv')\n", + " X = df.iloc[:, :-1]\n", + " y = df['prognosis']\n", + " X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=20)\n", + " rf_clf = DecisionTreeClassifier()\n", + " rf_clf.fit(X_train, y_train)\n", + "\n", + " symptoms_dict = {symptom: index for index, symptom in enumerate(X)}\n", + " input_vector = np.zeros(len(symptoms_dict))\n", + " for item in symptoms_exp:\n", + " input_vector[[symptoms_dict[item]]] = 1\n", + "\n", + " return rf_clf.predict([input_vector])\n", + "\n", + "\n", + "def print_disease(node):\n", + " node = node[0]\n", + " val = node.nonzero() \n", + " disease = le.inverse_transform(val[0])\n", + " return list(map(lambda x:x.strip(),list(disease)))\n", + "\n", + "def tree_to_code(tree, feature_names):\n", + " tree_ = tree.tree_\n", + " feature_name = [\n", + " feature_names[i] if i != _tree.TREE_UNDEFINED else \"undefined!\"\n", + " for i in tree_.feature\n", + " ]\n", + "\n", + " chk_dis=\",\".join(feature_names).split(\",\")\n", + " symptoms_present = []\n", + "\n", + " while True:\n", + "\n", + " print(\"\\nEnter the symptom you are experiencing \\t\\t\",end=\"->\")\n", + " disease_input = input(\"\")\n", + " conf,cnf_dis=check_pattern(chk_dis,disease_input)\n", + " if conf==1:\n", + " print(\"searches related to input: \")\n", + " for num,it in enumerate(cnf_dis):\n", + " print(num,\")\",it)\n", + " if num!=0:\n", + " print(f\"Select the one you meant (0 - {num}): \", end=\"\")\n", + " conf_inp = int(input(\"\"))\n", + " else:\n", + " conf_inp=0\n", + "\n", + " disease_input=cnf_dis[conf_inp]\n", + " break\n", + " # print(\"Did you mean: \",cnf_dis,\"?(yes/no) :\",end=\"\")\n", + " # conf_inp = input(\"\")\n", + " # if(conf_inp==\"yes\"):\n", + " # break\n", + " else:\n", + " print(\"Enter valid symptom.\")\n", + "\n", + " while True:\n", + " try:\n", + " num_days=int(input(\"Okay. From how many days ? : \"))\n", + " break\n", + " except:\n", + " print(\"Enter valid input.\")\n", + " def recurse(node, depth):\n", + " indent = \" \" * depth\n", + " if tree_.feature[node] != _tree.TREE_UNDEFINED:\n", + " name = feature_name[node]\n", + " threshold = tree_.threshold[node]\n", + "\n", + " if name == disease_input:\n", + " val = 1\n", + " else:\n", + " val = 0\n", + " if val <= threshold:\n", + " recurse(tree_.children_left[node], depth + 1)\n", + " else:\n", + " symptoms_present.append(name)\n", + " recurse(tree_.children_right[node], depth + 1)\n", + " else:\n", + " present_disease = print_disease(tree_.value[node])\n", + " # print( \"You may have \" + present_disease )\n", + " red_cols = reduced_data.columns \n", + " symptoms_given = red_cols[reduced_data.loc[present_disease].values[0].nonzero()]\n", + " # dis_list=list(symptoms_present)\n", + " # if len(dis_list)!=0:\n", + " # print(\"symptoms present \" + str(list(symptoms_present)))\n", + " # print(\"symptoms given \" + str(list(symptoms_given)) )\n", + " print(\"Are you experiencing any \")\n", + " symptoms_exp=[]\n", + " for syms in list(symptoms_given):\n", + " inp=\"\"\n", + " print(syms,\"? : \",end='')\n", + " while True:\n", + " inp=input(\"\")\n", + " if(inp==\"yes\" or inp==\"no\"):\n", + " break\n", + " else:\n", + " print(\"provide proper answers i.e. (yes/no) : \",end=\"\")\n", + " if(inp==\"yes\"):\n", + " symptoms_exp.append(syms)\n", + "\n", + " second_prediction=sec_predict(symptoms_exp)\n", + " # print(second_prediction)\n", + " calc_condition(symptoms_exp,num_days)\n", + " if(present_disease[0]==second_prediction[0]):\n", + " print(\"You may have \", present_disease[0])\n", + " print(description_list[present_disease[0]])\n", + "\n", + " # readn(f\"You may have {present_disease[0]}\")\n", + " # readn(f\"{description_list[present_disease[0]]}\")\n", + "\n", + " else:\n", + " print(\"You may have \", present_disease[0], \"or \", second_prediction[0])\n", + " print(description_list[present_disease[0]])\n", + " print(description_list[second_prediction[0]])\n", + "\n", + " # print(description_list[present_disease[0]])\n", + " precution_list=precautionDictionary[present_disease[0]]\n", + " print(\"Take following measures : \")\n", + " for i,j in enumerate(precution_list):\n", + " print(i+1,\")\",j)\n", + "\n", + " # confidence_level = (1.0*len(symptoms_present))/len(symptoms_given)\n", + " # print(\"confidence level is \" + str(confidence_level))\n", + "\n", + " recurse(0, 1)\n", + "getSeverityDict()\n", + "getDescription()\n", + "getprecautionDict()\n", + "getInfo()\n", + "tree_to_code(clf,cols)\n", + "print(\"----------------------------------------------------------------------------------------\")\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "33356b87", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ef5690a3", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f2d9076c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8da9b836", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "692fc2bd", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6df23640", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "73656cd0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "99b80946", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "22915c77", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "99f4268c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "26bd4243", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b8536727", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "040a5238", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "057b703f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3c5cb9b7", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "17ff2ef0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0413475c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "11108558", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b89387c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f26c8793", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d9ae7758", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f982b6ce", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c5a59435", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6016454c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cfdb314f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f33128a5", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4e929f29", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bb0d24c1", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e3a79bef", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "56490227", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8e5d2abd", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a907f0e5", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9076896e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "50497f6f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "17003184", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "31a63d8f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f4e2e464", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ca3d4e43", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b49ab223", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ed61f368", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "81229a84", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "696b07b9", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47e87abb", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fa51a573", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "565866d0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "40bd7b20", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5f066347", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1db54f9e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eeda3dfd", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "09c9a00e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "04e8d95b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "038a446c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "abda2d7c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e24ae74b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "13923adb", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3d747318", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e72165ec", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b15dec7b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dd89d4aa", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f972bb8e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1af5105f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "88f01100", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0df9375a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9966a474", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "69306d0e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "caba5c9d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1754a8fe", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6c3f56f0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3a3f372e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9ebb9c25", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "055efe1a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "86867f78", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63b607b1", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "77c442bb", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b65e9a90", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "15c8f1a7", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e91f9264", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cdcbb7e3", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "307aa1e7", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b0358205", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6dc329a8", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0ef3301d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "678d62d0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "90b07348", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9b0bd16b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4344bf97", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b70d6471", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d54b1c77", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "52d7450c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "16a710cb", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "56cf61fd", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "69924d0e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "41b9883f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aff0f483", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "65ef9f4a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bc2d99a9", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "38198973", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7d16d1a7", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5e7e055b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "86f1c86a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d8c3fb0c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "49fbca4e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "076037fb", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3f4f884e", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "837ebbd2", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2938bc4c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f9dc8a82", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "693eda76", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2a5ed572", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3074f79b", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c4c557e0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c08557e8", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "86498931", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9d06f490", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2c6ce44c", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "666e89f4", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "781fbbf0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dd4a6186", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "30b8d70d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0da7dc5a", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ca01a51d", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8bc5e502", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d400bfac", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e0713b39", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e22e5aa0", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e510d538", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c5d076cd", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0ac2d344", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "83de60d6", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..df479e9 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,43 @@ + + +
+ + + + +Please try typing full sentences as I am still learning!
+I am a chatbot. You can begin conversation by typing in a message and pressing enter.
+Hi There! What is your name?
+