Skip to content

Commit 2435591

Browse files
committed
ch01
0 parents  commit 2435591

14 files changed

+769
-0
lines changed

Diff for: .gitignore

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
*checkpoint
2+
*tfevents*
3+
*.data-00000-of-00001
4+
*.index
5+
*.meta
6+
*.local
7+
train-images-idx3-ubyte
8+
train-labels-idx1-ubyte
9+
t10k-labels-idx1-ubyte
10+
t10k-images-idx3-ubyte
11+
code/ch14/checkpoint
12+
code/ch12/mnist_scaled.npz
13+
docs/equations/*.aux
14+
docs/equations/*.log
15+
docs/equations/*.out
16+
docs/equations/*.synctex.gz
17+
code/ch08/aclImdb/
18+
19+
.ipynb_checkpoints
20+
.DS_Store
21+
code/datasets/movie/aclImdb_v1.tar.gz
22+
23+
# Byte-compiled / optimized / DLL files
24+
__pycache__/
25+
*.py[cod]
26+
27+
# C extensions
28+
*.so
29+
30+
# Distribution / packaging
31+
.Python
32+
env/
33+
build/
34+
develop-eggs/
35+
dist/
36+
downloads/
37+
eggs/
38+
.eggs/
39+
lib/
40+
lib64/
41+
parts/
42+
sdist/
43+
var/
44+
*.egg-info/
45+
.installed.cfg
46+
*.egg
47+
48+
# PyInstaller
49+
# Usually these files are written by a python script from a template
50+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
51+
*.manifest
52+
*.spec
53+
54+
# Installer logs
55+
pip-log.txt
56+
pip-delete-this-directory.txt
57+
58+
# Unit test / coverage reports
59+
htmlcov/
60+
.tox/
61+
.coverage
62+
.coverage.*
63+
.cache
64+
nosetests.xml
65+
coverage.xml
66+
*,cover
67+
68+
# Translations
69+
*.mo
70+
*.pot
71+
72+
# Django stuff:
73+
*.log
74+
75+
# Sphinx documentation
76+
docs/_build/
77+
78+
# PyBuilder
79+
target/

Diff for: ch01/README.md

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
Sebastian Raschka, 2019
2+
3+
Python Machine Learning - Code Examples
4+
5+
6+
## Chapter 1: Giving Computers the Ability to Learn from Data
7+
8+
9+
---
10+
11+
**Chapter 1 does not contain any code examples.**
12+
13+
---
14+
15+
## Installing Python packages
16+
17+
Python is available for all three major operating systems — Microsoft Windows, macOS, and Linux — and the installer, as well as the documentation, can be downloaded from the official Python website: https://www.python.org.
18+
19+
This book is written for Python version `>= 3.7.0`, and it is recommended
20+
you use the most recent version of Python 3 that is currently available,
21+
although most of the code examples may also be compatible with older versions of Python 3 and Python `>= 2.7.10`. If you decide to use Python 2.7 to execute the code examples, please make sure that you know about the major differences between the two Python versions. A good summary about the differences between Python 3 and 2.7 can be found at https://wiki.python.org/moin/Python2orPython3.
22+
23+
**Note**
24+
25+
You can check your current default version of Python by executing
26+
27+
$ python -V
28+
29+
In my case, it returns
30+
31+
Python 3.7.1 :: Continuum Analytics, Inc.
32+
33+
34+
#### Pip
35+
36+
The additional packages that we will be using throughout this book can be installed via the `pip` installer program, which has been part of the Python standard library since Python 3.3. More information about pip can be found at https://docs.python.org/3/installing/index.html.
37+
38+
After we have successfully installed Python, we can execute pip from the command line terminal to install additional Python packages:
39+
40+
pip install SomePackage
41+
42+
43+
(where `SomePackage` is a placeholder for numpy, pandas, matplotlib, scikit-learn, and so forth).
44+
45+
Already installed packages can be updated via the `--upgrade` flag:
46+
47+
pip install SomePackage --upgrade
48+
49+
50+
#### Anaconda
51+
52+
A highly recommended alternative Python distribution for scientific computing
53+
is Anaconda by Continuum Analytics. Anaconda is a free—including commercial use—enterprise-ready Python distribution that bundles all the essential Python packages for data science, math, and engineering in one user-friendly cross-platform distribution. The Anaconda installer can be downloaded at https://docs.anaconda.com/anaconda/install/, and an Anaconda quick start-guide is available at https://docs.anaconda.com/anaconda/user-guide/getting-started/.
54+
55+
After successfully installing Anaconda, we can install new Python packages using the following command:
56+
57+
conda install SomePackage
58+
59+
Existing packages can be updated using the following command:
60+
61+
conda update SomePackage
62+
63+
Throughout this book, we will mainly use NumPy's multi-dimensional arrays to store and manipulate data. Occasionally, we will make use of pandas, which is a library built on top of NumPy that provides additional higher level data manipulation tools that make working with tabular data even more convenient. To augment our learning experience and visualize quantitative data, which is often extremely useful to intuitively make sense of it, we will use the very customizable matplotlib library.
64+
65+
#### Core packages
66+
67+
The version numbers of the major Python packages that were used for writing this book are listed below. Please make sure that the version numbers of your installed packages are equal to, or greater than, those version numbers to ensure the code examples run correctly:
68+
69+
- [NumPy](http://www.numpy.org) >= 1.16.4
70+
- [SciPy](http://www.scipy.org) >= 1.2.1
71+
- [scikit-learn](http://scikit-learn.org/stable/) >= 0.21.1
72+
- [matplotlib](http://matplotlib.org) >= 3.1.0
73+
- [pandas](http://pandas.pydata.org) >= 0.24.2
74+
75+
## Python/Jupyter Notebook
76+
77+
Some readers were wondering about the `.ipynb` of the code files -- these files are IPython notebooks. I chose IPython notebooks over plain Python `.py` scripts, because I think that they are just great for data analysis projects! IPython notebooks allow us to have everything in one place: Our code, the results from executing the code, plots of our data, and documentation that supports the handy Markdown and powerful LaTeX syntax!
78+
79+
![](./images/ipynb_ex1.png)
80+
81+
**Side Note:** "IPython Notebook" recently became the "[Jupyter Notebook](<http://jupyter.org>)"; Jupyter is an umbrella project that aims to support other languages in addition to Python including Julia, R, and many more. Don't worry, though, for a Python user, there's only a difference in terminology (we say "Jupyter Notebook" now instead of "IPython Notebook").
82+
83+
The Jupyter notebook can be installed as usually via pip.
84+
85+
$ pip install jupyter notebook
86+
87+
Alternatively, we can use the Conda installer if we have Anaconda or Miniconda installed:
88+
89+
$ conda install jupyter notebook
90+
91+
To open a Jupyter notebook, we `cd` to the directory that contains your code examples, e.g,.
92+
93+
94+
$ cd ~/code/python-machine-learning-book
95+
96+
and launch `jupyter notebook` by executing
97+
98+
$ jupyter notebook
99+
100+
Jupyter will start in our default browser (typically running at [http://localhost:8888/](http://localhost:8888/)). Now, we can simply select the notebook you wish to open from the Jupyter menu.
101+
102+
![](./images/ipynb_ex2.png)
103+
104+
For more information about the Jupyter notebook, I recommend the [Jupyter Beginner Guide](http://jupyter-notebook-beginner-guide.readthedocs.org/en/latest/what_is_jupyter.html) and [Jupyter Notebook Basics](https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Notebook%20Basics.html).
105+
106+
## Jupyter Lab
107+
108+
An alternative to Jupyter Notebook, called Jupyter Lab, was released in 2018. It operates with the same `.ipynb` file types but offers some extra features in the browser interface. Whether you use Jupyter Notebook or Jupyter Lab is a matter of preference, but
109+
110+
Jupyter Lab can be installed via
111+
112+
$ conda install -c conda-forge jupyterlab
113+
114+
and similar to starting Jupyter Notebooks, you can run the command
115+
116+
$ jupyter lab
117+
118+
in your command line terminal to launch a Jupyter Lab session in your browser. For more information about the Jupyter Lab project, please visit the official documentation at https://jupyterlab.readthedocs.io/en/stable/,

Diff for: ch01/ch01.ipynb

+572
Large diffs are not rendered by default.

Diff for: ch01/images/01_01.png

403 KB
Loading

Diff for: ch01/images/01_02.png

278 KB
Loading

Diff for: ch01/images/01_03.png

547 KB
Loading

Diff for: ch01/images/01_04.png

446 KB
Loading

Diff for: ch01/images/01_05.png

222 KB
Loading

Diff for: ch01/images/01_06.png

504 KB
Loading

Diff for: ch01/images/01_07.png

3.21 MB
Loading

Diff for: ch01/images/01_08.png

1.38 MB
Loading

Diff for: ch01/images/01_09.png

1.87 MB
Loading

Diff for: ch01/images/ipynb_ex1.png

71.5 KB
Loading

Diff for: ch01/images/ipynb_ex2.png

22.8 KB
Loading

0 commit comments

Comments
 (0)