Notebooks zum Lektüre
 
Go to file
Aurélien Geron fa0c676b6b Merge pull request #314 from lvnilesh/patch-3
Persist after reboot
2018-12-02 16:48:12 +13:00
docker Merge pull request #314 from lvnilesh/patch-3 2018-12-02 16:48:12 +13:00
images Add clustering, density estimation and anomaly detection to chapter 8 2018-04-04 11:49:00 +02:00
.gitignore Add *.old, *.dot and lifesat.csv (generated) to .gitignore 2018-05-07 22:46:44 +02:00
01_the_machine_learning_landscape.ipynb Make the code example 1-1 easier to read, and create a better `prepare_country_stats()` function 2018-01-15 17:25:36 +01:00
02_end_to_end_machine_learning_project.ipynb Fix comment in DataFrameSelector 2018-07-31 23:10:23 +01:00
03_classification.ipynb Add boxplot in notebook 03, exercise 3 2018-05-26 15:01:33 +02:00
04_training_linear_models.ipynb mean_squared_error(y_true, y_pred) instead of (y_pred, y_true), for clarity (result unchanged). Fixes #158 2018-03-15 19:17:51 +01:00
05_support_vector_machines.ipynb Replace n_iter with max_iter in SGDClassifier 2018-05-08 12:36:43 +02:00
06_decision_trees.ipynb Remove linewidth argument for plt.contourf() 2018-05-08 12:38:05 +02:00
07_ensemble_learning_and_random_forests.ipynb Add solution of exercises 7.8 (voting classifier) and 7.9 (stacking ensemble) 2018-05-09 10:09:04 +02:00
08_dimensionality_reduction.ipynb Correction of a typo 2018-08-06 21:57:40 +02:00
09_up_and_running_with_tensorflow.ipynb Use tensorflow_graph_in_jupyter.py in notebooks, fixes #223 2018-05-18 21:22:56 +02:00
10_introduction_to_artificial_neural_networks.ipynb Use tensorflow_graph_in_jupyter.py in notebooks, fixes #223 2018-05-18 21:22:56 +02:00
11_deep_learning.ipynb Remove unnecessary variable initialization, fixes #283 2018-08-20 18:55:24 +02:00
12_distributed_tensorflow.ipynb Add a quick intro to the Data API in notebook 12 2018-05-07 22:45:48 +02:00
13_convolutional_neural_networks.ipynb Improve comment format about OSX and Python 3.6, SSL certificates 2017-10-18 09:18:46 +02:00
14_recurrent_neural_networks.ipynb Make notebook 14 reproducible (except for the dropout section, that one is tough), fixes #274 2018-08-06 16:28:10 +01:00
15_autoencoders.ipynb Fix a typo: s/it/is 2018-02-27 11:57:11 +05:30
16_reinforcement_learning.ipynb Update ReplayMemory class and add a short description 2018-05-09 16:54:17 +02:00
LICENSE First notebook added: matplotlib 2016-02-16 21:40:20 +01:00
README.md Fix the virtualenv activation command for Windows (fixes #287) 2018-09-03 22:26:31 +02:00
book_equations.ipynb Fix equation 16-6 (max_alpha'=>max_a') 2018-05-07 22:47:28 +02:00
extra_autodiff.ipynb Improve formatting 2018-05-18 17:17:51 +02:00
extra_capsnets-cn.ipynb zh-cn version 2018-05-02 21:03:33 +08:00
extra_capsnets.ipynb made initial weights higher-variance 2018-02-10 19:24:56 +02:00
extra_gradient_descent_comparison.ipynb Add intro paragraph, tx to Daniel and minor formatting fixes 2018-09-17 11:51:05 +02:00
extra_tensorflow_reproducibility.ipynb Fix expected result for first estimator training 2018-09-03 23:22:17 +02:00
future_encoders.py Add ColumnTransformer to future_encoders.py 2018-07-31 20:09:12 +01:00
index.ipynb Add a notebook about achieving reproducibility with TensorFlow 2018-08-11 12:20:57 +01:00
math_linear_algebra.ipynb Right angle is pi/2, not pi/4. One reason why tau > pi ;) 2017-10-27 13:03:15 +02:00
requirements.txt Add jupyter-tensorboard to requirements.txt, it's pretty handy 2018-05-18 20:53:38 +02:00
tensorflow_graph_in_jupyter.py Use tensorflow_graph_in_jupyter.py in notebooks, fixes #223 2018-05-18 21:22:56 +02:00
tools_matplotlib.ipynb fixed typo in tools_matplotlib.ipynb 2016-03-04 08:49:56 +01:00
tools_numpy.ipynb Fix small typo in numpy notebook 2018-03-24 17:34:38 +03:00
tools_pandas.ipynb Upgrade to latest pandas version, update resampling API 2018-01-05 14:36:11 +01:00

README.md

Machine Learning Notebooks

This project aims at teaching you the fundamentals of Machine Learning in python. It contains the example code and solutions to the exercises in my O'Reilly book Hands-on Machine Learning with Scikit-Learn and TensorFlow:

book

Simply open the Jupyter notebooks you are interested in:

  • Using jupyter.org's notebook viewer
  • or by cloning this repository and running Jupyter locally. This option lets you play around with the code. In this case, follow the installation instructions below.

Installation

First, you will need to install git, if you don't have it already.

Next, clone this repository by opening a terminal and typing the following commands:

$ cd $HOME  # or any other development directory you prefer
$ git clone https://github.com/ageron/handson-ml.git
$ cd handson-ml

If you do not want to install git, you can instead download master.zip, unzip it, rename the resulting directory to handson-ml and move it to your development directory.

