└── 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.
GaussianNB()