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

実行環境

Jupyter on Docker

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

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

一覧

    • 4.4 単回帰

 

    • Chapter 4 練習問題

 

    • 5.1 重回帰

 

    • 5.2 二項ロジスティック回帰

 

    • 5.3 ロジスティック回帰

 

    • Chapter 5 練習問題

 

    • Chapter 6 練習問題

 

    • 7.2 対数をとるか否か

 

    • 7.3 非線形の関係

 

    • 7.5 交絡

 

    • 7.8 打ち切り

 

    • 7.9 外れ値

 

    • 8.1 階層モデルの導入

 

    • 8.2 複数の階層を持つ階層モデル

 

    • 8.3 非線形モデルの階層モデル

 

    • 8.4 ロジスティック回帰の階層モデル

 

    • Chapter 8 練習問題

 

    • 10.1 パラメータの識別可能性

 

    • 10.2 弱情報事前分布

 

    • 10.3 再パラメータ化

 

    • 11.2 混合正規分布

 

    • 11.3 ゼロ過剰ポアソン分布

 

    • 11.4 Latent_Dirichlet_Allocation

 

    • 12.1 状態空間モデルことはじめ

 

    • 12.2-季節調整項

 

    • 12.3 変化点検出

 

    • 12.6 1次元の空間構造

 

    • 12.7 2次元の空間構造

 

    • 12.8 地図を使った空間構造

 

    Chapter 12 練習問題
广告
将在 10 秒后关闭
bannerAds