{"metadata":{"colab":{"provenance":[]},"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"accelerator":"TPU"},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Setting Up","metadata":{"id":"7GL3KbAlWgp9"}},{"cell_type":"code","source":"!nvidia-smi","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"6NofzG8SWn2L","outputId":"3ca78c44-eaae-43fa-911b-de7df0d42c0a","execution":{"iopub.status.busy":"2023-09-20T12:11:46.942678Z","iopub.execute_input":"2023-09-20T12:11:46.943139Z","iopub.status.idle":"2023-09-20T12:11:48.078176Z","shell.execute_reply.started":"2023-09-20T12:11:46.943103Z","shell.execute_reply":"2023-09-20T12:11:48.076831Z"},"trusted":true},"execution_count":1,"outputs":[{"name":"stdout","text":"/bin/bash: nvidia-smi: command not found\n","output_type":"stream"}]},{"cell_type":"code","source":"!pip install pandas numpy scikit-learn matplotlib seaborn torch torchvision torchtext\n","metadata":{"id":"Mlm_Dpc-Wcnx","execution":{"iopub.status.busy":"2023-09-20T12:11:48.082281Z","iopub.execute_input":"2023-09-20T12:11:48.082782Z","iopub.status.idle":"2023-09-20T12:12:25.351335Z","shell.execute_reply.started":"2023-09-20T12:11:48.082731Z","shell.execute_reply":"2023-09-20T12:12:25.349951Z"},"trusted":true},"execution_count":2,"outputs":[{"name":"stdout","text":"Requirement already satisfied: pandas in /opt/conda/lib/python3.10/site-packages (2.0.3)\nRequirement already satisfied: numpy in /opt/conda/lib/python3.10/site-packages (1.23.5)\nRequirement already satisfied: scikit-learn in /opt/conda/lib/python3.10/site-packages (1.2.2)\nRequirement already satisfied: matplotlib in /opt/conda/lib/python3.10/site-packages (3.7.2)\nRequirement already satisfied: seaborn in /opt/conda/lib/python3.10/site-packages (0.12.2)\nRequirement already satisfied: torch in /opt/conda/lib/python3.10/site-packages (2.0.0+cpu)\nRequirement already satisfied: torchvision in /opt/conda/lib/python3.10/site-packages (0.15.1+cpu)\nRequirement already satisfied: torchtext in /opt/conda/lib/python3.10/site-packages (0.15.1+cpu)\nRequirement already satisfied: python-dateutil>=2.8.2 in /opt/conda/lib/python3.10/site-packages (from pandas) (2.8.2)\nRequirement already satisfied: pytz>=2020.1 in /opt/conda/lib/python3.10/site-packages (from pandas) (2023.3)\nRequirement already satisfied: tzdata>=2022.1 in /opt/conda/lib/python3.10/site-packages (from pandas) (2023.3)\nRequirement already satisfied: scipy>=1.3.2 in /opt/conda/lib/python3.10/site-packages (from scikit-learn) (1.11.2)\nRequirement already satisfied: joblib>=1.1.1 in /opt/conda/lib/python3.10/site-packages (from scikit-learn) (1.3.2)\nRequirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/lib/python3.10/site-packages (from scikit-learn) (3.1.0)\nRequirement already satisfied: contourpy>=1.0.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib) (1.1.0)\nRequirement already satisfied: cycler>=0.10 in /opt/conda/lib/python3.10/site-packages (from matplotlib) (0.11.0)\nRequirement already satisfied: fonttools>=4.22.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib) (4.40.0)\nRequirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib) (1.4.4)\nRequirement already satisfied: packaging>=20.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib) (21.3)\nRequirement already satisfied: pillow>=6.2.0 in /opt/conda/lib/python3.10/site-packages (from matplotlib) (9.5.0)\nRequirement already satisfied: pyparsing<3.1,>=2.3.1 in /opt/conda/lib/python3.10/site-packages (from matplotlib) (3.0.9)\nRequirement already satisfied: filelock in /opt/conda/lib/python3.10/site-packages (from torch) (3.12.2)\nRequirement already satisfied: typing-extensions in /opt/conda/lib/python3.10/site-packages (from torch) (4.6.3)\nRequirement already satisfied: sympy in /opt/conda/lib/python3.10/site-packages (from torch) (1.12)\nRequirement already satisfied: networkx in /opt/conda/lib/python3.10/site-packages (from torch) (3.1)\nRequirement already satisfied: jinja2 in /opt/conda/lib/python3.10/site-packages (from torch) (3.1.2)\nRequirement already satisfied: requests in /opt/conda/lib/python3.10/site-packages (from torchvision) (2.31.0)\nRequirement already satisfied: tqdm in /opt/conda/lib/python3.10/site-packages (from torchtext) (4.66.1)\nRequirement already satisfied: torchdata==0.6.0 in /opt/conda/lib/python3.10/site-packages (from torchtext) (0.6.0)\nRequirement already satisfied: urllib3>=1.25 in /opt/conda/lib/python3.10/site-packages (from torchdata==0.6.0->torchtext) (1.26.15)\nRequirement already satisfied: six>=1.5 in /opt/conda/lib/python3.10/site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)\nRequirement already satisfied: MarkupSafe>=2.0 in /opt/conda/lib/python3.10/site-packages (from jinja2->torch) (2.1.3)\nRequirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/lib/python3.10/site-packages (from requests->torchvision) (3.1.0)\nRequirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.10/site-packages (from requests->torchvision) (3.4)\nRequirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.10/site-packages (from requests->torchvision) (2023.7.22)\nRequirement already satisfied: mpmath>=0.19 in /opt/conda/lib/python3.10/site-packages (from sympy->torch) (1.3.0)\n","output_type":"stream"}]},{"cell_type":"code","source":"#!pip install -q gradio torch","metadata":{"id":"bQoNpfUxFRJW","colab":{"base_uri":"https://localhost:8080/"},"outputId":"1f3c0077-5449-4dca-c798-6331a4e02202","execution":{"iopub.status.busy":"2023-09-20T12:12:25.353514Z","iopub.execute_input":"2023-09-20T12:12:25.353917Z","iopub.status.idle":"2023-09-20T12:12:25.359553Z","shell.execute_reply.started":"2023-09-20T12:12:25.353881Z","shell.execute_reply":"2023-09-20T12:12:25.358211Z"},"trusted":true},"execution_count":3,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport torch\nimport torch.nn as nn\nimport torch.optim as optim\nfrom torch.utils.data import Dataset, DataLoader\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.feature_extraction.text import CountVectorizer\nimport joblib","metadata":{"id":"n5SiCs5XUHhh","execution":{"iopub.status.busy":"2023-09-20T12:12:25.363409Z","iopub.execute_input":"2023-09-20T12:12:25.363915Z","iopub.status.idle":"2023-09-20T12:12:30.125654Z","shell.execute_reply.started":"2023-09-20T12:12:25.363870Z","shell.execute_reply":"2023-09-20T12:12:30.124673Z"},"trusted":true},"execution_count":4,"outputs":[]},{"cell_type":"code","source":"device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\ndevice","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"SKHSceiQWroz","outputId":"c18cd767-0a67-4a9b-c658-c7b8c04c8eb8","execution":{"iopub.status.busy":"2023-09-20T12:12:30.127180Z","iopub.execute_input":"2023-09-20T12:12:30.128225Z","iopub.status.idle":"2023-09-20T12:12:30.139861Z","shell.execute_reply.started":"2023-09-20T12:12:30.128174Z","shell.execute_reply":"2023-09-20T12:12:30.138043Z"},"trusted":true},"execution_count":5,"outputs":[{"execution_count":5,"output_type":"execute_result","data":{"text/plain":"device(type='cpu')"},"metadata":{}}]},{"cell_type":"code","source":"import pandas as pd\n\ndf = pd.read_csv(\"/kaggle/input/drug-dataset/drug_dataset_big.csv\")\n\n","metadata":{"execution":{"iopub.status.busy":"2023-09-20T12:12:30.142096Z","iopub.execute_input":"2023-09-20T12:12:30.142615Z","iopub.status.idle":"2023-09-20T12:12:32.023903Z","shell.execute_reply.started":"2023-09-20T12:12:30.142568Z","shell.execute_reply":"2023-09-20T12:12:32.022791Z"},"trusted":true},"execution_count":6,"outputs":[]},{"cell_type":"markdown","source":"#Data","metadata":{"id":"4udEHKqQxMuI"}},{"cell_type":"code","source":"df.head(5)","metadata":{"colab":{"base_uri":"https://localhost:8080/","height":293},"id":"5VSQ4WHmbi1e","outputId":"028cc9e0-f9f6-47d1-c87b-d2ede5fd1dfe","execution":{"iopub.status.busy":"2023-09-20T12:12:32.026056Z","iopub.execute_input":"2023-09-20T12:12:32.026579Z","iopub.status.idle":"2023-09-20T12:12:32.059859Z","shell.execute_reply.started":"2023-09-20T12:12:32.026530Z","shell.execute_reply":"2023-09-20T12:12:32.057992Z"},"trusted":true},"execution_count":7,"outputs":[{"execution_count":7,"output_type":"execute_result","data":{"text/plain":" Drug Name \\\n0 abilify \n1 actemra \n2 afinitor \n3 alprazolam-ir-oral-tablet \n4 amlodipine-oral-tablet \n\n Description \\\n0 abilify\\nabilify\\nWhat is Abilify?\\nIf you hav... \n1 actemra\\nactemra\\nWhat is Actemra?\\nIf you hav... \n2 afinitor\\nafinitor\\nWhat is Afinitor?\\nIf you ... \n3 alprazolam-ir-oral-tablet\\nalprazolam-ir-oral-... \n4 amlodipine-oral-tablet\\namlodipine-oral-tablet... \n\n Uses \\\n0 What is Abilify used for?\\nIf you have a certa... \n1 What is Actemra used for?\\nActemra is used to ... \n2 What is Afinitor used for?\\nAfinitor and Afini... \n3 What is alprazolam IR oral tablet used for?\\nI... \n4 What is amlodipine oral tablet used for?\\nIf y... \n\n Dosage \\\n0 What is Abilify’s dosage?\\nYour doctor will re... \n1 What is Actemra’s dosage?\\nBelow are commonly ... \n2 What is Afinitor’s dosage?\\nYour doctor will r... \n3 What is alprazolam’s dosage?\\nYour doctor will... \n4 What is amlodipine oral tablet’s dosage?\\nYour... \n\n Side Effects \n0 What are Abilify’s side effects?\\nLike most dr... \n1 What are Actemra’s side effects?\\nLike most dr... \n2 What are Afinitor’s side effects?\\nLike most d... \n3 What are alprazolam IR oral tablet’s side effe... \n4 What are amlodipine oral tablet’s side effects... ","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
Drug NameDescriptionUsesDosageSide Effects
0abilifyabilify\\nabilify\\nWhat is Abilify?\\nIf you hav...What is Abilify used for?\\nIf you have a certa...What is Abilify’s dosage?\\nYour doctor will re...What are Abilify’s side effects?\\nLike most dr...
1actemraactemra\\nactemra\\nWhat is Actemra?\\nIf you hav...What is Actemra used for?\\nActemra is used to ...What is Actemra’s dosage?\\nBelow are commonly ...What are Actemra’s side effects?\\nLike most dr...
2afinitorafinitor\\nafinitor\\nWhat is Afinitor?\\nIf you ...What is Afinitor used for?\\nAfinitor and Afini...What is Afinitor’s dosage?\\nYour doctor will r...What are Afinitor’s side effects?\\nLike most d...
3alprazolam-ir-oral-tabletalprazolam-ir-oral-tablet\\nalprazolam-ir-oral-...What is alprazolam IR oral tablet used for?\\nI...What is alprazolam’s dosage?\\nYour doctor will...What are alprazolam IR oral tablet’s side effe...
4amlodipine-oral-tabletamlodipine-oral-tablet\\namlodipine-oral-tablet...What is amlodipine oral tablet used for?\\nIf y...What is amlodipine oral tablet’s dosage?\\nYour...What are amlodipine oral tablet’s side effects...
\n
"},"metadata":{}}]},{"cell_type":"code","source":"df.shape\n","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"nkE4-umdxrqX","outputId":"31840069-a778-49e6-8c72-48fe4f9ef436","execution":{"iopub.status.busy":"2023-09-20T12:12:32.064151Z","iopub.execute_input":"2023-09-20T12:12:32.064550Z","iopub.status.idle":"2023-09-20T12:12:32.071825Z","shell.execute_reply.started":"2023-09-20T12:12:32.064520Z","shell.execute_reply":"2023-09-20T12:12:32.070801Z"},"trusted":true},"execution_count":8,"outputs":[{"execution_count":8,"output_type":"execute_result","data":{"text/plain":"(45898, 5)"},"metadata":{}}]},{"cell_type":"code","source":"# Iterate through columns and perform text cleaning\nfor column in df.columns:\n if df[column].dtype == 'object': # Check if the column contains text\n df[column] = df[column].str.lower()","metadata":{"id":"3orY01ek-Ikt","execution":{"iopub.status.busy":"2023-09-20T12:12:32.072836Z","iopub.execute_input":"2023-09-20T12:12:32.073229Z","iopub.status.idle":"2023-09-20T12:12:32.761036Z","shell.execute_reply.started":"2023-09-20T12:12:32.073196Z","shell.execute_reply":"2023-09-20T12:12:32.759803Z"},"trusted":true},"execution_count":9,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"VUHrI3G0yDlH","outputId":"a8bb6b7c-f954-4610-ad03-7f86324116c0","execution":{"iopub.status.busy":"2023-09-20T12:12:32.765447Z","iopub.execute_input":"2023-09-20T12:12:32.765812Z","iopub.status.idle":"2023-09-20T12:12:32.776849Z","shell.execute_reply.started":"2023-09-20T12:12:32.765783Z","shell.execute_reply":"2023-09-20T12:12:32.774719Z"},"trusted":true},"execution_count":10,"outputs":[{"execution_count":10,"output_type":"execute_result","data":{"text/plain":"(45898, 5)"},"metadata":{}}]},{"cell_type":"code","source":"# Drop rows with missing values\ndf = df.dropna().reset_index(drop=True)","metadata":{"id":"ZiqshNQWyryI","execution":{"iopub.status.busy":"2023-09-20T12:12:32.778513Z","iopub.execute_input":"2023-09-20T12:12:32.779140Z","iopub.status.idle":"2023-09-20T12:12:32.873198Z","shell.execute_reply.started":"2023-09-20T12:12:32.779094Z","shell.execute_reply":"2023-09-20T12:12:32.871780Z"},"trusted":true},"execution_count":11,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"6m7YZJiYyyge","outputId":"ee8f2ef0-83f6-4115-ace1-9ca419d91384","execution":{"iopub.status.busy":"2023-09-20T12:12:32.874855Z","iopub.execute_input":"2023-09-20T12:12:32.875714Z","iopub.status.idle":"2023-09-20T12:12:32.883142Z","shell.execute_reply.started":"2023-09-20T12:12:32.875676Z","shell.execute_reply":"2023-09-20T12:12:32.881897Z"},"trusted":true},"execution_count":12,"outputs":[{"execution_count":12,"output_type":"execute_result","data":{"text/plain":"(45898, 5)"},"metadata":{}}]},{"cell_type":"code","source":"df.head()","metadata":{"colab":{"base_uri":"https://localhost:8080/","height":293},"id":"ESzF37DBy1pn","outputId":"5e3f9430-d146-4659-a09d-83554f23a32d","execution":{"iopub.status.busy":"2023-09-20T12:12:32.884756Z","iopub.execute_input":"2023-09-20T12:12:32.885846Z","iopub.status.idle":"2023-09-20T12:12:32.920011Z","shell.execute_reply.started":"2023-09-20T12:12:32.885804Z","shell.execute_reply":"2023-09-20T12:12:32.918421Z"},"trusted":true},"execution_count":13,"outputs":[{"execution_count":13,"output_type":"execute_result","data":{"text/plain":" Drug Name \\\n0 abilify \n1 actemra \n2 afinitor \n3 alprazolam-ir-oral-tablet \n4 amlodipine-oral-tablet \n\n Description \\\n0 abilify\\nabilify\\nwhat is abilify?\\nif you hav... \n1 actemra\\nactemra\\nwhat is actemra?\\nif you hav... \n2 afinitor\\nafinitor\\nwhat is afinitor?\\nif you ... \n3 alprazolam-ir-oral-tablet\\nalprazolam-ir-oral-... \n4 amlodipine-oral-tablet\\namlodipine-oral-tablet... \n\n Uses \\\n0 what is abilify used for?\\nif you have a certa... \n1 what is actemra used for?\\nactemra is used to ... \n2 what is afinitor used for?\\nafinitor and afini... \n3 what is alprazolam ir oral tablet used for?\\ni... \n4 what is amlodipine oral tablet used for?\\nif y... \n\n Dosage \\\n0 what is abilify’s dosage?\\nyour doctor will re... \n1 what is actemra’s dosage?\\nbelow are commonly ... \n2 what is afinitor’s dosage?\\nyour doctor will r... \n3 what is alprazolam’s dosage?\\nyour doctor will... \n4 what is amlodipine oral tablet’s dosage?\\nyour... \n\n Side Effects \n0 what are abilify’s side effects?\\nlike most dr... \n1 what are actemra’s side effects?\\nlike most dr... \n2 what are afinitor’s side effects?\\nlike most d... \n3 what are alprazolam ir oral tablet’s side effe... \n4 what are amlodipine oral tablet’s side effects... ","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
Drug NameDescriptionUsesDosageSide Effects
0abilifyabilify\\nabilify\\nwhat is abilify?\\nif you hav...what is abilify used for?\\nif you have a certa...what is abilify’s dosage?\\nyour doctor will re...what are abilify’s side effects?\\nlike most dr...
1actemraactemra\\nactemra\\nwhat is actemra?\\nif you hav...what is actemra used for?\\nactemra is used to ...what is actemra’s dosage?\\nbelow are commonly ...what are actemra’s side effects?\\nlike most dr...
2afinitorafinitor\\nafinitor\\nwhat is afinitor?\\nif you ...what is afinitor used for?\\nafinitor and afini...what is afinitor’s dosage?\\nyour doctor will r...what are afinitor’s side effects?\\nlike most d...
3alprazolam-ir-oral-tabletalprazolam-ir-oral-tablet\\nalprazolam-ir-oral-...what is alprazolam ir oral tablet used for?\\ni...what is alprazolam’s dosage?\\nyour doctor will...what are alprazolam ir oral tablet’s side effe...
4amlodipine-oral-tabletamlodipine-oral-tablet\\namlodipine-oral-tablet...what is amlodipine oral tablet used for?\\nif y...what is amlodipine oral tablet’s dosage?\\nyour...what are amlodipine oral tablet’s side effects...
\n
"},"metadata":{}}]},{"cell_type":"code","source":"# Features & Labels\n#X_features = df['Description']\n#y_labels = df[['Drug Name', 'Uses', 'Dosage', 'Side Effects']]\nX_features = df['Drug Name']\ny_labels = df[['Uses', 'Dosage', 'Side Effects']]\n\n","metadata":{"id":"S_jd7lIkWxbH","execution":{"iopub.status.busy":"2023-09-20T12:12:32.923640Z","iopub.execute_input":"2023-09-20T12:12:32.924179Z","iopub.status.idle":"2023-09-20T12:12:32.943013Z","shell.execute_reply.started":"2023-09-20T12:12:32.924132Z","shell.execute_reply":"2023-09-20T12:12:32.941750Z"},"trusted":true},"execution_count":14,"outputs":[]},{"cell_type":"code","source":"from joblib import dump\nfrom sklearn.preprocessing import LabelEncoder","metadata":{"id":"_solpMI2rZJv","execution":{"iopub.status.busy":"2023-09-20T12:12:32.944367Z","iopub.execute_input":"2023-09-20T12:12:32.944820Z","iopub.status.idle":"2023-09-20T12:12:32.952212Z","shell.execute_reply.started":"2023-09-20T12:12:32.944778Z","shell.execute_reply":"2023-09-20T12:12:32.951010Z"},"trusted":true},"execution_count":15,"outputs":[]},{"cell_type":"code","source":"df['Drug Name'].value_counts()","metadata":{"id":"IPUcSO4OP60q","execution":{"iopub.status.busy":"2023-09-20T12:12:32.954149Z","iopub.execute_input":"2023-09-20T12:12:32.954659Z","iopub.status.idle":"2023-09-20T12:12:33.000755Z","shell.execute_reply.started":"2023-09-20T12:12:32.954618Z","shell.execute_reply":"2023-09-20T12:12:32.999555Z"},"trusted":true},"execution_count":16,"outputs":[{"execution_count":16,"output_type":"execute_result","data":{"text/plain":"Drug Name\nabilify 30\nozempic 30\nsoliqua 30\nsinemet 30\nrybrevant 30\n ..\netidronate 4\netodolac 4\netonogestrel 4\netonogestrel implant 4\nzyvox (linezolid oral) 4\nName: count, Length: 10892, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"#df['Description'].value_counts()","metadata":{"id":"w6H9XcHf0LY0","execution":{"iopub.status.busy":"2023-09-20T12:12:33.001808Z","iopub.execute_input":"2023-09-20T12:12:33.002158Z","iopub.status.idle":"2023-09-20T12:12:33.012592Z","shell.execute_reply.started":"2023-09-20T12:12:33.002130Z","shell.execute_reply":"2023-09-20T12:12:33.011141Z"},"trusted":true},"execution_count":17,"outputs":[]},{"cell_type":"code","source":"df['Uses'].value_counts()","metadata":{"id":"HRaIGC6CDiVd","execution":{"iopub.status.busy":"2023-09-20T12:12:33.014462Z","iopub.execute_input":"2023-09-20T12:12:33.015161Z","iopub.status.idle":"2023-09-20T12:12:33.061136Z","shell.execute_reply.started":"2023-09-20T12:12:33.015126Z","shell.execute_reply":"2023-09-20T12:12:33.059980Z"},"trusted":true},"execution_count":18,"outputs":[{"execution_count":18,"output_type":"execute_result","data":{"text/plain":"Uses\nacetaminophen is a pain reliever and fever reducer. 340\nsalicylic acid is a keratolytic (peeling agent) that causes shedding of the outer layer of skin. 252\ndextromethorphan is a cough suppressant. guaifenesin is an expectorant. 212\nacetaminophen is a pain reliever and a fever reducer. 196\ndextromethorphan is a cough suppressant that affects signals in the brain that trigger cough reflex. guaifenesin is an expectorant that loosens congestion in your chest and throat. phenylephrine is a decongestant that shrinks blood vessels in the nasal passages. 160\n ... \nferric pyrophosphate citrate is used as an iron replacement to prevent anemia in patients with chronic kidney disease who are on dialysis. 4\nferric pyrophosphate is an iron replacement product. you normally get iron from the foods you eat. iron helps your body produce red blood cells that carry oxygen through your blood to tissues and organs. 4\nferric maltol is an iron replacement product that is used in adults used to treat iron deficiency. 4\nferric derisomaltose is used to treat iron deficiency anemia in adults with chronic kidney disease who are not on dialysis. 4\nzyvox is an oxazolidinone antibiotic that fights bacteria in the body. linezolid is also an mao (monoamine oxidase) inhibitor. 4\nName: count, Length: 7584, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"df['Dosage'].value_counts()","metadata":{"id":"3O8hty8tB8nL","execution":{"iopub.status.busy":"2023-09-20T12:12:33.062719Z","iopub.execute_input":"2023-09-20T12:12:33.063201Z","iopub.status.idle":"2023-09-20T12:12:33.107202Z","shell.execute_reply.started":"2023-09-20T12:12:33.063169Z","shell.execute_reply":"2023-09-20T12:12:33.106293Z"},"trusted":true},"execution_count":19,"outputs":[{"execution_count":19,"output_type":"execute_result","data":{"text/plain":"Dosage\nfollow all directions on your prescription label and read all medication guides or instruction sheets. use the medicine exactly as directed. 3360\nfollow all directions on your prescription label and read all medication guides or instruction sheets. your doctor may occasionally change your dose. use the medicine exactly as directed. 1484\nuse exactly as directed on the label, or as prescribed by your doctor. 1440\nuse exactly as directed on the label, or as prescribed by your doctor. do not use in larger or smaller amounts or for longer than recommended. 1200\nuse exactly as directed on the label, or as prescribed by your doctor. cold or cough medicine is only for short-term use until your symptoms clear up. 740\n ... \nsome brands of this vaccine are made for use in adults and not in children. your child's vaccination provider can recommend the best flublok quadrivalent 2023-2024 for your child. 4\nsome brands of this vaccine are made for use in adults and not in children. your child's vaccination provider can recommend the best flucelvax pf quadrivalent 2021-2022 for your child. 4\nsome brands of this vaccine are made for use in adults and not in children. your child's vaccination provider can recommend the best flucelvax pf quadrivalent 2022-2023 for your child. 4\nsome brands of this vaccine are made for use in adults and not in children. your child's vaccination provider can recommend the best flucelvax pf quadrivalent 2023-2024 for your child. 4\nuse zyvox exactly as prescribed by your doctor. follow all directions on your prescription label and read all medication guides or instruction sheets. 4\nName: count, Length: 3922, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"df['Side Effects'].value_counts()","metadata":{"id":"tI5Wg9WyL39C","execution":{"iopub.status.busy":"2023-09-20T12:12:33.108344Z","iopub.execute_input":"2023-09-20T12:12:33.109410Z","iopub.status.idle":"2023-09-20T12:12:33.152294Z","shell.execute_reply.started":"2023-09-20T12:12:33.109373Z","shell.execute_reply":"2023-09-20T12:12:33.150948Z"},"trusted":true},"execution_count":20,"outputs":[{"execution_count":20,"output_type":"execute_result","data":{"text/plain":"Side Effects\nalong with its needed effects, a medicine may cause some unwanted effects. although not all of these side effects may occur, if they do occur they may need medical attention. 13836\nget emergency medical help if you have signs of an allergic reaction: hives; difficult breathing; swelling of your face, lips, tongue, or throat. 11424\nget emergency medical help if you have signs of an allergic reaction: hives; difficulty breathing; swelling of your face, lips, tongue, or throat. 2660\nget emergency medical help if you have any of these signs of an allergic reaction: hives; difficult breathing; swelling of your face, lips, tongue, or throat. 1596\nget emergency medical help if you have signs of an allergic reaction (hives, difficult breathing, swelling in your face or throat) or a severe skin reaction (fever, sore throat, burning eyes, skin pain, red or purple skin rash with blistering and peeling). 1044\n ... \nget emergency medical help if you have any of these signs of an allergic reaction to femtrace: hives; difficulty breathing; swelling of your face, lips, tongue, or throat. stop using femtrace and call your doctor at once if you have a serious side effect such as: 4\nget emergency medical help if you have signs of an allergic reaction to femhrt: hives; difficult breathing; swelling of your face, lips, tongue, or throat. 4\nget emergency medical help if you have signs of an allergic reaction to femara: hives; difficult breathing; swelling of your face, lips, tongue, or throat. 4\nget emergency medical help if you have signs of an allergic reaction to fazaclo (hives, difficult breathing, swelling in your face or throat) or a severe skin reaction (fever, sore throat, burning eyes, skin pain, red or purple skin rash with blistering and peeling). 4\nget emergency medical help if you have signs of an allergic reaction to zyvox (hives, difficult breathing, swelling in your face or throat) or a severe skin reaction (fever, sore throat, burning eyes, skin pain, red or purple skin rash with blistering and peeling). 4\nName: count, Length: 2461, dtype: int64"},"metadata":{}}]},{"cell_type":"code","source":"# Load Pkgs\nfrom sklearn.multioutput import MultiOutputClassifier","metadata":{"id":"JTjTEtkfMMmU","execution":{"iopub.status.busy":"2023-09-20T12:12:33.153901Z","iopub.execute_input":"2023-09-20T12:12:33.154286Z","iopub.status.idle":"2023-09-20T12:12:33.169183Z","shell.execute_reply.started":"2023-09-20T12:12:33.154254Z","shell.execute_reply":"2023-09-20T12:12:33.168092Z"},"trusted":true},"execution_count":21,"outputs":[]},{"cell_type":"code","source":"# Features & Labels\nXfeatures = df['Drug Name']\nylabels = df[['Uses', 'Dosage', 'Side Effects']]","metadata":{"id":"62xnnLdMMQOG","execution":{"iopub.status.busy":"2023-09-20T12:12:33.170593Z","iopub.execute_input":"2023-09-20T12:12:33.171188Z","iopub.status.idle":"2023-09-20T12:12:33.187154Z","shell.execute_reply.started":"2023-09-20T12:12:33.171154Z","shell.execute_reply":"2023-09-20T12:12:33.186145Z"},"trusted":true},"execution_count":22,"outputs":[]},{"cell_type":"code","source":"# Split Data\nx_train,x_test,y_train,y_test = train_test_split(Xfeatures,ylabels,test_size=0.3,random_state=7)\n\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.feature_extraction.text import CountVectorizer\nfrom sklearn.multioutput import MultiOutputClassifier\nfrom sklearn.linear_model import LogisticRegression\n\n\npipe_lr = Pipeline(steps=[\n ('cv', CountVectorizer()),\n ('lr_multi', MultiOutputClassifier(LogisticRegression(max_iter=70))) \n])\n# Fit on Dataset\npipe_lr.fit(x_train,y_train)\n\n# Accuracy Score\npipe_lr.score(x_test,y_test)\n\n# Sample Prediction\nprint(x_test.iloc[0])\nprint(\"Actual Prediction:\",y_test.iloc[0])\n\nex1 = x_test.iloc[0]\n\npipe_lr.predict([ex1])\n\n# Prediction Prob\nprint(pipe_lr.classes_)\npipe_lr.predict_proba([ex1])\n\n# Save the trained model\nmodel = 'drug_finder_3i.joblib'\ndump(pipe_lr, model)\nprint(\"Model saved as\", model)\n\n\n\n","metadata":{"execution":{"iopub.status.busy":"2023-09-20T12:12:33.188638Z","iopub.execute_input":"2023-09-20T12:12:33.189507Z","iopub.status.idle":"2023-09-20T12:58:19.117391Z","shell.execute_reply.started":"2023-09-20T12:12:33.189473Z","shell.execute_reply":"2023-09-20T12:58:19.115522Z"},"trusted":true},"execution_count":23,"outputs":[{"name":"stderr","text":"/opt/conda/lib/python3.10/site-packages/sklearn/linear_model/_logistic.py:458: ConvergenceWarning: lbfgs failed to converge (status=1):\nSTOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n\nIncrease the number of iterations (max_iter) or scale the data as shown in:\n https://scikit-learn.org/stable/modules/preprocessing.html\nPlease also refer to the documentation for alternative solver options:\n https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n n_iter_i = _check_optimize_result(\n/opt/conda/lib/python3.10/site-packages/sklearn/linear_model/_logistic.py:458: ConvergenceWarning: lbfgs failed to converge (status=1):\nSTOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n\nIncrease the number of iterations (max_iter) or scale the data as shown in:\n https://scikit-learn.org/stable/modules/preprocessing.html\nPlease also refer to the documentation for alternative solver options:\n https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n n_iter_i = _check_optimize_result(\n","output_type":"stream"},{"name":"stdout","text":"simply saline nasal\nActual Prediction: Uses there are many brands and forms of sodium chlo...\nDosage use exactly as directed on the label, or as pr...\nSide Effects get emergency medical help if you have signs o...\nName: 38463, dtype: object\n[array(['13c urea and citric acid are medicines used in a diagnostic test called exalenz breathid® non-invasive breath test. it is a test that analyzes a breath sample before and after taking 13c-enriched urea to help diagnose patients with infections in the stomach caused by a bacteria called h. pylori.',\n 'a-methapred is a steroid that prevents the release of substances in the body that cause inflammation.',\n 'a-phedrin is a combination antihistamine and decongestant medicine that is used to treat runny or stuffy nose, sneezing, itching, watery eyes, and sinus congestion caused by allergies or the common cold.',\n ...,\n 'zyrtec is used in adults and children to treat cold or allergy symptoms such as sneezing, itching, watery eyes, or runny nose.',\n 'zytiga works by reducing androgen production in the body. androgens are male hormones that can promote tumor growth in the prostate gland.',\n 'zyvox is an oxazolidinone antibiotic that fights bacteria in the body. linezolid is also an mao (monoamine oxidase) inhibitor.'],\n dtype=object), array(['*conversion from the invega sustenna 39 mg dose was not studied.',\n '*for pediatric patients weighing less than 10 kg, administer 0.1 mg/kg (0.01 ml/kg) of pegfilgrastim',\n '- administer zimhi (naloxone hydrochloride) 5 mg/0.5 ml to adult or pediatric patients into the anterolateral aspect of the thigh, through clothing if necessary.',\n ...,\n 'zurzuvae is taken once a day in the evening, with fatty food, for 14 days (two weeks).',\n 'zynrelef is administered by a healthcare professional. you will receive zynrelef in a medical setting.',\n 'zyprexa relprevv is injected into a muscle. you will receive this injection in a clinic or hospital setting.'],\n dtype=object), array(['a medicine may cause some unwanted effects. if you notice any side effects, check with your doctor.',\n 'a serious side effect of xofigo is bone marrow suppression. it is important to have your regular blood tests. you should report signs of bleeding or infections to your health care provider.',\n 'abrysvo is generally well tolerated, and the most common side effects included fatigue, headache, injection site pain, and muscle pain. these were generally only short-lived.',\n ..., 'zuranolone may cause serious side effects, including:',\n 'zynlonta may cause serious side effects, including:',\n 'zynyz can cause serious side effects. see important information.'],\n dtype=object)]\nModel saved as drug_finder_3i.joblib\n","output_type":"stream"}]},{"cell_type":"markdown","source":"#Define pipeline","metadata":{"id":"S142rSwzNDUT"}},{"cell_type":"code","source":"# Sample Prediction\nprint(x_test.iloc[0])\nprint(\"Actual Prediction:\",y_test.iloc[0])","metadata":{"id":"z-hU3wFkOX-e","execution":{"iopub.status.busy":"2023-09-20T12:58:19.119992Z","iopub.execute_input":"2023-09-20T12:58:19.120378Z","iopub.status.idle":"2023-09-20T12:58:19.128583Z","shell.execute_reply.started":"2023-09-20T12:58:19.120347Z","shell.execute_reply":"2023-09-20T12:58:19.127247Z"},"trusted":true},"execution_count":24,"outputs":[{"name":"stdout","text":"simply saline nasal\nActual Prediction: Uses there are many brands and forms of sodium chlo...\nDosage use exactly as directed on the label, or as pr...\nSide Effects get emergency medical help if you have signs o...\nName: 38463, dtype: object\n","output_type":"stream"}]},{"cell_type":"code","source":"ex1 = x_test.iloc[0]","metadata":{"id":"pEBsEuVNOxZr","execution":{"iopub.status.busy":"2023-09-20T12:58:19.130246Z","iopub.execute_input":"2023-09-20T12:58:19.130695Z","iopub.status.idle":"2023-09-20T12:58:19.146750Z","shell.execute_reply.started":"2023-09-20T12:58:19.130642Z","shell.execute_reply":"2023-09-20T12:58:19.145516Z"},"trusted":true},"execution_count":25,"outputs":[]},{"cell_type":"code","source":"ex1","metadata":{"colab":{"base_uri":"https://localhost:8080/","height":122},"id":"TPPmqnlHO0Fj","outputId":"f234c576-7709-4bae-a04f-9d8b85631605","execution":{"iopub.status.busy":"2023-09-20T12:58:19.149186Z","iopub.execute_input":"2023-09-20T12:58:19.149736Z","iopub.status.idle":"2023-09-20T12:58:19.167822Z","shell.execute_reply.started":"2023-09-20T12:58:19.149691Z","shell.execute_reply":"2023-09-20T12:58:19.166381Z"},"trusted":true},"execution_count":26,"outputs":[{"execution_count":26,"output_type":"execute_result","data":{"text/plain":"'simply saline nasal'"},"metadata":{}}]},{"cell_type":"code","source":"pipe_lr.predict([ex1])","metadata":{"id":"Dx7HzbzEPBBb","execution":{"iopub.status.busy":"2023-09-20T12:58:19.169709Z","iopub.execute_input":"2023-09-20T12:58:19.170195Z","iopub.status.idle":"2023-09-20T12:58:19.667690Z","shell.execute_reply.started":"2023-09-20T12:58:19.170151Z","shell.execute_reply":"2023-09-20T12:58:19.665775Z"},"trusted":true},"execution_count":27,"outputs":[{"execution_count":27,"output_type":"execute_result","data":{"text/plain":"array([['there are many brands and forms of sodium chloride nasal available. not all brands are listed on this leaflet.',\n 'use exactly as directed on the label, or as prescribed by your doctor.',\n 'get emergency medical help if you have signs of an allergic reaction: hives; difficult breathing; swelling of your face, lips, tongue, or throat.']],\n dtype=object)"},"metadata":{}}]},{"cell_type":"code","source":"# Prediction Prob\nprint(pipe_lr.classes_)\npipe_lr.predict_proba([ex1])","metadata":{"id":"2l5M0HY1PTE1","execution":{"iopub.status.busy":"2023-09-20T12:58:19.676123Z","iopub.execute_input":"2023-09-20T12:58:19.676734Z","iopub.status.idle":"2023-09-20T12:58:20.159685Z","shell.execute_reply.started":"2023-09-20T12:58:19.676690Z","shell.execute_reply":"2023-09-20T12:58:20.158399Z"},"trusted":true},"execution_count":28,"outputs":[{"name":"stdout","text":"[array(['13c urea and citric acid are medicines used in a diagnostic test called exalenz breathid® non-invasive breath test. it is a test that analyzes a breath sample before and after taking 13c-enriched urea to help diagnose patients with infections in the stomach caused by a bacteria called h. pylori.',\n 'a-methapred is a steroid that prevents the release of substances in the body that cause inflammation.',\n 'a-phedrin is a combination antihistamine and decongestant medicine that is used to treat runny or stuffy nose, sneezing, itching, watery eyes, and sinus congestion caused by allergies or the common cold.',\n ...,\n 'zyrtec is used in adults and children to treat cold or allergy symptoms such as sneezing, itching, watery eyes, or runny nose.',\n 'zytiga works by reducing androgen production in the body. androgens are male hormones that can promote tumor growth in the prostate gland.',\n 'zyvox is an oxazolidinone antibiotic that fights bacteria in the body. linezolid is also an mao (monoamine oxidase) inhibitor.'],\n dtype=object), array(['*conversion from the invega sustenna 39 mg dose was not studied.',\n '*for pediatric patients weighing less than 10 kg, administer 0.1 mg/kg (0.01 ml/kg) of pegfilgrastim',\n '- administer zimhi (naloxone hydrochloride) 5 mg/0.5 ml to adult or pediatric patients into the anterolateral aspect of the thigh, through clothing if necessary.',\n ...,\n 'zurzuvae is taken once a day in the evening, with fatty food, for 14 days (two weeks).',\n 'zynrelef is administered by a healthcare professional. you will receive zynrelef in a medical setting.',\n 'zyprexa relprevv is injected into a muscle. you will receive this injection in a clinic or hospital setting.'],\n dtype=object), array(['a medicine may cause some unwanted effects. if you notice any side effects, check with your doctor.',\n 'a serious side effect of xofigo is bone marrow suppression. it is important to have your regular blood tests. you should report signs of bleeding or infections to your health care provider.',\n 'abrysvo is generally well tolerated, and the most common side effects included fatigue, headache, injection site pain, and muscle pain. these were generally only short-lived.',\n ..., 'zuranolone may cause serious side effects, including:',\n 'zynlonta may cause serious side effects, including:',\n 'zynyz can cause serious side effects. see important information.'],\n dtype=object)]\n","output_type":"stream"},{"execution_count":28,"output_type":"execute_result","data":{"text/plain":"[array([[3.37608338e-05, 2.76920376e-05, 2.95217789e-05, ...,\n 1.97527317e-05, 2.95217789e-05, 1.97613515e-05]]),\n array([[4.43886061e-05, 1.30972124e-05, 2.77455328e-05, ...,\n 2.77514741e-05, 4.06287587e-05, 4.45356842e-05]]),\n array([[3.65662714e-06, 1.14434904e-05, 7.20965499e-06, ...,\n 1.49463876e-05, 7.20965499e-06, 7.20965499e-06]])]"},"metadata":{}}]},{"cell_type":"code","source":"# Save the trained model\n#model = 'drug_finder_big.joblib'\n#dump(pipe_lr, model)\n#print(\"Model saved as\", model)","metadata":{"id":"5L0sTli9Pc-t","execution":{"iopub.status.busy":"2023-09-20T12:58:20.161183Z","iopub.execute_input":"2023-09-20T12:58:20.161712Z","iopub.status.idle":"2023-09-20T12:58:20.168622Z","shell.execute_reply.started":"2023-09-20T12:58:20.161600Z","shell.execute_reply":"2023-09-20T12:58:20.167134Z"},"trusted":true},"execution_count":29,"outputs":[]},{"cell_type":"code","source":"from joblib import load\n\n# Load the saved model\nloaded_model = load(model)\n","metadata":{"id":"N3V-4v6bEB6R","execution":{"iopub.status.busy":"2023-09-20T12:58:20.170577Z","iopub.execute_input":"2023-09-20T12:58:20.170915Z","iopub.status.idle":"2023-09-20T12:58:20.689571Z","shell.execute_reply.started":"2023-09-20T12:58:20.170887Z","shell.execute_reply":"2023-09-20T12:58:20.688354Z"},"trusted":true},"execution_count":30,"outputs":[]},{"cell_type":"code","source":"loaded_model.predict([ex1])","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"DHI-o8PGENpK","outputId":"1b66079f-75d2-444d-97a8-4d666983b836","execution":{"iopub.status.busy":"2023-09-20T12:58:20.691229Z","iopub.execute_input":"2023-09-20T12:58:20.691583Z","iopub.status.idle":"2023-09-20T12:58:21.720511Z","shell.execute_reply.started":"2023-09-20T12:58:20.691554Z","shell.execute_reply":"2023-09-20T12:58:21.717232Z"},"trusted":true},"execution_count":31,"outputs":[{"execution_count":31,"output_type":"execute_result","data":{"text/plain":"array([['there are many brands and forms of sodium chloride nasal available. not all brands are listed on this leaflet.',\n 'use exactly as directed on the label, or as prescribed by your doctor.',\n 'get emergency medical help if you have signs of an allergic reaction: hives; difficult breathing; swelling of your face, lips, tongue, or throat.']],\n dtype=object)"},"metadata":{}}]},{"cell_type":"code","source":"# Sample prediction\nsample_input = [ex1]\n\n# Predict probabilities for each class in each output\nprediction_probs = loaded_model.predict_proba(sample_input)\n\n# Print the predicted probabilities\nprint(\"Prediction Probabilities:\")\nprint(prediction_probs)","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"qpM72FpeENuc","outputId":"b2da0b12-33e8-4077-d5c7-8340588dfb6c","execution":{"iopub.status.busy":"2023-09-20T12:58:21.726636Z","iopub.execute_input":"2023-09-20T12:58:21.728036Z","iopub.status.idle":"2023-09-20T12:58:23.168237Z","shell.execute_reply.started":"2023-09-20T12:58:21.727973Z","shell.execute_reply":"2023-09-20T12:58:23.166641Z"},"trusted":true},"execution_count":32,"outputs":[{"name":"stdout","text":"Prediction Probabilities:\n[array([[3.37608338e-05, 2.76920376e-05, 2.95217789e-05, ...,\n 1.97527317e-05, 2.95217789e-05, 1.97613515e-05]]), array([[4.43886061e-05, 1.30972124e-05, 2.77455328e-05, ...,\n 2.77514741e-05, 4.06287587e-05, 4.45356842e-05]]), array([[3.65662714e-06, 1.14434904e-05, 7.20965499e-06, ...,\n 1.49463876e-05, 7.20965499e-06, 7.20965499e-06]])]\n","output_type":"stream"}]},{"cell_type":"markdown","source":"###Using ML Estimators KNN which supports multi-output","metadata":{"id":"n1nOyYyBP0R0"}},{"cell_type":"code","source":"from sklearn.pipeline import Pipeline\nfrom sklearn.feature_extraction.text import CountVectorizer\nfrom sklearn.neighbors import KNeighborsClassifier\n\n# Define your pipeline\npipe_knn = Pipeline(steps=[\n ('cv', CountVectorizer()),\n ('knn', KNeighborsClassifier(n_neighbors=4))\n])\n","metadata":{"id":"kUMos3V4QKwV","execution":{"iopub.status.busy":"2023-09-20T12:58:23.171503Z","iopub.execute_input":"2023-09-20T12:58:23.173547Z","iopub.status.idle":"2023-09-20T12:58:23.450572Z","shell.execute_reply.started":"2023-09-20T12:58:23.173500Z","shell.execute_reply":"2023-09-20T12:58:23.447940Z"},"trusted":true},"execution_count":33,"outputs":[]},{"cell_type":"code","source":"pipe_knn.fit(x_train,y_train)","metadata":{"colab":{"base_uri":"https://localhost:8080/","height":126},"id":"nQiiX1wiQOXk","outputId":"8a7270cf-4a63-4277-dcc7-f3cdac6da699","execution":{"iopub.status.busy":"2023-09-20T12:58:23.454743Z","iopub.execute_input":"2023-09-20T12:58:23.455473Z","iopub.status.idle":"2023-09-20T12:58:25.655793Z","shell.execute_reply.started":"2023-09-20T12:58:23.455432Z","shell.execute_reply":"2023-09-20T12:58:25.654258Z"},"trusted":true},"execution_count":34,"outputs":[{"execution_count":34,"output_type":"execute_result","data":{"text/plain":"Pipeline(steps=[('cv', CountVectorizer()),\n ('knn', KNeighborsClassifier(n_neighbors=4))])","text/html":"
Pipeline(steps=[('cv', CountVectorizer()),\n                ('knn', KNeighborsClassifier(n_neighbors=4))])
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.
"},"metadata":{}}]},{"cell_type":"code","source":"# Save the trained model\nmodel = 'drug_finder_3i_knn.joblib'\ndump(pipe_knn, model)\nprint(\"Model saved as\", model)\n","metadata":{"id":"AD82l7fAWK05","execution":{"iopub.status.busy":"2023-09-20T12:58:25.658067Z","iopub.execute_input":"2023-09-20T12:58:25.658846Z","iopub.status.idle":"2023-09-20T12:58:25.937738Z","shell.execute_reply.started":"2023-09-20T12:58:25.658808Z","shell.execute_reply":"2023-09-20T12:58:25.936103Z"},"trusted":true},"execution_count":35,"outputs":[{"name":"stdout","text":"Model saved as drug_finder_3i_knn.joblib\n","output_type":"stream"}]},{"cell_type":"code","source":"from joblib import load\n\n# Load the saved model\nloaded_model = load(model)\n","metadata":{"id":"pmWuCbkeW4Yk","execution":{"iopub.status.busy":"2023-09-20T12:58:25.940338Z","iopub.execute_input":"2023-09-20T12:58:25.941500Z","iopub.status.idle":"2023-09-20T12:58:26.078377Z","shell.execute_reply.started":"2023-09-20T12:58:25.941434Z","shell.execute_reply":"2023-09-20T12:58:26.076150Z"},"trusted":true},"execution_count":36,"outputs":[]},{"cell_type":"code","source":"loaded_model.predict([ex1])","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"hEIHGrZpXL-8","outputId":"6b266b57-8a5a-49b0-f465-063958892ca2","execution":{"iopub.status.busy":"2023-09-20T12:58:26.080681Z","iopub.execute_input":"2023-09-20T12:58:26.081796Z","iopub.status.idle":"2023-09-20T12:58:26.114666Z","shell.execute_reply.started":"2023-09-20T12:58:26.081712Z","shell.execute_reply":"2023-09-20T12:58:26.111990Z"},"trusted":true},"execution_count":37,"outputs":[{"execution_count":37,"output_type":"execute_result","data":{"text/plain":"array([['there are many brands and forms of sodium chloride nasal available. not all brands are listed on this leaflet.',\n 'use exactly as directed on the label, or as prescribed by your doctor.',\n 'get emergency medical help if you have signs of an allergic reaction: hives; difficult breathing; swelling of your face, lips, tongue, or throat.']],\n dtype=object)"},"metadata":{}}]},{"cell_type":"code","source":"# Sample prediction\nsample_input = [ex1]\n\n# Predict probabilities for each class in each output\nprediction_probs = loaded_model.predict_proba(sample_input)\n\n# Print the predicted probabilities\nprint(\"Prediction Probabilities:\")\nprint(prediction_probs)\n","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"tCMSB_X3aD5j","outputId":"100da404-cbf7-467f-df05-e67102269dbb","execution":{"iopub.status.busy":"2023-09-20T12:58:26.117002Z","iopub.execute_input":"2023-09-20T12:58:26.117806Z","iopub.status.idle":"2023-09-20T12:58:26.144563Z","shell.execute_reply.started":"2023-09-20T12:58:26.117759Z","shell.execute_reply":"2023-09-20T12:58:26.141601Z"},"trusted":true},"execution_count":38,"outputs":[{"name":"stdout","text":"Prediction Probabilities:\n[array([[0., 0., 0., ..., 0., 0., 0.]]), array([[0., 0., 0., ..., 0., 0., 0.]]), array([[0., 0., 0., ..., 0., 0., 0.]])]\n","output_type":"stream"}]},{"cell_type":"code","source":"","metadata":{"id":"EIaTpar2UVIk"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Pipeline(steps=[('cv', CountVectorizer()),\n ('knn', KNeighborsClassifier(n_neighbors=4))])","metadata":{"colab":{"base_uri":"https://localhost:8080/","height":126},"id":"NmKAnCLXQaRs","outputId":"4fd65da5-c850-4dc0-cb7d-a33512901951","execution":{"iopub.status.busy":"2023-09-20T12:58:26.146764Z","iopub.execute_input":"2023-09-20T12:58:26.147169Z","iopub.status.idle":"2023-09-20T12:58:26.174315Z","shell.execute_reply.started":"2023-09-20T12:58:26.147131Z","shell.execute_reply":"2023-09-20T12:58:26.172063Z"},"trusted":true},"execution_count":39,"outputs":[{"execution_count":39,"output_type":"execute_result","data":{"text/plain":"Pipeline(steps=[('cv', CountVectorizer()),\n ('knn', KNeighborsClassifier(n_neighbors=4))])","text/html":"
Pipeline(steps=[('cv', CountVectorizer()),\n                ('knn', KNeighborsClassifier(n_neighbors=4))])
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.
"},"metadata":{}}]},{"cell_type":"code","source":"pipe_knn.predict([ex1])","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"xQnQ2oZeQtiz","outputId":"e839d94f-7259-4d86-bc0d-efd02d0cdde7","execution":{"iopub.status.busy":"2023-09-20T12:58:26.176578Z","iopub.execute_input":"2023-09-20T12:58:26.178275Z","iopub.status.idle":"2023-09-20T12:58:26.210950Z","shell.execute_reply.started":"2023-09-20T12:58:26.178193Z","shell.execute_reply":"2023-09-20T12:58:26.207529Z"},"trusted":true},"execution_count":40,"outputs":[{"execution_count":40,"output_type":"execute_result","data":{"text/plain":"array([['there are many brands and forms of sodium chloride nasal available. not all brands are listed on this leaflet.',\n 'use exactly as directed on the label, or as prescribed by your doctor.',\n 'get emergency medical help if you have signs of an allergic reaction: hives; difficult breathing; swelling of your face, lips, tongue, or throat.']],\n dtype=object)"},"metadata":{}}]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}}]}