如何在 Python 的机器学习中使用值列表作为标签

How to use a list of values as label in Python's Machine Learning

我遇到了一个问题,我不知道如何在 ML 模型中使用列表作为标签。基本上我有一个数据框如下:

我的特征集是一个数字列表,我的标签也是一个数字列表。我如何将一个与另一个关联起来?我已经使用了二进制标签,但我不能 manage-it 使用 non-binary 标签。

ps: 我知道我的数据缺乏预处理,出于处理速度的原因我只加载了整体的一小部分

编辑 - 抱歉不够清楚:每个数字都是一个词。我的特征集是文本,标签是标题。我正在尝试构建一个给定文本的模型,它会根据经过训练的模型生成一个标题

https://scikit-learn.org/stable/modules/multiclass.html#multilabel-classification-format 你应该使用多标签方法来解决你的问题

您可能想尝试 sklearn 的 MultiLabelBinarizer()。看看this post

我想你可以试试 pandas "get_dummies".

中 built-in 的 OneHotEncoding

根据我的理解,您的数据看起来像(在此处给出 'y' 的示例):

df
 
   a  b  y
0  1  2  1
1  4  5  2
2  7  1  3
3  4  7  1
4  6  0  3
5  7  9  2
6  8  1  1

其中 y 列中的每个数字代表每个 class。

所以你可以做的是:

new_y = pd.get_dummies(df['y'], drop_first=True)

It would be very helpful if you post some sample data here and what exactly you are willing to achieve.

PS :除此之外,您必须使用 Categorical_CrossEntropy 作为损失计算。