gpt4 book ai didi

python - Keras 输入形状,输入列表的简单数组

转载 作者:太空宇宙 更新时间:2023-11-03 21:17:13 24 4
gpt4 key购买 nike

其中每个数组([x1, x2, x3, ... , x15]) 代表单个输入

[array([0.        , 0.08333333, 0.08333333, 0.08333333, 0.08333333,
0.08333333, 0.08333333, 0. , 0.08333333, 0.08333333,
0.08333333, 0.08333333, 0.08333333, 0.08333333, 0. ])
array([0.04166667, 0.10416667, 0.10416667, 0.08333333, 0. ,
0.10416667, 0.10416667, 0.02083333, 0.10416667, 0.08333333,
0. , 0. , 0.125 , 0.125 , 0. ])
array([0.04166667, 0. , 0.125 , 0.10416667, 0.02083333,
0.125 , 0.125 , 0.02083333, 0.10416667, 0. ,
0.02083333, 0.02083333, 0.14583333, 0.14583333, 0. ])
...
array([0.4375 , 0.0625 , 0. , 0. , 0. ,
0.0625 , 0. , 0.25 , 0. , 0.08333333,
0.04166667, 0.02083333, 0. , 0.04166667, 1. ])
array([0.45833333, 0. , 0.02083333, 0.02083333, 0.02083333,
0.08333333, 0. , 0.25 , 0. , 0.08333333,
0.04166667, 0.02083333, 0. , 0. , 1. ])
array([0.5 , 0. , 0. , 0.02083333, 0.02083333,
0. , 0.02083333, 0.27083333, 0.02083333, 0.10416667,
0.0
4166667, 0. , 0. , 0. , 1. ])]

进入模型

model = Sequential()
model.add(Dense(15, input_dim=15, kernel_initializer='uniform', activation='relu'))
model.add(Dense(16, kernel_initializer='uniform', activation='relu'))
model.add(Dense(14, kernel_initializer='uniform', activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

提示:

ValueError: Error when checking input: expected dense_1_input to have shape (15,) but got array with shape (1,)

如何 reshape 输入数据以适应此模型?

最佳答案

它不想在里面有一个 numpy 数组,它应该是内部列表,但只是最顶层的数组

X_train = np.array([x.tolist() for x in df['board_in'].values])
y_train = df['target']
y_train = np.array([y for y in df['target'].values])

关于python - Keras 输入形状,输入列表的简单数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54602673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com