scikit-learnをインストールする

AI

専用の仮想環境を作成

Anacondaの環境にscikit-learnの環境を構築します。
まず「scikit-learn」専用の仮想環境を作りましょう。
左メニューの[Environments]を選択します。

仮想環境一覧の下の[Create]をクリックします。

仮想環境の名前を入力して[Create]をクリックします。

仮想環境が作成されます。
作ったばかりの環境にはこれしかインストールされているものがありません。

scikit-learnをインストール

それではさっそくscikit-learnをインストールしてみます。
▶️ボタンをクリックしてクリックして[Open Terminal]でターミナルを起動します。

Anaconda環境へのインストールには、conda コマンドを使います。以下のコマンドを入力しましょう。

$ conda install scikit-learn

以下のモジュールがインストールされます。

## Package Plan ##

  environment location: /Users/kenichioshiki/opt/anaconda3/envs/scikit-learn

  added / updated specs:
    - scikit-learn


The following NEW packages will be INSTALLED:

  appdirs            pkgs/main/noarch::appdirs-1.4.4-pyhd3eb1b0_0 None
  blas               pkgs/main/osx-64::blas-1.0-mkl None
  brotlipy           pkgs/main/osx-64::brotlipy-0.7.0-py39h9ed2024_1003 None
  certifi            pkgs/main/osx-64::certifi-2022.12.7-py39hecd8cb5_0 None
  cffi               pkgs/main/osx-64::cffi-1.15.1-py39h6c40b1e_3 None
  charset-normalizer pkgs/main/noarch::charset-normalizer-2.0.4-pyhd3eb1b0_0 None
  cryptography       pkgs/main/osx-64::cryptography-39.0.1-py39hf6deb26_0 None
  idna               pkgs/main/osx-64::idna-3.4-py39hecd8cb5_0 None
  intel-openmp       pkgs/main/osx-64::intel-openmp-2021.4.0-hecd8cb5_3538 None
  joblib             pkgs/main/osx-64::joblib-1.1.1-py39hecd8cb5_0 None
  libgfortran        pkgs/main/osx-64::libgfortran-5.0.0-11_3_0_hecd8cb5_28 None
  libgfortran5       pkgs/main/osx-64::libgfortran5-11.3.0-h9dfd629_28 None
  llvm-openmp        pkgs/main/osx-64::llvm-openmp-14.0.6-h0dcd299_0 None
  mkl                pkgs/main/osx-64::mkl-2021.4.0-hecd8cb5_637 None
  mkl-service        pkgs/main/osx-64::mkl-service-2.4.0-py39h9ed2024_0 None
  mkl_fft            pkgs/main/osx-64::mkl_fft-1.3.1-py39h4ab4a9b_0 None
  mkl_random         pkgs/main/osx-64::mkl_random-1.2.2-py39hb2f4e1b_0 None
  numpy              pkgs/main/osx-64::numpy-1.24.3-py39he696674_0 None
  numpy-base         pkgs/main/osx-64::numpy-base-1.24.3-py39h9cd3388_0 None
  packaging          pkgs/main/osx-64::packaging-23.0-py39hecd8cb5_0 None
  pooch              pkgs/main/noarch::pooch-1.4.0-pyhd3eb1b0_0 None
  pycparser          pkgs/main/noarch::pycparser-2.21-pyhd3eb1b0_0 None
  pyopenssl          pkgs/main/osx-64::pyopenssl-23.0.0-py39hecd8cb5_0 None
  pysocks            pkgs/main/osx-64::pysocks-1.7.1-py39hecd8cb5_0 None
  requests           pkgs/main/osx-64::requests-2.29.0-py39hecd8cb5_0 None
  scikit-learn       pkgs/main/osx-64::scikit-learn-1.2.2-py39hcec6c5f_0 None
  scipy              pkgs/main/osx-64::scipy-1.10.0-py39h91c6ef4_1 None
  six                pkgs/main/noarch::six-1.16.0-pyhd3eb1b0_1 None
  threadpoolctl      pkgs/main/noarch::threadpoolctl-2.2.0-pyh0d69192_0 None
  urllib3            pkgs/main/osx-64::urllib3-1.26.15-py39hecd8cb5_0 None


Proceed ([y]/n)?

確認で「y」を入力します。

Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: / 

    Installed package of scikit-learn can be accelerated using scikit-learn-intelex.
    More details are available here: https://intel.github.io/scikit-learn-intelex

    For example:

        $ conda install scikit-learn-intelex
        $ python -m sklearnex my_application.py

    

done
Retrieving notices: ...working... done
(scikit-learn) ~ $

