Easy to use Jupyter notebook (Python3.5)

Introduction

Jupyter notebook (Python) can be said to be the standard for scientific and technological calculations such as data analysis. Here's an easy way to get started with docker.

Install Docker Toolbox

Download the installer from the Docker Toolbox site (below) and run it. https://www.docker.com/products/docker-toolbox

Installation is not difficult, but if necessary, [Reference Link](#-% E5% 8F% 82% E8% 80% 83% E3% 83% AA% E3% 83% B3% E3% 82% AF )Please refer to.

For Linux, you can install docker as follows.

bash


wget -qO- https://get.docker.com/ | sh

Start Jupyter

When running on Linux

Please do as follows [^ 1].

[^ 1]: Both user ID and group ID are set to 1000. If it is different, please modify Dockerfile and "docker build" yourself.

bash


mkdir jupyter
docker run -it -d -p 8888:8888 -v $PWD/jupyter:/home/jupyter \
  --name jupyter tsutomu7/alpine-python:jupyter
firefox localhost:8888

If you want to exit and delete the container, do the following:

bash


docker rm -f jupyter

When running on Windows or Mac

When you install Docker Toolbox, a tool called Kitematic is installed. Start Kitematic. At the first startup, the Docker Hub login screen will be displayed, but please skip it.

When Kitematic starts, enter "tsutomu7 / alpine-python" in the search box as shown below. The search results will appear below, so click "○○○" at the bottom right. image

Click "SELECTED TAG" as shown below. image

Click "jupyter". image

Press "x" to go back. image

Press "CREATE". image

The download will start, and after a while, the container will start as shown below.

-** Click ** under "VOLUMES" and click "Enable" to leave the execution results described below on the host (Windows or Mac). -** Click ** under "WEB PREVIEW" to open a browser and use Jupyter. image

Try it

image

Graph

Type the following in a cell and hold down the Shift key and press the Enter key to execute.

jupyter


%matplotlib inline
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'IPAexGothic'
plt.plot([2,1,3], label='sample')
plt.legend();

In this way, you can draw graphs with matplotlib and you can also handle Japanese. image

optimisation

Enter the following in the cell and execute it. Solve combinatorial optimization problems Solve Sudoku / 4f919f453aae95b3834b) You can also.

jupyter


import pandas as pd, numpy as np
from more_itertools import grouper
from pulp import *

prob = """\
..6.....1
.7..6..5.
8..1.32..
..5.4.8..
.4.7.2.9.
..8.1.7..
..12.5..3
.6..7..8.
2.....4..
"""
r = range(9)
m = LpProblem() #Mathematical model
a = pd.DataFrame([(i, j, k, LpVariable('x%d%d%d'%(i,j,k), cat=LpBinary))
                  for i in r for j in r for k in r],
                 columns=['Vertical', 'side', 'number', 'x']) # (Formulation 1)
for i in r:
    for j in r:
        m += lpSum(a[(a.Vertical== i) & (a.side== j)].x) == 1 # (Formulation 2)
        m += lpSum(a[(a.Vertical== i) & (a.number== j)].x) == 1 # (Formulation 3)
        m += lpSum(a[(a.side== i) & (a.number== j)].x) == 1 # (Formulation 4)
for i in range(0, 9, 3):
    for j in range(0, 9, 3):
        for k in r:
            m += lpSum(a[(a.Vertical>= i) & (a.Vertical< i+3) & # (Formulation 5)
                         (a.side>= j) & (a.side< j+3) & (a.number== k)].x) == 1
for i, s in enumerate(prob.split('\n')):
    for j, c in enumerate(s):
        if c.isdigit():
            k = int(c)-1 # (Formulation 6)
            m += lpSum(a[(a.Vertical== i) & (a.side== j) & (a.number== k)].x) == 1
m.solve() #Solved with solver
f = a.x.apply(lambda v: value(v) == 1) #Selected numbers
print(np.array(list(grouper(9, a.number[f] + 1))))

result


[[5 3 6 8 2 7 9 4 1]
 [1 7 2 9 6 4 3 5 8]
 [8 9 4 1 5 3 2 6 7]
 [7 1 5 3 4 9 8 2 6]
 [6 4 3 7 8 2 1 9 5]
 [9 2 8 5 1 6 7 3 4]
 [4 8 1 2 9 5 6 7 3]
 [3 6 9 4 7 1 5 8 2]
 [2 5 7 6 3 8 4 1 9]]

