mirror of
https://github.com/fenago/data-science.git
synced 2026-05-04 16:41:05 +00:00
235 lines
4.9 KiB
Plaintext
235 lines
4.9 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {},
|
|
"colab_type": "code",
|
|
"id": "X6QIH3eK6Hwd"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import matplotlib.pyplot as plt"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {},
|
|
"colab_type": "code",
|
|
"id": "tbfUwHym6vhs"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# list of all xs\n",
|
|
"x = list(range(1, 11))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 34
|
|
},
|
|
"colab_type": "code",
|
|
"executionInfo": {
|
|
"elapsed": 1166,
|
|
"status": "ok",
|
|
"timestamp": 1571315496557,
|
|
"user": {
|
|
"displayName": "Andrew Worsley",
|
|
"photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mAp-Td-yKvu76Tg0Swzal8U17btuwNIXFmWVwZo=s64",
|
|
"userId": "11337101975325054847"
|
|
},
|
|
"user_tz": -660
|
|
},
|
|
"id": "C5oA9j5B7THl",
|
|
"outputId": "45bb6609-a114-41b3-ea99-f7df75d02fa5"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"print(x)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {},
|
|
"colab_type": "code",
|
|
"id": "RFRcEQHp9ZdC"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# pmf\n",
|
|
"p_X_x = [1/len(x)] * len(x)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 34
|
|
},
|
|
"colab_type": "code",
|
|
"executionInfo": {
|
|
"elapsed": 1154,
|
|
"status": "ok",
|
|
"timestamp": 1571315496561,
|
|
"user": {
|
|
"displayName": "Andrew Worsley",
|
|
"photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mAp-Td-yKvu76Tg0Swzal8U17btuwNIXFmWVwZo=s64",
|
|
"userId": "11337101975325054847"
|
|
},
|
|
"user_tz": -660
|
|
},
|
|
"id": "PSoAZpl99nLv",
|
|
"outputId": "316a65df-1e28-4dd7-87ad-63fc33207efb"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# sums to \n",
|
|
"print(p_X_x)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 300
|
|
},
|
|
"colab_type": "code",
|
|
"executionInfo": {
|
|
"elapsed": 1649,
|
|
"status": "ok",
|
|
"timestamp": 1571315497065,
|
|
"user": {
|
|
"displayName": "Andrew Worsley",
|
|
"photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mAp-Td-yKvu76Tg0Swzal8U17btuwNIXFmWVwZo=s64",
|
|
"userId": "11337101975325054847"
|
|
},
|
|
"user_tz": -660
|
|
},
|
|
"id": "qShRhhOn934X",
|
|
"outputId": "b3f0f052-558e-4bdf-b294-218a980dd36b"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"plt.bar(x, p_X_x)\n",
|
|
"plt.xlabel('X')\n",
|
|
"plt.ylabel('P(X=x)')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {},
|
|
"colab_type": "code",
|
|
"id": "M72x9J89FnN8"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import numpy as np\n",
|
|
"import scipy.stats as stats"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {},
|
|
"colab_type": "code",
|
|
"id": "M2ssEju6Gg1A"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# range of xs\n",
|
|
"x = np.linspace(-10, 10, 100)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {},
|
|
"colab_type": "code",
|
|
"id": "q9ikfnk-HEhE"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# first normal distribution with mean = 0, variance = 1\n",
|
|
"p_X_1 = stats.norm.pdf(x=x, loc=0.0, scale=1.0**2)\n",
|
|
"\n",
|
|
"# second normal distribution with mean = 0, variance = 2.25\n",
|
|
"p_X_2 = stats.norm.pdf(x=x, loc=0.0, scale=1.5**2)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 300
|
|
},
|
|
"colab_type": "code",
|
|
"executionInfo": {
|
|
"elapsed": 1234,
|
|
"status": "ok",
|
|
"timestamp": 1571315524484,
|
|
"user": {
|
|
"displayName": "Andrew Worsley",
|
|
"photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mAp-Td-yKvu76Tg0Swzal8U17btuwNIXFmWVwZo=s64",
|
|
"userId": "11337101975325054847"
|
|
},
|
|
"user_tz": -660
|
|
},
|
|
"id": "sYZ9BRflIJkE",
|
|
"outputId": "ff365e43-a2c7-4b3b-dfdf-65ec397401e5"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"plt.plot(x,p_X_1, color='blue')\n",
|
|
"plt.plot(x, p_X_2, color='orange')\n",
|
|
"plt.xlabel('X')\n",
|
|
"plt.ylabel('P(X)')"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"colab": {
|
|
"collapsed_sections": [],
|
|
"name": "distributions.ipynb",
|
|
"provenance": []
|
|
},
|
|
"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.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 1
|
|
}
|