在多类分类问题中,我可以使用python将3个类标签转换为2D数组吗?
我可以把每个类转换成这个数组形状吗在多类分类问题中,我可以使用python将3个类标签转换为2D数组吗?,python,pandas,numpy,scikit-learn,Python,Pandas,Numpy,Scikit Learn,我可以把每个类转换成这个数组形状吗 第1类-[0,0]第2类-[0,1]第3类-[1,0] 我搜索了标签预处理中的所有sklearn文档,只能找到3D数组形状的编码[1,0,0],[0,1,0],[0,0,1] 您可以使用tensorflow.one\u hot,使用3个类,深度为2: 使用你找到的编码并切掉最后一列或第一列?这似乎是一个可行的解决方案,我要试试。谢谢@保尔装甲车 import tensorflow as tf tf.one_hot([1, 2, 0, 1, 2, 0], de
第1类-[0,0]
第2类-[0,1]第3类-[1,0]
我搜索了标签预处理中的所有sklearn文档,只能找到3D数组形状的编码[1,0,0],[0,1,0],[0,0,1]
使用你找到的编码并切掉最后一列或第一列?这似乎是一个可行的解决方案,我要试试。谢谢@保尔装甲车
import tensorflow as tf
tf.one_hot([1, 2, 0, 1, 2, 0], depth=2)
<tf.Tensor: shape=(6, 2), dtype=float32, numpy=
array([[0., 1.],
[0., 0.],
[1., 0.],
[0., 1.],
[0., 0.],
[1., 0.]], dtype=float32)>
from sklearn.preprocessing import OneHotEncoder
ohe = OneHotEncoder(drop='first')
ohe.fit_transform([[1], [2], [0], [1], [2], [0]]).toarray()
array([[1., 0.],
[0., 1.],
[0., 0.],
[1., 0.],
[0., 1.],
[0., 0.]])