リストをone-hot encodingしたいです。
今、
[0, 0, 1, 1, 2, 2, 3, 3, 4, 4]
というリストがあります。これをone-hot encodingしたいです。
[[1,0,0,0] [1,0,0,0] [0,1,0,0] [0,1,0,0] ・ ・ ・ [0,0,0,1]]
のような形にしたいです。
import numpy as np from sklearn.preprocessing import OneHotEncoder train_labels = OneHotEncoder().fit_transform(train_labels).toarray()
のようにコードを書いて実行したところ、
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
とエラーが出ました。
どのように修正したらいいのでしょうか?
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。