Open4

VS CodeでJupyterLabのノートブック拡張子を編集するための準備

Tremendous1192Tremendous1192

インストール

  1. Cドライブ直下に使用するPythonバージョンのフォルダを作成する.(例C:\Python311)
  2. Download Python | Python.org から開発環境をインストールする.
  3. インストーラーを起動して,custom installから使用するPythonバージョンのフォルダにPython環境をインストールする.
  4. 2つのシステム環境変数を設定する(C:\Python311C:\Python311\Scripts).
  5. VS Code のExtention で PythonJupyter , Jupyter Notebook Renderersの拡張機能をインストールする
  6. Terminalでpython -m ensurepip --default-pipを入力して、pipを有効にする。
  7. Terminalでpython.exe -m pip install --upgrade pipを入力して、pipを更新する。

2024/3/27 手順の粒度を動作毎まで細かくした.

Tremendous1192Tremendous1192

ファイル作成

  1. ファイル名.ipynbでファイルを作成する
  2. Python環境を設定する。
  • 右上のPython/Mu(省略)をクリック
  • Select Another Kernelをクリック
  • Python Environmentをクリック
  • インストールしたPythonのバージョンを選択する

Tremendous1192Tremendous1192

PyMCを使用する

Miniconda環境をインストールする

  1. Cドライブ直下に使用するMinicondaのフォルダを作成する.(例C:\miniconda3)
  2. Miniconda — Anaconda documentationをダウンロードする
  3. Install for -- の画面でAll Usersを選択する.
  4. ダウンロードするフォルダ(C:\miniconda3)を選択する.
  5. システム環境変数のPATHC:\miniconda3\Scriptsを追加する.
  6. VS CodeのTerminalでcondaを実行する.
  7. Command PaletteTerminal: Select Default Shellを選び,Command Promptを選択する.

仮想環境を構築する

  1. Terminalでconda create -c conda-forge -n pymc_env "pymc>=5" python=3.11を実行して仮想環境を作成する.
  2. conda activate pymc_envを実行して仮想環境に移る.
  3. 必要なライブラリをインストールする
  • conda install -c conda-forge ipykernel: VS Code
  • conda install -c conda-forge nutpie: サンプラー
  • conda install -c conda-forge seaborn: グラフ
  • pip install japanize-matplotlib: 日本語フォント
  • conda install -c conda-forge polars: DataFrame
  • conda install -c conda-forge scikit-Learn: 機械学習モデル
  • conda install -c conda-forge watermark: 使用ライブラリ表示
  • conda install -c conda-forge prettytable: 視認性の高いprint
  • conda install -c conda-forge optuna: ハイパーパラメータ最適化
    • SQLite Viewer のVS Code拡張機能をインストールする

必要に応じて下記ライブラリをインストールする.

  • 機械学習
    • conda install -c conda-forge lightgbm: 高性能推定器
    • conda install -c conda-forge darts: 時系列分析パッケージ
    • conda install -c conda-forge xgboost: 高性能推定器
  • 深層学習
    • pip install torch: PyTorch
    • conda install -c conda-forge jax:TensorFlow関連
  • optunaの可視化
    • conda install -c conda-forge plotly: optunaの結果可視化
    • conda install -c conda-forge nbformat: optunaの結果可視化
  • MCMC関係
    • conda install numpyro: サンプラー
    • conda install -c conda-forge bambi: statsmodelsのようなformula
  • 古典統計
    • conda install -c conda-forge statsmodels
    • conda install -c conda-forge fastcluster
    • conda install -c conda-forge patsy: formulaの読み取り
  • .RDataファイルの読込み
    • conda install -c conda-forge rdata
  • 祝日
    • conda install -c conda-forge holidays: 祝日
    • pip install jpholiday: 日本の祝日
  • Excel操作
    • conda install -c conda-forge openpyxl
  • JITコンパイラ
    • conda install -c conda-forge numba
  • グラフ
    • conda install -c conda-forge hvplot
      • conda install -c conda-forge jupyter_bokeh: 等高線
      • conda install -c conda-forge cartopy geoviews pyproj: 地図への等高線オーバーラップ
    • conda install -c conda-forge yellowbrick
      • conda install -c conda-forge pooch: サンプルデータ
    • conda install -c conda-forge ipywidgets: インタラクティブなグラフ
  • 欠測値可視化
    • conda install -c conda-forge missingno

Jupyter NotebookのPython環境を指定する

.ipynbファイルの右上の環境設定をクリックしてCommand PaletteSelect Another Kernelから仮想環境を指定する.

参考

Tremendous1192Tremendous1192

個人的データサイエンス環境

  1. 仮想環境の作成: conda create -n ds_env
  2. 仮想環境へ移動: conda activate ds_env
  3. ライブラリのインストール:
  • conda install -c conda-forge ipykernel
  • conda install -c conda-forge numpy
  • conda install -c conda-forge pandas
  • conda install -c conda-forge polars
  • conda install -c conda-forge matplotlib
  • pip install japanize-matplotlib
  • conda install -c conda-forge seaborn
  • conda install -c conda-forge plotly
  • conda install -c conda-forge scikit-Learn
  • conda install -c conda-forge scipy
  • conda install -c conda-forge statsmodels
  • conda install -c conda-forge rdata:.RDataファイルを読み込む
  • conda install -c conda-forge watermark: 使用したライブラリ一覧を表示する.
  • conda install -c conda-forge pyarrow

便利なcommand

  • 環境一覧: conda info -e
  • 移行: conda activate [仮想環境名]
  • 離脱: conda deactivate

参考