TDと、
features
.8, .1, .3
.2, .4, .6
.7, .2, .1
へ:
[[.8
.1
.3],
[.2,
.4,
.6
],
[.3,
.6
.1]]
基本的にはこのようになりますデータセットを再形成 X = np.expand_dims(X, axis=2) # reshape (569, 30) to (569, 30, 1)
# now input can be set as
model.add(Conv1D(2,2,activation='relu',input_shape=(30, 1))
:Conv1d
が意味をなすためにのためにLRあなたは空間次元を持っているあなたにデータを再構築する必要があります
説明と例
通常、畳み込みは空間次元で機能します。カーネルは、テンソルを生成する次元にわたって「畳み込まれている」。 Conv1Dの場合、カーネルはすべての例の 'steps'ディメンションに渡されます。
steps
が文中の単語の数であるNLPでConv1Dが使用されていることがわかります(一定の最大長に埋められます)。言葉はここでは長さのベクトル4
としてコード化されるかもしれないでしょう例文です:
jack .1 .3 -.52 |
is .05 .8, -.7 |<--- kernel is `convolving` along this dimension.
a .5 .31 -.2 |
boy .5 .8 -.4 \|/
そして、私たちは、この場合にコンバージョンへの入力を設定するような方法:
maxlen = 4
input_dim = 3
model.add(Conv1D(2,2,activation='relu',input_shape=(maxlen, input_dim))
あなたの場合は、長さ1の各フィーチャで空間フィーチャとしてフィーチャを扱います(下記参照)
ここにあなたのデータセットの例があります
att1 .04 |
att2 .05 | < -- kernel convolving along this dimension
att3 .1 | notice the features have length 1. each
att4 .5 \|/ example have these 4 featues.
そして、我々はとしてConv1D例を設定します:あなたはあなたのデータセットがへに再形成されなければならわかるように(569、30、1)
maxlen = num_features = 4 # this would be 30 in your case
input_dim = 1 # since this is the length of _each_ feature (as shown above)
model.add(Conv1D(2,2,activation='relu',input_shape=(maxlen, input_dim))
使用:
X = np.expand_dims(X, axis=2) # reshape (569, 30, 1)
# now input can be set as
model.add(Conv1D(2,2,activation='relu',input_shape=(30, 1))
をここでは、実行可能なフルフェッジの例を示します(Functional APIを使用します)
from keras.models import Model
from keras.layers import Conv1D, Dense, MaxPool1D, Flatten, Input
import numpy as np
inp = Input(shape=(5, 1))
conv = Conv1D(filters=2, kernel_size=2)(inp)
pool = MaxPool1D(pool_size=2)(conv)
flat = Flatten()(pool)
dense = Dense(1)(flat)
model = Model(inp, dense)
model.compile(loss='mse', optimizer='adam')
print(model.summary())
# get some data
X = np.expand_dims(np.random.randn(10, 5), axis=2)
y = np.random.randn(10, 1)
# fit model
model.fit(X, y)
です。寸法が1x690のデータがある場合は、カーネルサイズ3の40個のフィルタを持つConv1Dレイヤーでは、そのレイヤーの重みを調べると、40 * 690 * 3の重みがあると言います。私はなぜこれが理解できるか分からない、私は40 * 3体重しか持たないだろうと思った?どのように1x40の形状を出力しますか? – jerpint