多标签的向量表示
from sklearn.preprocessing import MultiLabelBinarizer
只有数据,未知全部标签,需要统计
mlb = MultiLabelBinarizer()
labellist = [('红'),('绿色'),('红色','绿色')]
mlb.fit(labellist) # 直接用fit函数,统计label种类
mlb.fit_transform([label])
mlb.classes_
已知全部标签,不需要统计
mlb = MultiLabelBinarizer(classes = ["红", "黄", "绿"]) # 注意这里加了classes参数
mlb.fit_transform([("红", "绿"), ("黄"),("红", "黄")])
mlb.classes_
将预测的tensor转成标签
mlb.inverse_transform(predict_tensor)
标签:mlb,fit,标签,transform,classes,使用,MultiLabelBinarizer
From: https://www.cnblogs.com/lyq622/p/17629324.html