PyData Osaka
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 2022/8/27 PyData Osaka #25 ミートアップ (MLFlow+Optuna+Catboostでハイパラ探索の記録) ###### tags: `Meetup` HackMDは共同でリアルタイムにMarkdownで編集が可能なWikiのようなものです。何か質問・メモなどありましたらご自由に書き込んでいただければと思います。 上部のペンや目の形などのアイコンをクリックすることで編集モード・編集&閲覧モード・閲覧モードを切り替え可能です。 最下部右側のあたりからキーバインドを変更することも可能です。 ## PyData Osakaの紹介 PyData Osakaのウェブサイト https://osaka.pydata.org/ スライドへのリンク https://docs.google.com/presentation/d/1rjxxqk91ji09stdaOlS9Cf6OPu7v2XUZ13e58FpX1oc/edit?usp=sharing ## Zoom について 気軽に音声、ビデオオンオフしていただいて問題ありません。 音声質問してくださっても問題ありません。 ## よしおかさん講義的なもののメモ ### 自己紹介 * Laboro aiという会社で1月からエンジニアリング部長 * 本日はMLFlow, CatBoostとOptunaを使ったハイパーパラメータのチューニングについて話す * 機械学習はずっとやってきているが強化学習をメインでやってきた ### 今回の情報 * PyData Osakaのリポジトリのlearn-mlflowに存在 * https://github.com/PyDataOsaka/learn-mlflow * スライドも中に存在している * cloneしたリポジトリの learn-mlflow/notebook/optuna/MARP.md * https://github.com/PyDataOsaka/learn-mlflow/blob/main/notebook/optuna/MARP.md * vscodeにmarpのプラグインを入れることでスライド表示になる ### 環境構築 * 発表と並行して先に行っておく * 環境構築方法はhttps://github.com/PyDataOsaka/learn-mlflow のREADME.mdに記載がある * pyenvを使って入れたpython 3.9.0を使う * (注;大橋)pyenvはwindowsだと使えないので代わりにpyenv-winを入れるか、あるいはpyコマンドを使って実際に実行するpythonを切り分けるといった必要が生じると思います * https://www.python.jp/install/windows/py_launcher.html * M1/M2 MacだとOPENBLASをbrewで入れたものにする必要がある * pyenv install 3.9.0は割と時間がかかる * `source venv/bin/activate` は Windows の場合 `source venv\Scripts\activate.bat` になるかもです。 * Windows + mambaforge 環境だと下記のようなエラーに遭遇 ``` (venv) (base) C:\Users\hoge\Documents\GitHub\learn-mlflow>pip install --upgrade pip Requirement already satisfied: pip in c:\users\hoge\venv\lib\site-packages (22.0.4) Collecting pip Downloading pip-22.2.2-py3-none-any.whl (2.0 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.0/2.0 MB 1.3 MB/s eta 0:00:00 Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 22.0.4 Uninstalling pip-22.0.4: Successfully uninstalled pip-22.0.4 ERROR: Could not install packages due to an OSError: [WinError 5] アクセスが拒否されました。: 'C:\\Users\\hoge\\AppData\\Local\\Temp\\pip-uninstall-e0am5rq1\\pip.exe' Check the permissions. * mambaforge (== condaforge) 環境は `learn-mlflow` 用には適してないかもしれない。poetry installで下記が出るかも。 ![](https://i.imgur.com/s4ida5d.png) * mamba/conda を使いたい場合は、必要なパッケージは基本的にpipではなくmamba/condaを使ってinstallした方がいいのかも。 * Windows で `learn-mlflow` を実行したい方は WSL2 環境内の Ubuntu あたりがいいかもです。 ``` * 手順4でpoetryが存在していない場合はpip install poetryが必要 * macOS環境、Homebrew環境で`openblas`をインストールしていない場合は`brew install openblas`が必要 ### スライド https://github.com/PyDataOsaka/learn-mlflow/blob/main/notebook/optuna/MARP.md ### 目標 * ハイパーパラメータ探索結果の可視化 * MLflow Trackingによる実験管理 ### 構成要素の説明 * Titanicデータセット * タイタニック号沈没事故での搭乗者の属性の記録 * 元々UCLのデータリポジトリにあったが、今回はseabornのAPIを用いて取得 ### 前処理 * dfはpandasのDataFrameのインスタンス * ceはcategorical encoder * pipelineの前処理として使用(後述) ### sklearnのpipeline * 通常のsklearnのモデルと同じAPIで扱うことが可能 * `Pipeline([('名前', model), ('名前', model)])` * pipelineの実行でmodelが順番に実行される * 前処理をpipelineに挿入可能とするためには`transform()`と`fit_transform()`を定義したクラスを準備 ### CatBoost * アルゴリズムに興味がある場合はarxivの論文を読む * XGBoostなどと比較しても良い性能を示すことが載っている * 特徴 * パラメータチューニングなしで良い性能 * カテゴリカル特徴量をサポート(ライブラリ名の由来) * 高速かつスケーラブルなGPUバージョン * 正確 * 高速な予測 * 使う分に数式を理解する必要はない * 他のscikit learnのモジュールと同じように使用することが可能(インスタンスを生成してfitを呼ぶ) * ハイパーパラメータ * depth, learning_rate, random_strength, l2_leaf_reg * チューニングしてもあまり性能が今回は変わらなかった(後ほど見る) ### optuna * PFNが開発しているOSSのハイパーパラメータ自動最適化フレームワーク * 以下のインタフェースを提供 * `optuna.Trial`ハイパーパラメータの分布を定義 * 目的関数 - `optuna.Trial`を引数にとり目的値を出力する関数 * `optuna.study.study.optimize()` * 目的関数を最適化 * 探索範囲の定義 * ベイズ最適化なのでpriorを定義 * objective関数は`optuna.Trial`を引数に取り、内部でパイプラインを実行しスコアを計算 * `optuna.study.Study`オブジェクトを生成しoptimize()の実行で最適化 ### MLflow * 4つのコンポーネントから構成 * MLflow Tracking -実験管理 * 最も手軽に使いやすい * MLflow Projcects 再現可能なコード * MLflow Models MLモデルの多様な環境へのデプロイ * MLflow Model Registry MLモデルリポジトリ ### MLflow Tracking * 実験をrunという単位で管理 --- ### 15時まで休憩 --- ### 考え方の共有 - optuna と scikit-learnの\*scoring の違いって何だろう ? - optuna の方が端的に言ってかしこい - optuna があったら mlflow って要るのかな? - 実はoptunaにもパラメータに対するメトリクスの可視化機能とかはあると思う - けど今回はよく用いられているmlflowを試したかったので上記機能をmlflowに担当させた形になる

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully