【发布时间】:2018-04-09 18:25:55
【问题描述】:
我无法为一维输入向量构建 CNN。
输入值示例:
df_x.iloc[300]
Out[33]:
0 0.571429
1 1.000000
2 0.971429
3 0.800000
4 1.000000
5 0.142857
6 0.657143
7 0.857143
8 0.971429
9 0.000000
10 0.000000
11 0.000000
12 0.000000
13 0.000000
14 0.000000
15 0.000000
Name: 300, dtype: float64
输出值示例:
df_y.iloc[300]
Out[34]:
0 0.571429
1 0.914286
2 1.000000
3 0.971429
4 0.800000
5 1.000000
6 0.914286
7 0.942857
8 0.800000
9 0.657143
10 0.857143
11 0.971429
12 0.000000
13 0.000000
14 0.000000
15 0.000000
16 0.000000
17 0.000000
18 0.000000
19 0.000000
20 0.000000
21 0.000000
22 0.000000
我有 15k 个训练示例。
df_x.shape
Out[28]:
(15772, 16)
df_y.shape
Out[29]:
(15772, 23)
我现在的模特:
model = Sequential()
model.add(Conv2D(5, df_x.shape[1], input_shape=(5, 1)))
model.add(Dense(46, activation='relu'))
model.add(Dense(56, activation='relu'))
model.add(Dense(66, activation='relu'))
model.add(Dense(56, activation='relu'))
model.add(Dense(46, activation='relu'))
model.add(Dense(df_y.shape[1], activation='relu'))
# compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# Fit the model
model.fit(df_x, df_y, epochs=5, batch_size=10)
我想构建模型,其中第一层的卷积大小为(5,1)、5 个过滤器和输入形状df_x.shape[1], 1。
我有一个错误:
ValueError: Input 0 is incompatible with layer conv2d_10: expected ndim=4, found ndim=3
您能解释一下如何为一维输入值构建 CNN 吗?
【问题讨论】:
标签: python machine-learning deep-learning keras conv-neural-network