└── bayesian_classifier.ipynb /bayesian_classifier.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "code", 19 | "execution_count": 4, 20 | "metadata": { 21 | "id": "9o10DIVadLaT" 22 | }, 23 | "outputs": [], 24 | "source": [ 25 | "import pandas as pd\n", 26 | "from sklearn.model_selection import train_test_split\n", 27 | "from sklearn.naive_bayes import GaussianNB\n", 28 | "from sklearn.metrics import classification_report" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "source": [ 34 | "data = pd.read_csv('/content/sample_data/Student.csv')" 35 | ], 36 | "metadata": { 37 | "id": "bqhi1t8Kfil_" 38 | }, 39 | "execution_count": 5, 40 | "outputs": [] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "source": [ 45 | "X = data.drop(['Maths', 'Result'], axis=1) # Features\n", 46 | "X['Physics'] = data['Physics']\n", 47 | "X['Chemistry'] = data['Chemistry']\n", 48 | "y = data['Result']" 49 | ], 50 | "metadata": { 51 | "id": "60Z7ftQsfit0" 52 | }, 53 | "execution_count": 12, 54 | "outputs": [] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "source": [ 59 | "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)" 60 | ], 61 | "metadata": { 62 | "id": "SSqgwTUYgRvu" 63 | }, 64 | "execution_count": 13, 65 | "outputs": [] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "source": [ 70 | "classifier = GaussianNB()\n", 71 | "classifier.fit(X_train, y_train)" 72 | ], 73 | "metadata": { 74 | "colab": { 75 | "base_uri": "https://localhost:8080/", 76 | "height": 74 77 | }, 78 | "id": "G4JbRIPWgVng", 79 | "outputId": "636eb448-e7a2-433f-c79d-bb75113adeba" 80 | }, 81 | "execution_count": 14, 82 | "outputs": [ 83 | { 84 | "output_type": "execute_result", 85 | "data": { 86 | "text/plain": [ 87 | "GaussianNB()" 88 | ], 89 | "text/html": [ 90 | "
GaussianNB()
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.
" 91 | ] 92 | }, 93 | "metadata": {}, 94 | "execution_count": 14 95 | } 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "source": [ 101 | "y_pred = classifier.predict(X_test)" 102 | ], 103 | "metadata": { 104 | "id": "8UEG60f4gaFs" 105 | }, 106 | "execution_count": 15, 107 | "outputs": [] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "source": [ 112 | "print(\"Classification Report:\\n\", classification_report(y_test, y_pred))" 113 | ], 114 | "metadata": { 115 | "colab": { 116 | "base_uri": "https://localhost:8080/" 117 | }, 118 | "id": "-77AwXrygc-O", 119 | "outputId": "0826cafd-663f-42cd-96b7-848718b52eba" 120 | }, 121 | "execution_count": 16, 122 | "outputs": [ 123 | { 124 | "output_type": "stream", 125 | "name": "stdout", 126 | "text": [ 127 | "Classification Report:\n", 128 | " precision recall f1-score support\n", 129 | "\n", 130 | " 0 0.82 0.88 0.85 145\n", 131 | " 1 0.60 0.47 0.53 55\n", 132 | "\n", 133 | " accuracy 0.77 200\n", 134 | " macro avg 0.71 0.68 0.69 200\n", 135 | "weighted avg 0.76 0.77 0.76 200\n", 136 | "\n" 137 | ] 138 | } 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "source": [], 144 | "metadata": { 145 | "id": "1QgwV-zugecG" 146 | }, 147 | "execution_count": null, 148 | "outputs": [] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "source": [], 153 | "metadata": { 154 | "id": "YcDlDbXxgepA" 155 | }, 156 | "execution_count": null, 157 | "outputs": [] 158 | } 159 | ] 160 | } --------------------------------------------------------------------------------