LoginSignup
1
4

More than 3 years have passed since last update.

KaggleのNotebookでAutoGluonを使ってみる

Last updated at Posted at 2021-02-26

※これは2021/02/26の記事です。指摘などありましたら気兼ねなくコメントお願いします:bow:

はじめに

以下の記事を読み、これを参考にしてKaggleのNotebookでAutoGluon(特にAutoGluon-Tabular)を使ってみようと試みたのですが、すんなりとはできませんでした。

原因として、この一年でAutoGluon自体にいくつか変更があったことなどが考えられます。また推奨される利用方法も変わったようです。そこで、そのあたりを考慮し、「KaggleのNotebookでAutoGluonを使ってみる」というところまでを実現しました。作成したNotebookの紹介と実現するまでに発生したエラー・解決方法を備忘録として残しておきます。

結論

以下のようなNotebookを作成しました:point_down:


# https://github.com/awslabs/autogluon

!pip install --upgrade pip
!pip install --upgrade setuptools
!pip install --upgrade "mxnet<2.0.0"
!pip install autogluon.tabular

import pandas as pd
from autogluon.tabular import TabularDataset, TabularPredictor

train= TabularDataset('../input/titanic/train.csv')
test = TabularDataset('../input/titanic/test.csv')

label='Survived'
time_limit=60
predictor = TabularPredictor(label=label).fit(train, time_limit=time_limit)

submission = pd.read_csv('../input/titanic/gender_submission.csv')
submission[label] = predictor.predict(test)
submission.to_csv('submission.csv', index=False)
submission.head()

Public Scoreは0.78229と算出され、望む実装ができているようです!簡単!素晴らしい!

しかし、ちょっと不安な出力も…ひとまず棚に上げます。


ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
earthengine-api 0.1.252 requires google-api-python-client>=1.12.1, but you have google-api-python-client 1.8.0 which is incompatible.

エラー&解決の備忘録

大きく以下2点を実施しました。

  • 他環境(Google Colab)での最新の成功例で試行
  • 環境依存の問題?を確認

まずは、Google Colabでの最新の成功例を試してみました。以前書いた以下2件の記事でも紹介したコードです。

これは参考記事が公開されて以降のAutoGluonの変更点を考慮したものです。モジュールなどが異なります。TabularDatasetTabularPredictorを使うためにautogluon.tabularをインポートします。このコードをすべてコピーして、実行してみたのですが以下のようなエラーが生じました。

READMEを参考にしたコマンドなのですがここに原因がありそうです。


!pip install --upgrade pip
!pip install --upgrade setuptools
!pip install --upgrade "mxnet<2.0.0"
!pip install --pre autogluon

from autogluon.tabular import TabularDataset, TabularPredictor

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-974358aaf144> in <module>
----> 1 from autogluon.tabular import TabularDataset, TabularPredictor

/opt/conda/lib/python3.7/site-packages/autogluon/tabular/__init__.py in <module>
      1 import logging
      2 
----> 3 from autogluon.core.dataset import TabularDataset
      4 from autogluon.core.features.feature_metadata import FeatureMetadata
      5 

/opt/conda/lib/python3.7/site-packages/autogluon/core/__init__.py in <module>
      4 from .decorator import *
      5 from .utils.files import *
----> 6 from .scheduler.resource.resource import *
      7 from .scheduler.scheduler import *
      8 from . import metrics

/opt/conda/lib/python3.7/site-packages/autogluon/core/scheduler/__init__.py in <module>
----> 1 from .import remote, resource
      2 from .resource import get_cpu_count, get_gpu_count
      3 
      4 # schedulers
      5 from .scheduler import *

/opt/conda/lib/python3.7/site-packages/autogluon/core/scheduler/remote/__init__.py in <module>
      1 # remotes
----> 2 from .remote import *
      3 from .ssh_helper import *
      4 from .remote_manager import *

/opt/conda/lib/python3.7/site-packages/autogluon/core/scheduler/remote/remote.py in <module>
      9 from threading import Thread
     10 import multiprocessing as mp
