<jupyter_start><jupyter_text>1,2,3,4 -> 72,3,4,5 -> 83,4,5,6 -> 94,5,6,7 -> 105,6,7,8 -> 116,7,8,9 -> 127,8,9,10 -> 18,9,10,11 -> 29,10,11,12 -> 310,11,12,1 -> 4<jupyter_code>def build_dataset(tts):
    t1, t2, t3, t4, ty = tts
    x1 = df_num[(df_merged['REG_YEAR'] + df_merged['REG_MONTH']) == t1]['AMT'].values
    x2 = df_num[(df_merged['REG_YEAR'] + df_merged['REG_MONTH']) == t2]['AMT'].values
    x3 = df_num[(df_merged['REG_YEAR'] + df_merged['REG_MONTH']) == t3]['AMT'].values
    x4 = df_num[(df_merged['REG_YEAR'] + df_merged['REG_MONTH']) == t4]['AMT'].values
    y = df_num[(df_merged['REG_YEAR'] + df_merged['REG_MONTH']) == ty]['AMT'].values
    
    return np.array([x1,x2,x3,x4,y])
reg_comb = [
    ['201901', '201902', '201903', '201904', '201907'],
    ['201902', '201903', '201904', '201905', '201908'],
    ['201903', '201904', '201905', '201906', '201909'],
    ['201904', '201905', '201906', '201907', '201910'],
    ['201905', '201906', '201907', '201908', '201911'],
    ['201906', '201907', '201908', '201909', '201912'],
    ['201907', '201908', '201909', '201910', '202001'],
    ['201908', '201909', '201910', '201911', '202002'],
    ['201909', '201910', '201911', '201912', '202003'],
]
reg_test = ['201910', '201911', '201912', '202001', '202004']
ds = []
for reg in reg_comb:
    xy = build_dataset(reg)
    ds.append(xy)
    
ds = np.array(ds)
xy = build_dataset(reg_test)
x_te = np.array([np.log1p(xy[:4])])
from tensorflow.keras import backend as k
from tensorflow.keras.layers import Input, Dense, Dropout, concatenate
from tensorflow.keras.layers import Bidirectional, LSTM, Attention
from tensorflow.keras.models import Model
from tensorflow.keras import regularizers
from tensorflow.keras.optimizers import Adam, RMSprop
x_trn = np.log1p(ds[:-1,:4])
y_trn = np.log1p(ds[:-1,-1:])

x_val = np.log1p(ds[-1:, :4])
y_val = np.log1p(ds[-1:, -1:])
k.clear_session()
# xYear = Input(batch_shape=(None, 1))
# xMonth = Input(batch_shape=(None, 12))
# xYearEmb = Dense(5)(xYear)
# xMonthEmb = Dense(5)(xMonth)

xInput = Input(batch_shape=(None, 4, 697))
xDrop = Dropout(0.3)(xInput)
xLstm = Bidirectional(LSTM(64, return_sequences=True))(xDrop)
xLstm = Bidirectional(LSTM(64))(xLstm)
xDense = Dense(128, activation='relu', kernel_regularizer=regularizers.l2(0.01))(xLstm)

# xConcat = concatenate([xLstm, xYearEmb, xMonthEmb])
xOutput = Dense(697)(xDense)
xOutput = k.expand_dims(xOutput, axis=1)


model = Model(xInput, xOutput)
model.compile(
    loss='mean_squared_error',
    optimizer=Adam(learning_rate=0.005))

print(model.summary())
model.fit(x_trn, y_trn, epochs=500, validation_data=[x_val, y_val], verbose=1)<jupyter_output>Train on 8 samples, validate on 1 samples
Epoch 1/500
8/8 [==============================] - 0s 2ms/sample - loss: 2.0848 - val_loss: 6.9309
Epoch 2/500
8/8 [==============================] - 0s 2ms/sample - loss: 2.0840 - val_loss: 6.7770
Epoch 3/500
8/8 [==============================] - 0s 2ms/sample - loss: 2.0826 - val_loss: 6.9015
Epoch 4/500
8/8 [==============================] - 0s 2ms/sample - loss: 2.0806 - val_loss: 6.8181
Epoch 5/500
8/8 [==============================] - 0s 2ms/sample - loss: 2.0787 - val_loss: 6.8442
Epoch 6/500
8/8 [==============================] - 0s 2ms/sample - loss: 2.0775 - val_loss: 6.8705
Epoch 7/500
8/8 [==============================] - 0s 2ms/sample - loss: 2.0769 - val_loss: 6.7987
Epoch 8/500
8/8 [==============================] - 0s 2ms/sample - loss: 2.0767 - val_loss: 6.8991
Epoch 9/500
8/8 [==============================] - 0s 2ms/sample - loss: 2.0763 - val_loss: 6.7861
Epoch 10/500
8/8 [==============================] - 0s 2ms/sample -[...]<jupyter_text>Real Test<jupyter_code>pred = model.predict([x_te])
pred_decode = 10**pred
(pred_decode[0,0]<0).sum()
df_rt = df_merged[(df_merged['REG_YEAR'] + df_merged['REG_MONTH']) == '202004']
df_rt['AMT'] = pred_decode[0, 0]
gb_rt = df_rt.groupby(['CARD_SIDO_NM', 'STD_CLSS_NM']).agg({'AMT':'sum'})
# 제출 파일 만들기
subm = pd.read_csv('input/submission.csv', index_col=0)
subm['AMT'] = np.concatenate([gb_rt['AMT'].values, gb_rt['AMT'].values])
subm.index.name = 'id'
subm.to_csv('submission_bigcat.csv', encoding='utf-8-sig')
subm.head()
subm<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.26284771334276286, 'fraction_numerical': 0.14474304573314475, 'mean_word_length': 5.342301943198804, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '294219', 'license': 'MIT', 'n_tokens_mistral': 2155, 'n_tokens_neox': 1746, 'n_words': 320, 'path': '[Dacon] Jeju_Big-2007/Untitled.ipynb', 'repo_name': 'Timmy-Oh/Challenges', 'size': '4242'}