{
"cells": [
{
"cell_type": "markdown",
"id": "b4454654",
"metadata": {},
"source": [
"### Machine Learning: Naive Bayes classifier for categorical data from scratch in Python\n",
"$P(C_k|\\textbf{x})\\propto P(C_k) P(\\textbf{x}|C_k)$\n",
"###### by Hamed Shah-Hosseini\n",
"Explanation at: https://www.pinterest.com/HamedShahHosseini/\n",
"
https://github.com/ostad-ai/Machine-Learning"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "50b8a8b6",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from collections import defaultdict"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "31065e4c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of samples in dataset:14\n"
]
}
],
"source": [
"# Reading dataset\n",
"weather=pd.read_csv('./datasets/weather.csv')\n",
"print(f'Number of samples in dataset:{len(weather)}')"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "d8583f14",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n", " | Outlook | \n", "Temperature | \n", "Humidity | \n", "Windy | \n", "Play | \n", "
---|---|---|---|---|---|
0 | \n", "Sunny | \n", "Hot | \n", "High | \n", "False | \n", "No | \n", "
1 | \n", "Sunny | \n", "Hot | \n", "High | \n", "True | \n", "No | \n", "
2 | \n", "Overcast | \n", "Hot | \n", "High | \n", "False | \n", "Yes | \n", "
3 | \n", "Rainy | \n", "Mild | \n", "High | \n", "False | \n", "Yes | \n", "
4 | \n", "Rainy | \n", "Cool | \n", "Normal | \n", "False | \n", "Yes | \n", "