sklearn

pipeline

  • sklearnのpipelineに自分で定義した関数を流し込む - Qiita

    • https://qiita.com/kazetof/items/fcfabfc3d737a8ff8668

data

  • train_test_splitのindex番号を記憶する方法

    • 引数indicesにindex番号を指定すればOK

X_train, X_test, Y_train, Y_test, indices_train, indices_test = train_test_split(X, Y, indices, test_size=0.33)
  • 参考

    • https://qiita.com/haru1977/items/7aaf1eaeb0747fe613be

マルチラベルをバイナリエンコード

category encodersで対応できないので、scikit-learniでやる必要がある。

一つのセルに対して複数データがセットある状態が入力。

import pandas as pd
df = pd.DataFrame(
    {"col1": [["aaa","bbb","ccc"], ["aaa"],["ccc","ddd"]]}
)
df

これを以下のコードでバイナリエンコード可能

StratifiedKFold

cross-validationで層分割する際に使用。戻ってくるのはindexのみ。

DataFrameを使う場合、このindexはpandasのindexではないので注意が必要。なのでilocでアクセスしないとハマる。

Last updated