First draft.

This commit is contained in:
Danilo Enoque Ferreira de Lima 2024-04-30 20:17:31 +02:00
parent 29f46c859a
commit 65893bbabf
26 changed files with 11353 additions and 1 deletions

317
1 Line fits.ipynb Normal file

File diff suppressed because one or more lines are too long

587
2 Bayesian fits.ipynb Normal file

File diff suppressed because one or more lines are too long

492
3 Non-linear fits.ipynb Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

777
5 Gaussian Processes.ipynb Normal file

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

126
Basic statistics.ipynb Normal file
View File

@ -0,0 +1,126 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "1c0d6d14-a97f-41f2-8b3e-673399418107",
"metadata": {},
"source": [
"# Basic statistics\n",
"\n",
"Here, the goal is to get used to several concepts in basic statistics needed later on for Machine Learning.\n",
"We are going to generate a simple dataset ourselves and try to calculate some standard quantities to describe them.\n",
"\n",
"First, let's import some standard libraries and generate the dataset."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "d5a29abd-6af1-4b18-8bec-8a8402b97dc7",
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"import pandas as pd\n",
"import numpy as np\n",
"import seaborn as sns"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "f4bed5ac-0828-4e5f-a166-2e161557b49b",
"metadata": {},
"outputs": [],
"source": [
"rng = np.random.RandomState(0)\n",
"n_samples = 10000\n",
"cov = [[1, 0.7*1*1.3, 0.3*1.3*1],\n",
" [0.7*1*1.3, 1.3**2, 0],\n",
" [0.3*1.3*1, 0, 1.5**2]]\n",
"data = rng.multivariate_normal(mean=[1, -1, 0], cov=cov, size=n_samples)\n",
"data = pd.DataFrame(data, columns=[\"x1\", \"x2\", \"x3\"])"
]
},
{
"cell_type": "markdown",
"id": "87d5cd39-4720-4eba-a268-0c38a561976a",
"metadata": {},
"source": [
"First, make a scatter plot of this dataset using matplotlib to visualise what are the possible values of $x_1$, $x_2$ and $x_3$.\n",
"One can make a 2D plot of $x_1$ versus $x_2$, $x_2$ versus $x_3$ or $x_1$ versus $x_3$ to understand how they relate to one another.\n",
"\n",
"Often this is cumbersome if one has too many variables to plot, but we are going to discuss methods to get around this later in the lecture.\n",
"\n",
"One tip: one may use `plt.scatter` for every pair of variables to do this, or use the seaborn module to plot all pairs in one go. Look for documentation on `sns.pairplot`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7de735cf-3466-41e9-bcd5-fcc756958019",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "89a1c59f-9ff7-4c16-a85e-c390b9f77b31",
"metadata": {},
"source": [
"What are the means and covariances of each variable?\n",
"Can you explain how they can be geometrically interpreted from the plots above?\n",
"\n",
"Tip 1: Try subtracting the mean from the variables, dividing by the square root of the variance, and plotting the variables again. If you fit a line to the data, what is the slope? What is the correlation coefficient?\n",
"\n",
"Tip 2: Try using `np.linalg.eig(covariance_matrix)` to decompose the covariance matrix into eigenvectors and try interpreting it.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ee885793-46a8-424c-be66-7b9c642c296a",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "df9f429b-e218-49fd-bc72-fca2e77ba770",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "54373271-dd1a-4fdd-8f49-b7db7a595695",
"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
}

284
Bayesian fits.ipynb Normal file

File diff suppressed because one or more lines are too long

873
CLT.ipynb Normal file

File diff suppressed because one or more lines are too long

667
Gaussian Processes.ipynb Normal file

File diff suppressed because one or more lines are too long

199
Line fits (sol.).ipynb Normal file

File diff suppressed because one or more lines are too long

104
Line fits.ipynb Normal file
View File

@ -0,0 +1,104 @@
{
"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
}

703
Mixture Models.ipynb Normal file

File diff suppressed because one or more lines are too long

View File

@ -1 +1,92 @@
# ml-lecture-eiroforum
# ml-lecture-eiroforum
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://git.xfel.eu/machineLearning/ml-lecture-eiroforum.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://git.xfel.eu/machineLearning/ml-lecture-eiroforum/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

BIN
SVM_margin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 KiB

532
Supervised Regression.ipynb Normal file

File diff suppressed because one or more lines are too long

BIN
bayes_reg_0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

BIN
bayes_reg_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

BIN
bayes_reg_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

BIN
bayes_reg_3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

2536
co2_weekly_mlo.txt Normal file

File diff suppressed because it is too large Load Diff

BIN
data.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
linear_classifier.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB