0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Kaggle]Santander Customer Transaction Prediction(その3)

Posted at

Santander Customer Transaction Prediction に挑戦してみた。(その3)

この記事は「Santander Customer Transaction Prediction に挑戦してみた。(その2)」の続きです。

(8)コールバック

コールバックを組み込む

今回使用したコールバックは「ReduceLROnPlateau」で、訓練中に学習率を調整してくれる魔法のようなものです。
使い方はとても簡単で、下記のリストを作成してからモデルに入れるだけです。(8-2)
コールバックは検証データを監視するため、モデルには"validation_data = (x_val, y_val)"を入れる

8-1
callbacks_list = [keras.callbacks.ReduceLROnPlateau(
                                        monitor = "val_loss", #損失値を監視
                                        factor = 0.1, #コールバックが起動したら、学習率に0.1をかける(位を一つ下げる)
                                        patience = 5, #検証データでの"val_loss"が5エポック改善されなければ起動
                            )]

コールバックを組み込んだモデル

一般的なモデルに、1行加えるだけで魔法が使えます。Kerasに感謝

8-2
now_list = high_feature_list + medium_feature_list
print(len(now_list))

x_train_in_model = x_train_ss[:, now_list]#モデルに入れる訓練データ
y_train_in_model = y_train_ss[:, now_list]#モデルに入れるテストデータ

percent_train = 80#訓練データに使う割合(残りは検証データ)[%]
train_num = round(200000*(percent_train/100))#訓練データに使うデータ数(残りは検証データ)

par_train = x_train_in_model[:train_num, :]
par_targets = train_targets[:train_num]
val_train = x_train_in_model[train_num:, :]
val_targets = train_targets[train_num:]

b_size = 1024
epoch = 12


model = Sequential()
model.add(Dense(64, input_shape = (len(now_list), ), activation = "relu"))
model.add(Dense(32, activation = "relu"))
model.add(Dropout(0.5))
model.add(Dense(32, activation = "relu"))
model.add(Dropout(0.5))
model.add(Dense(1, activation = "sigmoid"))

model.compile(optimizer = optimizers.Adam(), loss = "binary_crossentropy", metrics = ["acc"])

history = model.fit(par_train, par_targets, 
                    epochs = epoch, 
                    batch_size = b_size, 
                    callbacks = callbacks_list, #このように記載するだけで、コールバックを組み込める
                    validation_data = (val_train, val_targets))#コールバック使用時、ここは必須

スクリーンショット 2019-06-07 午後14.46.13 午後.png

(9)提出

提出用データを作成

提出データは0〜1の確率で提出するそうです。0と1の値に直して提出しないように注意してください。
(インデックスをつけていいかなどがわかりにくく、いつも1回は弾かれます・・・)

9-1
ans = model.predict(y_train_in_model)
# ans = np.round(ans).astype(int)とすると0・1になる
ans = ans.flatten()
ans = ans.tolist()

print(len(ans))

data = {"target": ans}
ans_df = pd.DataFrame(data)
ans_df.index = test["ID_code"]
ans_df.to_csv("sub_1_Santander_Customer_Transaction_Prediction.csv")

結果

提出期限が過ぎているからか、順位は確認できませんでした・・・
(左)Private Score  (右)Public Score
スクリーンショット 2019-06-07 午後14.51.46 午後.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?