내 질문은 this question과 매우 밀접하게 관련되어 있지만 그 이상의 것입니다. 내가Keras : 클래스 가중치가있는 LSTM
- 는 시간 단계의 수를 입력 수 있습니다
nb_tsteps=10
- 수 Keras에서 다음 LSTM을 구현하기 위해 노력하고
각 시간 단계에서 LSTM 세포의 수는
nb_feat=40
- 입니다
120
- LSTM 층 다음에 TimeDistributedDense 층이있다.
내가 모양 (5932720, 40)
의 원래의 시계열에 걸쳐 길이 nb_tsteps=10
의 창을 굴려 nb_samples
어디서
nb_samples, 10, 40
으로 입력 데이터를 제시 할 필요가 있음을 이해합니다. 코드는 따라서 (위의 지금까지 올바른 가정) 내 질문에 이제
model = Sequential()
model.add(LSTM(120, input_shape=(X_train.shape[1], X_train.shape[2]),
return_sequences=True, consume_less='gpu'))
model.add(TimeDistributed(Dense(50, activation='relu')))
model.add(Dropout(0.2))
model.add(TimeDistributed(Dense(20, activation='relu')))
model.add(Dropout(0.2))
model.add(TimeDistributed(Dense(10, activation='relu')))
model.add(Dropout(0.2))
model.add(TimeDistributed(Dense(3, activation='relu')))
model.add(TimeDistributed(Dense(1, activation='sigmoid')))
입니다 : 이진 응답 (0/1)은 크게 균형이 맞지 나는 model.fit()
에 cw = {0: 1, 1: 25}
같은 class_weight
사전을 통과해야합니다. 그러나 나는 예외 class_weight not supported for 3+ dimensional targets
를 얻는다. 이는 응답 데이터를 (nb_samples, 1, 1)
으로 제시하기 때문입니다. 2D 배열 (nb_samples, 1)
으로 바꾼 경우 Error when checking model target: expected timedistributed_5 to have 3 dimensions, but got array with shape (5932720, 1)
예외가 발생합니다.
도움을 주셔서 감사합니다.
왜 sample_weight (sample_weight_mode = "temporal")와 관련이 있는지 이해할 수 없습니다. 우리는 샘플의 가중치가 아닌 클래스 가중치에 대해 이야기하고 있습니다. sample_weight_mode = "temporal"은 매 시간 단계마다 모든 샘플에 가중치를 할당하지만 클래스 레이블과 전혀 관련이 없습니까? – ymeng