{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Validating the Normal Distribution\n",
"\n",
"The [Normal Distribution](https://en.wikipedia.org/wiki/Normal_distribution) or Gaussian Distribution is a probability distribution with a distinctive bell-curve shape. It has the property that 68.2% of all values are within one standard deviation of the mean, and 95.45% of all values are within two standard deviations of the mean.\n",
"\n",
"Here, you'll be verifying that ~95% of the values are indeed between -2 standard deviations and +2 standard deviations of the mean by sampling randomly."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from numpy.random import default_rng"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([-0.20262383, -0.5297287 , -0.34621358, -0.08370099, -0.09591137])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rng = default_rng()\n",
"values = rng.standard_normal(10_000)\n",
"values[:5]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"9550"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"std = values.std()\n",
"filtered = values[(values > -2 * std) & (values < 2 * std)]\n",
"\n",
"filtered.size"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10000"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"values.size"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.955"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"filtered.size / values.size"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}