我怀疑的是我应该如何为多变量物流回归准备我的训练和标签数据,我试图在网上找到,但大多数教程都在使用任何能够完成这项工作的图书馆,
所以如果我的数据集看起来像这样:
input_data labels
[ 'aa' , 'bb' ,'cc' ,'dd' , 'ee' ] ['n1' ,'n5']
['rr' , 'ff' , 'gg' , 'hh' , 'ii' ,'jj'] ['g1', 'g5']
['kk' , 'll' , 'mm' , 'nn' , 'oo' , 'pp] ['y1','y2','y3']
['qq','rr','ss','tt','uu'vv','ww'] ['y1','y2','z1','z2']
我夸大了词汇量:
#building vocabulary
vocabulary = {'bb': 1, 'ff': 6, 'll': 12, 'hh': 8, 'rr': 18, 'tt': 20, 'gg': 7, 'vv': 22, 'jj': 10, 'nn': 14, 'qq': 17, 'kk': 11, 'cc': 2, 'mm': 13, 'ee': 4, 'ww': 23, 'ii': 9, 'oo': 15, 'ss': 19, 'uu': 21, 'pp': 16, 'aa': 0, 'dd': 3}
#building all labels list
labels =['y3', 'n1', 'g1', 'g5', 'y1', 'y2', 'n5', 'z1', 'z2']
现在下一步我填写数据:
# doing padding
[0, 1, 2, 3, 4,0 ,0 ]
[18, 6, 7, 8, 9, 10,0]
[11, 12, 13, 14, 15, 16,0]
[17, 18, 19, 20, 21, 22, 23,0]
一切都还好,现在困惑的是如何将我的标签提供给神经网络,每个输入都有多个类,
我应该使用单热编码方法:
padded input_data one_hot labels
[0, 1, 2, 3, 4, 0, 0] [0, 1, 0, 0, 0, 0, 1, 0, 0] # ['n1' ,'n5']
[18, 6, 7, 8, 9, 10,0] [0, 0, 1, 1, 0, 0, 0, 0, 0] # ['g1', 'g5']
[11, 12, 13, 14, 15, 16,0] [1, 0, 0, 0, 1, 1, 0, 0, 0] # ['y1','y2','y3']
[17, 18, 19, 20, 21, 22, 23,0] [0, 0, 0, 0, 1, 1, 0, 1, 1] #['y1','y2','z1','z2']
或第二种方法是
[[0, 1, 0, 0, 0, 0, 0, 0, 0] , [0, 0, 0, 0, 0, 0, 1, 0, 0]] # [ ['n1'] , ['n5'] ]
[ [0, 0, 1, 0, 0, 0, 0, 0, 0] , [0, 0, 0, 1, 0, 0, 0, 0, 0] ] # [ ['g1'] , ['g5'] ]
[ [1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0] ] # [ ['y1'] , ['y2'] ,['y3]]
[ [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1]] # [ ['y1'],['y2'],['z1'],['z2']]
或索引方法
[0, 1, 2, 3, 4, 0, 0] [1, 6]
[18, 6, 7, 8, 9, 10,0] [2, 3]
[11, 12, 13, 14, 15, 16,0] [4, 5, 0]
[17, 18, 19, 20, 21, 22, 23,0] [4, 5, 7, 8]
对于单一分类,我曾经从概率分布中获取argmax,如下所示:
probs = tf.nn.softmax(logits)
preds = tf.argmax(probs, axis=-1) #which gives the max probality
分配是结果
但在多分类中我们如何从分销中获得结果?