Clean up.
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
104
Line fits.ipynb
104
Line fits.ipynb
@@ -1,104 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "1bba0128",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Simple fits\n",
|
||||
"\n",
|
||||
"Here we are fitting a line from scratch.\n",
|
||||
"In the next notebook, we will do fancier fits with neural networks, but let's start with a basic problem and complicate it as we go along.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "23feddde",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from typing import Tuple\n",
|
||||
"\n",
|
||||
"import pandas as pd\n",
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "bb1286f0",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"We start by generating some fake dataset, which is simple enough that we can visualize the results easily. For this reason, the dataset will contain only two variables.\n",
|
||||
"\n",
|
||||
"The simulated example data will be $f(x) = 3 x + \\epsilon$, where $\\epsilon \\sim \\mathcal{N}(\\mu=0, \\sigma=0.5)$.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "5d457cd8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def generate_data(N: int) -> np.ndarray:\n",
|
||||
" x = 2*np.random.randn(N, 1)\n",
|
||||
" epsilon = 0.5*np.random.randn(N, 1)\n",
|
||||
" z = 3*x + epsilon\n",
|
||||
" return np.concatenate((x, z), axis=1).astype(np.float32)\n",
|
||||
"\n",
|
||||
"data = generate_data(N=1000)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "48433f6f",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"We can fit this line from scratch, assuming $y = f(x) = \\beta x + \\alpha + \\epsilon$, where $\\epsilon$ is a zero-mean Gaussian noise.\n",
|
||||
"\n",
|
||||
"How would you do it? Feel free to use standard Python modules. Look at the solution for a simple mathematical expression for this fit with a full derivation.\n",
|
||||
"\n",
|
||||
"Tip: Look for the documentation for `numpy.linalg.lstsq`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "85040eef-3558-4531-9bce-4f29d520f86b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "5e9170af-ca77-4526-b3d2-e19e77fef44e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"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.10.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
BIN
bayes_reg_0.png
BIN
bayes_reg_0.png
Binary file not shown.
|
Before Width: | Height: | Size: 77 KiB |
BIN
bayes_reg_1.png
BIN
bayes_reg_1.png
Binary file not shown.
|
Before Width: | Height: | Size: 78 KiB |
BIN
bayes_reg_2.png
BIN
bayes_reg_2.png
Binary file not shown.
|
Before Width: | Height: | Size: 69 KiB |
BIN
bayes_reg_3.png
BIN
bayes_reg_3.png
Binary file not shown.
|
Before Width: | Height: | Size: 69 KiB |
Reference in New Issue
Block a user