Comparison with Jupyter Project

Jupyter notebook also has an image of Jupyter Project (jupyter / notebook), The one introduced this time has the following merits.

Feature What was introduced Jupyter Project
new Python 3.5.1 Python 3.4.3
Small size 658.5 MB 863.1 MB
Many installed packages 69 38

tsutomu7 / alpine-python: installed package of jupyter

package ver package ver package ver package ver
blist 1.3.6 bokeh 0.11.1 chest 0.2.3 cloudpickle 0.1.1
conda 4.0.5 conda-env 2.4.5 cycler 0.10.0 dask 0.8.2
decorator 4.0.9 entrypoints 0.2 flask 0.10.1 fontconfig 2.11.1
freetype 2.5.5 heapdict 1.0.0 ipykernel 4.3.1 ipython 4.1.2
ipython-genutils 0.1.0 ipython_genutils 0.1.0 ipywidgets 4.1.1 itsdangerous 0.24
jinja2 2.8 jsonschema 2.4.0 jupyter 1.0.0 jupyter-client 4.2.2
jupyter-console 4.1.1 jupyter-core 4.1.0 jupyter_client 4.2.2 jupyter_console 4.1.1
jupyter_core 4.1.0 libgfortran 3.0 libpng 1.6.17 libsodium 1.0.3
libxml2 2.9.2 locket 0.2.0 markdown 2.6.6 markupsafe 0.23
matplotlib 1.5.1 mistune 0.7.2 more-itertools 2.2 mpmath 0.19
nbconvert 4.2.0 nbformat 4.0.1 ncurses 5.9 networkx 1.11
nomkl 1.0 notebook 4.1.0 numpy 1.11.0 openblas 0.2.14
openssl 1.0.2g pandas 0.18.0 partd 0.3.2 path.py 8.2
patsy 0.4.1 pexpect 4.0.1 pickleshare 0.5 pip 8.1.1
psutil 4.1.0 ptyprocess 0.5 pulp 1.6.1 pycosat 0.6.1
pycrypto 2.6.1 pygments 2.1.3 pyjade 4.0.0 pyparsing 2.0.3
pyqt 4.11.4 python 3.5.1 python-dateutil 2.5.2 pytz 2016.3
pyyaml 3.11 pyzmq 15.2.0 qt 4.8.7 qtconsole 4.2.1
readline 6.2 requests 2.9.1 scikit-learn 0.17.1 scipy 0.17.0
seaborn 0.7.0 setuptools 20.3 simplegeneric 0.8.1 sip 4.16.9
six 1.10.0 sqlite 3.9.2 statsmodels 0.6.1 sympy 1.0
terminado 0.5 tk 8.5.18 toolz 0.7.4 tornado 4.3
traitlets 4.2.1 werkzeug 0.11.5 wheel 0.29.0 xz 5.0.5
yaml 0.1.6 zeromq 4.1.3 zlib 1.2.8

installed packages of jupyter / notebook

package ver package ver package ver package ver
backports-abc (0.4) cffi (1.5.2) cryptography (1.2.2) decorator (4.0.9)
idna (2.0) ipykernel (4.2.2) ipython (4.1.1) ipython-genutils (0.1.0)
Jinja2 (2.8) jsonschema (2.5.1) jupyter-client (4.1.1) jupyter-core (4.0.6)
MarkupSafe (0.23) mistune (0.7.1) nbconvert (4.1.0) nbformat (4.0.1)
ndg-httpsclient (0.4.0) nose (1.3.7) notebook (5.0.0.dev0) path.py (8.1.2)
pexpect (4.0.1) pickleshare (0.6) pip (8.0.2) ptyprocess (0.5.1)
pyasn1 (0.1.9) pycparser (2.14) Pygments (2.1.1) pyOpenSSL (0.15.1)
pyzmq (15.2.0) requests (2.9.1) setuptools (20.1.1) simplegeneric (0.8.1)
six (1.10.0) terminado (0.6) tornado (4.3) traitlets (4.1.0)
wheel (0.29.0) widgetsnbextension (0.0.2.dev0)

Reference link

-Install Docker Toolbox: Windows -Powerful notepad for modern engineers Jupyter notebook recommendation --ubuntu-based jupyter: tsutomu7 / jupyter (827MB)

that's all

Recommended Posts