---> 11 from distributed import Client
     12 
     13 from .ssh_helper import start_scheduler, start_worker

/opt/conda/lib/python3.7/site-packages/distributed/__init__.py in <module>
      2 import dask
      3 from dask.config import config
----> 4 from .actor import Actor, ActorFuture
      5 from .core import connect, rpc, Status
      6 from .deploy import LocalCluster, Adaptive, SpecCluster, SSHCluster

/opt/conda/lib/python3.7/site-packages/distributed/actor.py in <module>
      4 from queue import Queue
      5 
----> 6 from .client import Future, default_client
      7 from .protocol import to_serialize
      8 from .utils import iscoroutinefunction, thread_state, sync

/opt/conda/lib/python3.7/site-packages/distributed/client.py in <module>
     41 from tornado.ioloop import IOLoop, PeriodicCallback
     42 
---> 43 from .batched import BatchedSend
     44 from .utils_comm import (
     45     WrappedKey,

/opt/conda/lib/python3.7/site-packages/distributed/batched.py in <module>
      6 from tornado.ioloop import IOLoop
      7 
----> 8 from .core import CommClosedError
      9 from .utils import parse_timedelta
     10 

/opt/conda/lib/python3.7/site-packages/distributed/core.py in <module>
     18 from tornado.ioloop import IOLoop, PeriodicCallback
     19 
---> 20 from .comm import (
     21     connect,
     22     listen,

/opt/conda/lib/python3.7/site-packages/distributed/comm/__init__.py in <module>
     24 
     25 
---> 26 _register_transports()

/opt/conda/lib/python3.7/site-packages/distributed/comm/__init__.py in _register_transports()
     16 def _register_transports():
     17     from . import inproc
---> 18     from . import tcp
     19 
     20     try:

/opt/conda/lib/python3.7/site-packages/distributed/comm/tcp.py in <module>
     15 import dask
     16 from tornado import netutil
---> 17 from tornado.iostream import StreamClosedError
     18 from tornado.tcpclient import TCPClient
     19 from tornado.tcpserver import TCPServer

/opt/conda/lib/python3.7/site-packages/tornado/iostream.py in <module>
    208 
    209 
--> 210 class BaseIOStream(object):
    211     """A utility class to write to and read from a non-blocking file or socket.
    212 

/opt/conda/lib/python3.7/site-packages/tornado/iostream.py in BaseIOStream()
    284         self._closed = False
    285 
--> 286     def fileno(self) -> Union[int, ioloop._Selectable]:
    287         """Returns the file descriptor for this stream."""
    288         raise NotImplementedError()

AttributeError: module 'tornado.ioloop' has no attribute '_Selectable'

--preを外してみます。


!pip install --upgrade pip
!pip install --upgrade setuptools
!pip install --upgrade "mxnet<2.0.0"
!pip install autogluon

from autogluon.tabular import TabularDataset, TabularPredictor

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-974358aaf144> in <module>
----> 1 from autogluon.tabular import TabularDataset, TabularPredictor

ModuleNotFoundError: No module named 'autogluon.tabular'

autogluon.tabularがないと言われていしまいました。それならとautogluonautogluon.tabularにしてみると…成功しました!最終的に、以下のような修正で解決しました。


!pip install --upgrade pip
!pip install --upgrade setuptools
!pip install --upgrade "mxnet<2.0.0"
!pip install autogluon.tabular

2021/02/26、Kaggleでは、TabularDatasetTabularPredictorを使うためにautogluonではなくautogluon.tabularをインストールする必要があるということですね。色々気になっています:thinking:

まとめ

「KaggleのNotebookでAutoGluonを使ってみる」というところまでを実現するために、作成したNotebookの紹介と、実現するまでに発生したエラー・解決方法を備忘録として記録しました。2021/02/26にした対応でしたが、今後もこのようなエラーが生じる恐れはあると思うので、あくまでも参考までにしていただけると幸いです。引き続きAutoGluonをはじめとするAutoMLをどんどん体験していきましょう!

1
4
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
1
4