{ "cells": [ { "cell_type": "code", "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2024-09-17T16:29:11.360662Z", "start_time": "2024-09-17T16:29:08.630629Z" } }, "source": [ "import pandas as pd\n", "dataset = pd.read_csv('Training.csv')\n", "dataset.head()" ], "outputs": [ { "data": { "text/plain": [ " itching skin_rash nodal_skin_eruptions continuous_sneezing shivering \\\n", "0 1 1 1 0 0 \n", "1 0 1 1 0 0 \n", "2 1 0 1 0 0 \n", "3 1 1 0 0 0 \n", "4 1 1 1 0 0 \n", "\n", " chills joint_pain stomach_pain acidity ulcers_on_tongue ... \\\n", "0 0 0 0 0 0 ... \n", "1 0 0 0 0 0 ... \n", "2 0 0 0 0 0 ... \n", "3 0 0 0 0 0 ... \n", "4 0 0 0 0 0 ... \n", "\n", " blackheads scurring skin_peeling silver_like_dusting \\\n", "0 0 0 0 0 \n", "1 0 0 0 0 \n", "2 0 0 0 0 \n", "3 0 0 0 0 \n", "4 0 0 0 0 \n", "\n", " small_dents_in_nails inflammatory_nails blister red_sore_around_nose \\\n", "0 0 0 0 0 \n", "1 0 0 0 0 \n", "2 0 0 0 0 \n", "3 0 0 0 0 \n", "4 0 0 0 0 \n", "\n", " yellow_crust_ooze prognosis \n", "0 0 Fungal infection \n", "1 0 Fungal infection \n", "2 0 Fungal infection \n", "3 0 Fungal infection \n", "4 0 Fungal infection \n", "\n", "[5 rows x 133 columns]" ], "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
itchingskin_rashnodal_skin_eruptionscontinuous_sneezingshiveringchillsjoint_painstomach_painacidityulcers_on_tongue...blackheadsscurringskin_peelingsilver_like_dustingsmall_dents_in_nailsinflammatory_nailsblisterred_sore_around_noseyellow_crust_oozeprognosis
01110000000...000000000Fungal infection
10110000000...000000000Fungal infection
21010000000...000000000Fungal infection
31100000000...000000000Fungal infection
41110000000...000000000Fungal infection
\n", "

5 rows × 133 columns

\n", "
" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 2 }, { "metadata": { "ExecuteTime": { "end_time": "2024-09-17T16:38:10.415115Z", "start_time": "2024-09-17T16:38:10.401958Z" } }, "cell_type": "code", "source": [ "from sklearn.model_selection import train_test_split\n", "from sklearn.preprocessing import LabelEncoder\n", "X = dataset.drop('prognosis', axis=1)\n", "y = dataset['prognosis']\n", "\n", "# ecoding prognonsis\n", "le = LabelEncoder()\n", "le.fit(y)\n", "Y = le.transform(y)\n", " \n", "X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.3, random_state=20)" ], "id": "2f4c60f8146e8fc0", "outputs": [], "execution_count": 4 }, { "metadata": { "ExecuteTime": { "end_time": "2024-09-17T16:38:12.287595Z", "start_time": "2024-09-17T16:38:12.194789Z" } }, "cell_type": "code", "source": [ "from sklearn.svm import SVC\n", "from sklearn.metrics import accuracy_score, confusion_matrix\n", "import numpy as np\n", "\n", "model=SVC(kernel='linear')\n", "model.fit(X_train, y_train)\n", "y_pred = model.predict(X_test)" ], "id": "6db6ccb7f91c6e13", "outputs": [], "execution_count": 5 }, { "metadata": { "ExecuteTime": { "end_time": "2024-09-17T16:38:38.657121Z", "start_time": "2024-09-17T16:38:38.650755Z" } }, "cell_type": "code", "source": "accuracy_score(y_test,y_pred)", "id": "791860a4e7b79da2", "outputs": [ { "data": { "text/plain": [ "1.0" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 7 }, { "metadata": { "ExecuteTime": { "end_time": "2024-09-17T16:59:15.525296Z", "start_time": "2024-09-17T16:59:15.518217Z" } }, "cell_type": "code", "source": [ "# save svc\n", "import pickle\n", "pickle.dump(model,open('svc.pkl','wb'))" ], "id": "7435482d4733f455", "outputs": [], "execution_count": 26 }, { "metadata": { "ExecuteTime": { "end_time": "2024-09-17T16:54:06.203635Z", "start_time": "2024-09-17T16:54:06.175734Z" } }, "cell_type": "code", "source": "", "id": "a26a9f66296a03ec", "outputs": [], "execution_count": 23 }, { "metadata": { "ExecuteTime": { "end_time": "2024-09-17T16:51:31.268445Z", "start_time": "2024-09-17T16:51:31.246267Z" } }, "cell_type": "code", "source": "", "id": "24d7cc296cacd5b6", "outputs": [], "execution_count": 21 }, { "metadata": { "ExecuteTime": { "end_time": "2024-09-17T16:51:40.537719Z", "start_time": "2024-09-17T16:51:34.848795Z" } }, "cell_type": "code", "source": "", "id": "dbf8bd3bd142cb2", "outputs": [ { "ename": "KeyError", "evalue": "''", "output_type": "error", "traceback": [ "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m", "\u001B[1;31mKeyError\u001B[0m Traceback (most recent call last)", "Cell \u001B[1;32mIn[22], line 7\u001B[0m\n\u001B[0;32m 5\u001B[0m \u001B[38;5;66;03m# Remove any extra characters, if any\u001B[39;00m\n\u001B[0;32m 6\u001B[0m user_symptoms \u001B[38;5;241m=\u001B[39m [symptom\u001B[38;5;241m.\u001B[39mstrip(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m[]\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m \u001B[39m\u001B[38;5;124m\"\u001B[39m) \u001B[38;5;28;01mfor\u001B[39;00m symptom \u001B[38;5;129;01min\u001B[39;00m user_symptoms]\n\u001B[1;32m----> 7\u001B[0m predicted_disease \u001B[38;5;241m=\u001B[39m \u001B[43mget_predicted_value\u001B[49m\u001B[43m(\u001B[49m\u001B[43muser_symptoms\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 9\u001B[0m desc, pre, med, die, wrkout \u001B[38;5;241m=\u001B[39m helper(predicted_disease)\n\u001B[0;32m 11\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m=================predicted disease============\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n", "Cell \u001B[1;32mIn[21], line 69\u001B[0m, in \u001B[0;36mget_predicted_value\u001B[1;34m(patient_symptoms)\u001B[0m\n\u001B[0;32m 67\u001B[0m input_vector \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39mzeros(\u001B[38;5;28mlen\u001B[39m(symptoms_dict))\n\u001B[0;32m 68\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m item \u001B[38;5;129;01min\u001B[39;00m patient_symptoms:\n\u001B[1;32m---> 69\u001B[0m input_vector[\u001B[43msymptoms_dict\u001B[49m\u001B[43m[\u001B[49m\u001B[43mitem\u001B[49m\u001B[43m]\u001B[49m] \u001B[38;5;241m=\u001B[39m \u001B[38;5;241m1\u001B[39m\n\u001B[0;32m 70\u001B[0m predicted_disease \u001B[38;5;241m=\u001B[39m SVC\u001B[38;5;241m.\u001B[39mpredict([input_vector])[\u001B[38;5;241m0\u001B[39m] \u001B[38;5;66;03m# Corrected prediction syntax\u001B[39;00m\n\u001B[0;32m 71\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m diseases_list[predicted_disease]\n", "\u001B[1;31mKeyError\u001B[0m: ''" ] } ], "execution_count": 22 }, { "metadata": {}, "cell_type": "code", "outputs": [], "execution_count": null, "source": "", "id": "edbef80ce1e1101d" } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 5 }