LoginSignup
54

More than 5 years have passed since last update.

StanとRでベイズ統計モデリング(アヒル本)をPythonにしてみる - 目次

Last updated at Posted at 2018-08-16

すでにいくつか記事はありますが、StanとRでベイズ統計モデリングをPythonにしてみました。手元では全て変換し終わっているので、見直してから順次上げていきます。最後のほうの章でstatsmodelsのlowessが2次元に対応していないっぽいのでrpy2からRカーネルにアクセスするという方法でかろうじてFull Pythonを保って(?)います。

実行環境

Jupyter on Docker

実行時にworkspaceにホスト側のファイルをマウントしています。
データは'data'、Stanのコードは'stan'に置いていますので、試してみる場合は筆者のGithubページからダウンロードしてきて適当に置いてください。
書籍の実行結果とは異なる部分もありますが、RStanとPyStanの実装の違いかと思います。(こちらの手違いでしたら教えてください)

Dockerfile
FROM ubuntu:16.04
RUN apt update && apt upgrade -qy
RUN apt install -qy language-pack-ja
ENV LANG "ja_JP.UTF-8"

RUN apt install -qy python3=3.5.1-3
RUN apt install -qy python3-pip=8.1.1-2ubuntu0.4
RUN pip3 install --upgrade pip

RUN pip3 install pystan==2.17.1.0

RUN pip3 install scipy==1.1.0
RUN pip3 install statsmodels==0.9.0
RUN pip3 install scikit-learn==0.19.2
RUN pip3 install pandas==0.23.3
RUN pip3 install jupyter==1.0.0 \
    && jupyter notebook --generate-config \
    && sed -i -e "s/#c.NotebookApp.token = '<generated>'/c.NotebookApp.token = 'jupyter'/" /root/.jupyter/jupyter_notebook_config.py
RUN pip3 install jupyter_contrib_nbextensions==0.5.0 \
    && jupyter contrib nbextension install \
    && jupyter nbextension enable codefolding/main \
    && jupyter nbextension enable collapsible_headings/main \
    && jupyter nbextension enable exercise2/main \
    && jupyter nbextension enable hide_input/main \
    && jupyter nbextension enable hinterland/hinterland \
    && jupyter nbextension enable toc2/main \
    && jupyter nbextension enable varInspector/main
RUN jupyter notebook --allow-root --no-browser --ip=0.0.0.0 &
RUN cd /root/.jupyter/nbconfig \
    && sed -i "2i   \"hinterland\": {\n    \"hint_delay\": \"500\"\n  }," ./notebook.json \
    && sed -i "2i   \"toc2\": {\n    \"toc_window_display\": true,\n    \"oc_window_display\": true,\n    \"skip_h1_title\": true\n  }," ./notebook.json
RUN pip3 install matplotlib==2.2.2
RUN pip3 install seaborn==0.9.0
RUN pip3 install bokeh==0.13.0
RUN pip3 install Pillow==5.2.0
RUN pip3 install opencv-python==3.4.2.17
RUN pip3 install japanmap==0.0.12

RUN echo "deb https://cloud.r-project.org/bin/linux/ubuntu xenial/" >> /etc/apt/sources.list \
    && apt install -y apt-transport-https \
    && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9 \
    && apt update \
    && apt install -y r-base=3.4.4-1xenial0
RUN pip3 install rpy2==2.9.4
RUN pip3 install tzlocal==1.5.1

RUN apt clean
RUN rm -rf /var/lib/apt/lists/*

VOLUME /root/workspace
WORKDIR /root/workspace

一覧

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
54