scikit-learn のインストールが完了しました。

jupyter notebookをインストール

jupyter notebookも使いたいので入れておきます。
以下のコマンドでインストールします

$ conda install jupyter

同様に依存関係にあるものをインストールしてくれます。
確認で「y」を選択します。

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    notebook-6.5.4             |   py39hecd8cb5_0         538 KB
    ------------------------------------------------------------
                                           Total:         538 KB

The following NEW packages will be INSTALLED:

  anyio              pkgs/main/osx-64::anyio-3.5.0-py39hecd8cb5_0 None
  appnope            pkgs/main/osx-64::appnope-0.1.2-py39hecd8cb5_1001 None
  argon2-cffi        pkgs/main/noarch::argon2-cffi-21.3.0-pyhd3eb1b0_0 None
  argon2-cffi-bindi~ pkgs/main/osx-64::argon2-cffi-bindings-21.2.0-py39hca72f7f_0 None
  asttokens          pkgs/main/noarch::asttokens-2.0.5-pyhd3eb1b0_0 None
  attrs              pkgs/main/osx-64::attrs-22.1.0-py39hecd8cb5_0 None
  babel              pkgs/main/osx-64::babel-2.11.0-py39hecd8cb5_0 None
  backcall           pkgs/main/noarch::backcall-0.2.0-pyhd3eb1b0_0 None
  beautifulsoup4     pkgs/main/osx-64::beautifulsoup4-4.12.2-py39hecd8cb5_0 None
  bleach             pkgs/main/noarch::bleach-4.1.0-pyhd3eb1b0_0 None
  comm               pkgs/main/osx-64::comm-0.1.2-py39hecd8cb5_0 None
  debugpy            pkgs/main/osx-64::debugpy-1.5.1-py39he9d5cce_0 None
  decorator          pkgs/main/noarch::decorator-5.1.1-pyhd3eb1b0_0 None
  defusedxml         pkgs/main/noarch::defusedxml-0.7.1-pyhd3eb1b0_0 None
  entrypoints        pkgs/main/osx-64::entrypoints-0.4-py39hecd8cb5_0 None
  executing          pkgs/main/noarch::executing-0.8.3-pyhd3eb1b0_0 None
  gettext            pkgs/main/osx-64::gettext-0.21.0-he85b6c0_1 None
  giflib             pkgs/main/osx-64::giflib-5.2.1-h6c40b1e_3 None
  glib               pkgs/main/osx-64::glib-2.69.1-hfff2838_2 None
  gst-plugins-base   pkgs/main/osx-64::gst-plugins-base-1.14.1-hcec6c5f_1 None
  gstreamer          pkgs/main/osx-64::gstreamer-1.14.1-h6c40b1e_1 None
  icu                pkgs/main/osx-64::icu-58.2-h0a44026_3 None
  importlib-metadata pkgs/main/osx-64::importlib-metadata-6.0.0-py39hecd8cb5_0 None
  importlib_metadata pkgs/main/noarch::importlib_metadata-6.0.0-hd3eb1b0_0 None
  ipykernel          pkgs/main/osx-64::ipykernel-6.19.2-py39h01d92e1_0 None
  ipython            pkgs/main/osx-64::ipython-8.12.0-py39hecd8cb5_0 None
  ipython_genutils   pkgs/main/noarch::ipython_genutils-0.2.0-pyhd3eb1b0_1 None
  ipywidgets         pkgs/main/osx-64::ipywidgets-8.0.4-py39hecd8cb5_0 None
  jedi               pkgs/main/osx-64::jedi-0.18.1-py39hecd8cb5_1 None
  jinja2             pkgs/main/osx-64::jinja2-3.1.2-py39hecd8cb5_0 None
  jpeg               pkgs/main/osx-64::jpeg-9e-h6c40b1e_1 None
  json5              pkgs/main/noarch::json5-0.9.6-pyhd3eb1b0_0 None
  jsonschema         pkgs/main/osx-64::jsonschema-4.17.3-py39hecd8cb5_0 None
  jupyter            pkgs/main/osx-64::jupyter-1.0.0-py39hecd8cb5_8 None
  jupyter_client     pkgs/main/osx-64::jupyter_client-8.1.0-py39hecd8cb5_0 None
  jupyter_console    pkgs/main/osx-64::jupyter_console-6.6.3-py39hecd8cb5_0 None
  jupyter_core       pkgs/main/osx-64::jupyter_core-5.3.0-py39hecd8cb5_0 None
  jupyter_server     pkgs/main/osx-64::jupyter_server-1.23.4-py39hecd8cb5_0 None
  jupyterlab         pkgs/main/osx-64::jupyterlab-3.5.3-py39hecd8cb5_0 None
  jupyterlab_pygmen~ pkgs/main/noarch::jupyterlab_pygments-0.1.2-py_0 None
  jupyterlab_server  pkgs/main/osx-64::jupyterlab_server-2.22.0-py39hecd8cb5_0 None
  jupyterlab_widgets pkgs/main/osx-64::jupyterlab_widgets-3.0.5-py39hecd8cb5_0 None
  krb5               pkgs/main/osx-64::krb5-1.19.4-hdba6334_0 None
  lerc               pkgs/main/osx-64::lerc-3.0-he9d5cce_0 None
  libclang           pkgs/main/osx-64::libclang-14.0.6-default_hd95374b_1 None
  libclang13         pkgs/main/osx-64::libclang13-14.0.6-default_habbcc1a_1 None
  libdeflate         pkgs/main/osx-64::libdeflate-1.17-hb664fd8_0 None
  libedit            pkgs/main/osx-64::libedit-3.1.20221030-h6c40b1e_0 None
  libiconv           pkgs/main/osx-64::libiconv-1.16-hca72f7f_2 None
  libllvm14          pkgs/main/osx-64::libllvm14-14.0.6-h91fad77_2 None
  libpng             pkgs/main/osx-64::libpng-1.6.39-h6c40b1e_0 None
  libpq              pkgs/main/osx-64::libpq-12.9-h1c9f633_3 None
  libsodium          pkgs/main/osx-64::libsodium-1.0.18-h1de35cc_0 None
  libtiff            pkgs/main/osx-64::libtiff-4.5.0-hcec6c5f_2 None
  libwebp            pkgs/main/osx-64::libwebp-1.2.4-hf6ce154_1 None
  libwebp-base       pkgs/main/osx-64::libwebp-base-1.2.4-h6c40b1e_1 None
  libxml2            pkgs/main/osx-64::libxml2-2.10.3-h930c0e2_0 None
  libxslt            pkgs/main/osx-64::libxslt-1.1.37-h6d1eb0e_0 None
  lxml               pkgs/main/osx-64::lxml-4.9.2-py39h6c40b1e_0 None
  lz4-c              pkgs/main/osx-64::lz4-c-1.9.4-hcec6c5f_0 None
  markupsafe         pkgs/main/osx-64::markupsafe-2.1.1-py39hca72f7f_0 None
  matplotlib-inline  pkgs/main/osx-64::matplotlib-inline-0.1.6-py39hecd8cb5_0 None
  mistune            pkgs/main/osx-64::mistune-0.8.4-py39h9ed2024_1000 None
  nbclassic          pkgs/main/osx-64::nbclassic-0.5.5-py39hecd8cb5_0 None
  nbclient           pkgs/main/osx-64::nbclient-0.5.13-py39hecd8cb5_0 None
  nbconvert          pkgs/main/osx-64::nbconvert-6.5.4-py39hecd8cb5_0 None
  nbformat           pkgs/main/osx-64::nbformat-5.7.0-py39hecd8cb5_0 None
  nest-asyncio       pkgs/main/osx-64::nest-asyncio-1.5.6-py39hecd8cb5_0 None
  notebook           pkgs/main/osx-64::notebook-6.5.4-py39hecd8cb5_0 None
  notebook-shim      pkgs/main/osx-64::notebook-shim-0.2.2-py39hecd8cb5_0 None
  nspr               pkgs/main/osx-64::nspr-4.33-he9d5cce_0 None
  nss                pkgs/main/osx-64::nss-3.74-h47edf6a_0 None
  pandocfilters      pkgs/main/noarch::pandocfilters-1.5.0-pyhd3eb1b0_0 None
  parso              pkgs/main/noarch::parso-0.8.3-pyhd3eb1b0_0 None
  pcre               pkgs/main/osx-64::pcre-8.45-h23ab428_0 None
  pexpect            pkgs/main/noarch::pexpect-4.8.0-pyhd3eb1b0_3 None
  pickleshare        pkgs/main/noarch::pickleshare-0.7.5-pyhd3eb1b0_1003 None
  platformdirs       pkgs/main/osx-64::platformdirs-2.5.2-py39hecd8cb5_0 None
  ply                pkgs/main/osx-64::ply-3.11-py39hecd8cb5_0 None
  prometheus_client  pkgs/main/osx-64::prometheus_client-0.14.1-py39hecd8cb5_0 None
  prompt-toolkit     pkgs/main/osx-64::prompt-toolkit-3.0.36-py39hecd8cb5_0 None
  prompt_toolkit     pkgs/main/noarch::prompt_toolkit-3.0.36-hd3eb1b0_0 None
  psutil             pkgs/main/osx-64::psutil-5.9.0-py39hca72f7f_0 None
  ptyprocess         pkgs/main/noarch::ptyprocess-0.7.0-pyhd3eb1b0_2 None
  pure_eval          pkgs/main/noarch::pure_eval-0.2.2-pyhd3eb1b0_0 None
  pygments           pkgs/main/noarch::pygments-2.11.2-pyhd3eb1b0_0 None
  pyqt               pkgs/main/osx-64::pyqt-5.15.7-py39he9d5cce_0 None
  pyqt5-sip          pkgs/main/osx-64::pyqt5-sip-12.11.0-py39he9d5cce_0 None
  pyrsistent         pkgs/main/osx-64::pyrsistent-0.18.0-py39hca72f7f_0 None
  python-dateutil    pkgs/main/noarch::python-dateutil-2.8.2-pyhd3eb1b0_0 None
  python-fastjsonsc~ pkgs/main/osx-64::python-fastjsonschema-2.16.2-py39hecd8cb5_0 None
  pytz               pkgs/main/osx-64::pytz-2022.7-py39hecd8cb5_0 None
  pyzmq              pkgs/main/osx-64::pyzmq-23.2.0-py39he9d5cce_0 None
  qt-main            pkgs/main/osx-64::qt-main-5.15.2-h51e0635_8 None
  qt-webengine       pkgs/main/osx-64::qt-webengine-5.15.9-h90a370e_4 None
  qtconsole          pkgs/main/osx-64::qtconsole-5.4.2-py39hecd8cb5_0 None
  qtpy               pkgs/main/osx-64::qtpy-2.2.0-py39hecd8cb5_0 None
  qtwebkit           pkgs/main/osx-64::qtwebkit-5.212-hbfab81c_5 None
  send2trash         pkgs/main/noarch::send2trash-1.8.0-pyhd3eb1b0_1 None
  sip                pkgs/main/osx-64::sip-6.6.2-py39he9d5cce_0 None
  sniffio            pkgs/main/osx-64::sniffio-1.2.0-py39hecd8cb5_1 None
  soupsieve          pkgs/main/osx-64::soupsieve-2.4-py39hecd8cb5_0 None
  stack_data         pkgs/main/noarch::stack_data-0.2.0-pyhd3eb1b0_0 None
  terminado          pkgs/main/osx-64::terminado-0.17.1-py39hecd8cb5_0 None
  tinycss2           pkgs/main/osx-64::tinycss2-1.2.1-py39hecd8cb5_0 None
  toml               pkgs/main/noarch::toml-0.10.2-pyhd3eb1b0_0 None
  tomli              pkgs/main/osx-64::tomli-2.0.1-py39hecd8cb5_0 None
  tornado            pkgs/main/osx-64::tornado-6.2-py39hca72f7f_0 None
  traitlets          pkgs/main/osx-64::traitlets-5.7.1-py39hecd8cb5_0 None
  typing-extensions  pkgs/main/osx-64::typing-extensions-4.5.0-py39hecd8cb5_0 None
  typing_extensions  pkgs/main/osx-64::typing_extensions-4.5.0-py39hecd8cb5_0 None
  wcwidth            pkgs/main/noarch::wcwidth-0.2.5-pyhd3eb1b0_0 None
  webencodings       pkgs/main/osx-64::webencodings-0.5.1-py39hecd8cb5_1 None
  websocket-client   pkgs/main/osx-64::websocket-client-0.58.0-py39hecd8cb5_4 None
  widgetsnbextension pkgs/main/osx-64::widgetsnbextension-4.0.5-py39hecd8cb5_0 None
  zeromq             pkgs/main/osx-64::zeromq-4.3.4-h23ab428_0 None
  zipp               pkgs/main/osx-64::zipp-3.11.0-py39hecd8cb5_0 None
  zstd               pkgs/main/osx-64::zstd-1.5.5-hc035e20_0 None


Proceed ([y]/n)? y

インストールが完了しました。

Downloading and Extracting Packages
notebook-6.5.4       | 538 KB    | ################################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Retrieving notices: ...working... done
(scikit-learn) ~ $

まとめ

解説するまでもなかったのですが、以上で Anaconda 環境へのscikit-learn のインストールの完了です。
ついでにJupyter Notebookもインストールしました。
次回は実際に scikit-learn を使ってみたいと思います。

タイトルとURLをコピーしました