急帮我详细解释一下这段python代码的意思
#taginputlabelsandcreatealistoflengthnum_classes,withall0'sexceptthecorrectclass,whic...
#tag input labels and create a list of length num_classes, with all 0's except the correct class, which is 1
def binarize_labels(label_set):
encoder = LabelBinarizer()
encoder.fit(label_set)
label_set = encoder.transform(label_set)
label_set = label_set.astype(np.float32)
return label_set 展开
def binarize_labels(label_set):
encoder = LabelBinarizer()
encoder.fit(label_set)
label_set = encoder.transform(label_set)
label_set = label_set.astype(np.float32)
return label_set 展开
展开全部
#标签输入标签和创建一个列表的长度,然后自动进行0和1二进制化.
import numpy as np
from sklearn.preprocessing import LabelBinarizer
def binarize_labels(label_set):
encoder = LabelBinarizer()
encoder.fit(label_set)
label_set = encoder.transform(label_set)
label_set = label_set.astype(np.float32)
return label_set
print(binarize_labels(["是", "不", "是"]))
print(binarize_labels(["A", "B", "C"]))
print(binarize_labels([1, 0, 1]))
输出结果:
[[ 1.]
[ 0.]
[ 1.]]
[[ 1. 0. 0.]
[ 0. 1. 0.]
[ 0. 0. 1.]]
[[ 1.]
[ 0.]
[ 1.]]
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询