LoginSignup
0
0

Kaggle Notebook Internet Offでpytorch_tabnetを使う方法 (2023年12月時点)

Last updated at Posted at 2023-12-18

はじめに

Kaggle Typingコンペ(Code competition)にてInternet offでのTabNetのインストールに困ったので解決策を残しておきます。

問題

TabNetのpackage依存関係でエラーが起きていました。
古いバージョンのTabNet (4.0以前) は要件に1.2 <= torch < 2.0を含みますが、Kaggle Notebook環境ではtorch==2.0.0となっており、以下のエラーが生じていました。

!pip install --no-index --find-links /kaggle/input/pytorch-tabnet/pytorch_tabnet-4.0-py3-none-any.whl pytorch_tabnet
from pytorch_tabnet.tab_model import TabNetRegressor
Looking in links: /kaggle/input/pytorch-tabnet/pytorch_tabnet-4.0-py3-none-any.whl
Processing /kaggle/input/pytorch-tabnet/pytorch_tabnet-4.0-py3-none-any.whl
Requirement already satisfied: numpy<2.0,>=1.17 in /opt/conda/lib/python3.10/site-packages (from pytorch_tabnet) (1.24.3)
Requirement already satisfied: scikit_learn>0.21 in /opt/conda/lib/python3.10/site-packages (from pytorch_tabnet) (1.2.2)
Requirement already satisfied: scipy>1.4 in /opt/conda/lib/python3.10/site-packages (from pytorch_tabnet) (1.11.4)
INFO: pip is looking at multiple versions of pytorch-tabnet to determine which version is compatible with other requirements. This could take a while.
ERROR: Could not find a version that satisfies the requirement torch<2.0,>=1.2 (from pytorch-tabnet) (from versions: none)
ERROR: No matching distribution found for torch<2.0,>=1.2
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[6], line 3
      1 # install TabNet
      2 get_ipython().system('pip install --no-index --find-links /kaggle/input/pytorch-tabnet/pytorch_tabnet-4.0-py3-none-any.whl pytorch_tabnet')
----> 3 from pytorch_tabnet.tab_model import TabNetRegressor

ModuleNotFoundError: No module named 'pytorch_tabnet'

環境
Python 3.10.12
pytorch-tabnet 4.0
torch 2.0.0
numpy 1.24.3
scikit_learn 1.2.2
scipy 1.11.4
tqdm 4.66.1

解決策

pywheelsにあるpytorch-tabnetの最新版wheelファイル (4.1.0) を使用するとうまくいきました。確認したところ、pytorch-tabnet version4.1.0からはtorch >= 2.0もサポートされていました。

手順

  1. TabNetのwheelファイルを下記よりダウンロード
    https://www.piwheels.org/project/pytorch-tabnet/
  2. wheelファイルをdatasetとしてアップロード
  3. pipでインストール

以下はwheelファイルを/kaggle/input/pytorch-tabnetに入れたときのコマンドです

!pip install --no-index --find-links /kaggle/input/pytorch-tabnet/pytorch_tabnet-4.1.0-py3-none-any.whl pytorch_tabnet
from pytorch_tabnet.tab_model import TabNetRegressor
Looking in links: /kaggle/input/pytorch-tabnet/pytorch_tabnet-4.1.0-py3-none-any.whl
Processing /kaggle/input/pytorch-tabnet/pytorch_tabnet-4.1.0-py3-none-any.whl
Requirement already satisfied: numpy>=1.17 in /opt/conda/lib/python3.10/site-packages (from pytorch_tabnet) (1.24.3)
Requirement already satisfied: scikit_learn>0.21 in /opt/conda/lib/python3.10/site-packages (from pytorch_tabnet) (1.2.2)
Requirement already satisfied: scipy>1.4 in /opt/conda/lib/python3.10/site-packages (from pytorch_tabnet) (1.11.4)
Requirement already satisfied: torch>=1.3 in /opt/conda/lib/python3.10/site-packages (from pytorch_tabnet) (2.0.0+cpu)
Requirement already satisfied: tqdm>=4.36 in /opt/conda/lib/python3.10/site-packages (from pytorch_tabnet) (4.66.1)
Requirement already satisfied: joblib>=1.1.1 in /opt/conda/lib/python3.10/site-packages (from scikit_learn>0.21->pytorch_tabnet) (1.3.2)
Requirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/lib/python3.10/site-packages (from scikit_learn>0.21->pytorch_tabnet) (3.2.0)
Requirement already satisfied: filelock in /opt/conda/lib/python3.10/site-packages (from torch>=1.3->pytorch_tabnet) (3.12.2)
Requirement already satisfied: typing-extensions in /opt/conda/lib/python3.10/site-packages (from torch>=1.3->pytorch_tabnet) (4.5.0)
Requirement already satisfied: sympy in /opt/conda/lib/python3.10/site-packages (from torch>=1.3->pytorch_tabnet) (1.12)
Requirement already satisfied: networkx in /opt/conda/lib/python3.10/site-packages (from torch>=1.3->pytorch_tabnet) (3.1)
Requirement already satisfied: jinja2 in /opt/conda/lib/python3.10/site-packages (from torch>=1.3->pytorch_tabnet) (3.1.2)
Requirement already satisfied: MarkupSafe>=2.0 in /opt/conda/lib/python3.10/site-packages (from jinja2->torch>=1.3->pytorch_tabnet) (2.1.3)
Requirement already satisfied: mpmath>=0.19 in /opt/conda/lib/python3.10/site-packages (from sympy->torch>=1.3->pytorch_tabnet) (1.3.0)
Installing collected packages: pytorch_tabnet
Successfully installed pytorch_tabnet-4.1.0

おわりに

バージョン管理の大切さを身をもって学びました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0