用于MLP的列车中的Scikit使用列表

问题描述 投票:1回答:1

我想用以下数据训练神经网络(Multi-Perceptron):

1              2              3             Other Field   Label
[1, 2, 3, 4]   [5, 6, 7, 8]   [9, 10, 11]   1234          5678
etc...

这里的123是包含列表的列。其他两列只有数值。

只有我一直这样:

ValueError: setting an array element with a sequence.

这甚至可能吗?

编辑: 我训练神经网络的代码如下:

from sklearn.neural_network import MLPClassifier
mlp = MLPClassifier(alpha=1e-5, hidden_layer_sizes=(10, 10), random_state=1)
mlp.fit(X_train, y_train)

这是我的火车数据的屏幕截图:

enter image description here

我的标签只是一列数字。

python dataframe scikit-learn neural-network training-data
1个回答
1
投票

如果您的列表始终具有相同的长度,则只是将每个列表列拆分为四个单独的列的问题,例如,如here

# create a dataset
raw_data = {'score': [1,2,3], 
        'tags': [['apple','pear','guava'],['truck','car','plane'],['cat','dog','mouse']]}
df = pd.DataFrame(raw_data, columns = ['score', 'tags'])
# expand df.tags into its own dataframe
tags = df['tags'].apply(pd.Series)
# rename each variable
tags = tags.rename(columns = lambda x : 'tag_' + str(x))
# join the tags dataframe back to the original dataframe
df = pd.concat([df[:], tags[:]], axis=1)
df.drop('tags', inplace=True, axis=1)

如果没有,最佳答案可能是特定问题。一种方法可以是通过使用填充值填充然后执行相同的操作来将每个列表扩展到最长列表的长度。

© www.soinside.com 2019 - 2024. All rights reserved.