0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

はじめに

Signateのアップル 引越し需要予測(SOTA)にチャレンジしていて、出たエラーについてメモです。

PyCaretの time_series を使った際に、型が異なる旨のエラーが出て困った。という内容です。

具体的な内容

・時系列モデルを利用するときには、indexにdatetimeを指定するのが通常
 ※2024-06-23のような形式
・PyCaretに投入する手前で、indexにdatetime型の日付データを設定
・trainデータで、モデル作成はできる
・testデータで、予測しようとすると型が異なる旨のエラーが発生
 datetime型 vs period型

このときまで、period型なるものを知らなかったのですが、どうやらPyCaret側で処理したモデルは自動的にperiod型がindexに設定されるようです・・・。
よって、testデータのdatetime型と異なるというエラーが発生していました。

※Period型については、こちらの記事が詳しいです。

※info()を見ると、Dtypeはこんな感じです。
image.png

解決方法

train,test共に、indexのdatetime型をperiod型に変換するだけ!

train['datetime'] = pd.to_datetime(train['datetime']).dt.to_period('D')
train.set_index('datetime', inplace=True)

test['datetime'] = pd.to_datetime(test['datetime']).dt.to_period('D')
test.set_index('datetime', inplace=True)

参考:period型のindex
見た目は、datetime型かperiod型かわかりませんね・・・👹
image.png

今回は、以上です!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?