scikit-learnのインストール手順
目的
- scikit-learnを動かしてみる(機械学習の学習用途)
- Dockerコンテナとして立ち上げる
環境
$ uname -srvmpio
Linux 5.8.0-59-generic #66~20.04.1-Ubuntu SMP Thu Jun 17 11:14:10 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
$ docker -v
Docker version 20.10.7, build f0df350
$ docker-compose -v
docker-compose version 1.26.0, build d4451659
コンテナ構築
ディレクトリ構造
.
├── Dockerfile
├── docker-compose.yaml
└── pyproject.toml
Dockerfile
FROM ubuntu:20.04
WORKDIR /app
# -- Set Envs
ENV DEBIAN_FRONTEND=noninteractive \
TZ=Asia/Tokyo \
LC_ALL=C.UTF-8 \
LANG=C.UTF-8
# -- Install System Lib
RUN apt-get update && \
apt-get install -y tzdata \
python3 \
python3-dev \
python3-venv \
python3-pip && \
pip3 install poetry
# -- Added workdir
COPY . /app
# -- Install dependencies
RUN poetry install
docker-compose.yaml
version: '3.7'
services:
app:
container_name: scikit-learn-container
build:
context: .
dockerfile: Dockerfile
command: ["tail", "-f", "/dev/null"]
volumes:
- .:/app
tty: true
pyproject.toml
[tool.poetry]
name = "scikit-learn-container"
version = "0.0.0"
description = ""
authors = [""]
[tool.poetry.dependencies]
python = "^3.8"
scikit-learn = "^0.24.2"
動作確認
docker-compose up -d
$ docker-compose exec app poetry show
joblib 1.0.1 Lightweight pipelining with Python functions
numpy 1.21.1 NumPy is the fundamental package for array computing with Python.
scikit-learn 0.24.2 A set of python modules for machine learning and data mining
scipy 1.6.1 SciPy: Scientific Library for Python
threadpoolctl 2.2.0 threadpoolctl
$ docker-compose exec app poetry run python3
Python 3.8.10 (default, Jun 2 2021, 10:49:15)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sklearn
>>> sklearn.__version__
'0.24.2'