0
1

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 3 years have passed since last update.

カテゴリカル変数の変換

Last updated at Posted at 2021-03-15

初めに

  • 機械学習に,カテゴリカル変数(男/女,新宿/原宿/渋谷 みたいな人間にか分からないようにラベルが貼られているもの)を学習させる時には,ダミー変数化(0/1,0/1/2)をする必要がある

方法

pandasのpd.get_dummiesを使う

predict_data = pd.get_dummies(predict_data)

      新宿/原宿/渋谷
ラベル:新宿  1 0 0
ラベル:原宿  0 1 0
ラベル:渋谷  0 0 1

みたいに行列を使って返してくれる(後で綺麗に書き直します・・・・)

疑問

新宿/原宿/渋谷 → 0/1/2
と変換する方法との精度の差がが気になる
(正規化しないで済むから行列の方が良い vs 説明変数は少ない方が良い)

後で時間があったらやってみます

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?