If you want to go through chapter 16 on Reinforcement Learning, you will need to install OpenAI gym and its dependencies for Atari simulations.

If you are familiar with Python and you know how to install Python libraries, go ahead and install the libraries listed in requirements.txt and jump to the Starting Jupyter section. If you need detailed instructions, please read on.

Python & Required Libraries

Of course, you obviously need Python. Python 2 is already preinstalled on most systems nowadays, and sometimes even Python 3. You can check which version(s) you have by typing the following commands:

$ python --version   # for Python 2
$ python3 --version  # for Python 3

Any Python 3 version should be fine, preferably ≥3.5. If you don't have Python 3, I recommend installing it (Python ≥2.6 should work, but it is deprecated so Python 3 is preferable). To do so, you have several options: on Windows or MacOSX, you can just download it from python.org. On MacOSX, you can alternatively use MacPorts or Homebrew. If you are using Python 3.6 on MacOSX, you need to run the following command to install the certifi package of certificates because Python 3.6 on MacOSX has no certificates to validate SSL connections (see this StackOverflow question):

$ /Applications/Python\ 3.6/Install\ Certificates.command

On Linux, unless you know what you are doing, you should use your system's packaging system. For example, on Debian or Ubuntu, type:

$ sudo apt-get update
$ sudo apt-get install python3

Another option is to download and install Anaconda. This is a package that includes both Python and many scientific libraries. You should prefer the Python 3 version.

If you choose to use Anaconda, read the next section, or else jump to the Using pip section.

Using Anaconda

When using Anaconda, you can optionally create an isolated Python environment dedicated to this project. This is recommended as it makes it possible to have a different environment for each project (e.g. one for this project), with potentially different libraries and library versions:

$ conda create -n mlbook python=3.5 anaconda
$ source activate mlbook

This creates a fresh Python 3.5 environment called mlbook (you can change the name if you want to), and it activates it. This environment contains all the scientific libraries that come with Anaconda. This includes all the libraries we will need (NumPy, Matplotlib, Pandas, Jupyter and a few others), except for TensorFlow, so let's install it:

$ conda install -n mlbook -c conda-forge tensorflow

This installs the latest version of TensorFlow available for Anaconda (which is usually not the latest TensorFlow version) in the mlbook environment (fetching it from the conda-forge repository). If you chose not to create an mlbook environment, then just remove the -n mlbook option.

Next, you can optionally install Jupyter extensions. These are useful to have nice tables of contents in the notebooks, but they are not required.

$ conda install -n mlbook -c conda-forge jupyter_contrib_nbextensions

You are all set! Next, jump to the Starting Jupyter section.

Using pip

If you are not using Anaconda, you need to install several scientific Python libraries that are necessary for this project, in particular NumPy, Matplotlib, Pandas, Jupyter and TensorFlow (and a few others). For this, you can either use Python's integrated packaging system, pip, or you may prefer to use your system's own packaging system (if available, e.g. on Linux, or on MacOSX when using MacPorts or Homebrew). The advantage of using pip is that it is easy to create multiple isolated Python environments with different libraries and different library versions (e.g. one environment for each project). The advantage of using your system's packaging system is that there is less risk of having conflicts between your Python libraries and your system's other packages. Since I have many projects with different library requirements, I prefer to use pip with isolated environments. Moreover, the pip packages are usually the most recent ones available, while Anaconda and system packages often lag behind a bit.

These are the commands you need to type in a terminal if you want to use pip to install the required libraries. Note: in all the following commands, if you chose to use Python 2 rather than Python 3, you must replace pip3 with pip, and python3 with python.

First you need to make sure you have the latest version of pip installed:

$ pip3 install --user --upgrade pip

The --user option will install the latest version of pip only for the current user. If you prefer to install it system wide (i.e. for all users), you must have administrator rights (e.g. use sudo pip3 instead of pip3 on Linux), and you should remove the --user option. The same is true of the command below that uses the --user option.

Next, you can optionally create an isolated environment. This is recommended as it makes it possible to have a different environment for each project (e.g. one for this project), with potentially very different libraries, and different versions:

$ pip3 install --user --upgrade virtualenv
$ virtualenv -p `which python3` env

This creates a new directory called env in the current directory, containing an isolated Python environment based on Python 3. If you installed multiple versions of Python 3 on your system, you can replace `which python3` with the path to the Python executable you prefer to use.

Now you must activate this environment. You will need to run this command every time you want to use this environment.

$ source ./env/bin/activate

On Windows, the command is slightly different:

$ .\env\Scripts\activate

Next, use pip to install the required python packages. If you are not using virtualenv, you should add the --user option (alternatively you could install the libraries system-wide, but this will probably require administrator rights, e.g. using sudo pip3 instead of pip3 on Linux).

$ pip3 install --upgrade -r requirements.txt

Great! You're all set, you just need to start Jupyter now.

Starting Jupyter

If you want to use the Jupyter extensions (optional, they are mainly useful to have nice tables of contents), you first need to install them:

$ jupyter contrib nbextension install --user

Then you can activate an extension, such as the Table of Contents (2) extension:

$ jupyter nbextension enable toc2/main

Okay! You can now start Jupyter, simply type:

$ jupyter notebook

This should open up your browser, and you should see Jupyter's tree view, with the contents of the current directory. If your browser does not open automatically, visit localhost:8888. Click on index.ipynb to get started!

Note: you can also visit http://localhost:8888/nbextensions to activate and configure Jupyter extensions.

Congrats! You are ready to learn Machine Learning, hands on!

Contributors

I would like to thank everyone who contributed to this project, either by providing useful feedback, filing issues or submitting Pull Requests. Special thanks go to Steven Bunkley and Ziembla who created the docker directory.