予想通り不合理 -FXと機械学習と-

FXの自動売買や機械学習、その他勉強したことをシェアします

Kaggle -Youtube-8M Challenge- とりあえずサンプルの限界まで学習

kapiparaです。

 

先日に引き続きYoutube-8M challengeをやります。

前回はとにかく結果をsubmitすることだけを考えていたので10stepだけ実行した結果のモデルで作ったCSVをsubmitしましたが、今日は誤差関数が収斂するまで学習を回し続けたモデルを作成し、そのモデルでCSVを作成し、submitします。

 

コマンド↓

python train.py --train_data_pattern='./features/train*.tfrecord' --model=LogisticModel --train_dir=$MODEL_DIR/video_level_logistic_model --export_model_steps=500

 

model:LogisticModel

export_model_steps:500

 

まだ3割ぐらいしかサンプルコードが見れていませんが、とりあえずシンプルに上記の設定で実行。

modelとして何が用意されているか早く確認せねば...

 

学習を回している間に用語勉強↓

・適合率(precision):正であると予測されたもののうち、実際に正であるものの割合

・再現率 (recall):実際に正であるもののうち,正であると予測されたものの割合

 

hit_at_one = eval_util.calculate_hit_at_one(predictions_val, labels_val)
perr = eval_util.calculate_precision_at_equal_recall_rate(predictions_val,labels_val)

 ⇒ソースは見てないがrecallを出しているのは明白
gap = eval_util.calculate_gap(predictions_val, labels_val)

 

・eval_util.calculate_hit_at_one

def calculate_hit_at_one(predictions, actuals):
    top_prediction = numpy.argmax(predictions, 1)

  ⇒これは最大値のインデックスを取得している。意味通り。
    hits = actuals[numpy.arange(actuals.shape[0]), top_prediction]

  ⇒これは..
    return numpy.average(hits)

  ⇒これはhitsの平均を返している。

 

hitsの動きを確認するために実験------------------------------------------

>>> listss = numpy.array([(1,2,3,4,5),(5,4,3,2,1),(3,4,5,1,2)])

>>> print listss
[[1 2 3 4 5]
 [5 4 3 2 1]
 [3 4 5 1 2]]

>>> top = numpy.argmax(listss ,1)

>>> print topp
[4 0 2]

うむ。各行の一番大きい値のインデックスをtop_predictionとして持っている。(横持)

>>> actuals = numpy.array([(0,0,0,0,1),(0,1,0,0,0),(0,0,1,0,0)])

>>> print actuals
[[0 0 0 0 1]
 [0 1 0 0 0]
 [0 0 1 0 0]]

>>> shp = actuals.shape[0]
>>> print shp
3
>>> arg = numpy.arange(shp)
>>> print arg
[0 1 2]

>>> hits = actuals[arg,topp]
>>> print hits
[1 0 1]

-----------------------------------------------------------------------------------

ということで。(pythonもnumpyも初心者ですみませんね..)

hits = actuals[numpy.arange(actuals.shape[0]), top_prediction]

 ⇒hitsは最も確率が高いとしたラベルが当たっているもののカウント。

それの平均を返すということは、hitsは最も高いとしたラベルの正答率と考えてよい。

 

PERRとGAPはまた今度。

 

見た感じ学習が収束した。

INFO:tensorflow:training step 10 | Loss: 3045.63 Examples/sec: 1054.09 | Hit@1: 0.52 PERR: 0.35 GAP: 0.21
INFO:tensorflow:training step 510 | Loss: 43.15 Examples/sec: 1090.50 | Hit@1: 0.69 PERR: 0.52 GAP: 0.54
INFO:tensorflow:training step 1010 | Loss: 16.47 Examples/sec: 1059.01 | Hit@1: 0.74 PERR: 0.57 GAP: 0.61
INFO:tensorflow:training step 1510 | Loss: 12.23 Examples/sec: 1091.07 | Hit@1: 0.77 PERR: 0.59 GAP: 0.63
INFO:tensorflow:training step 2010 | Loss: 10.43 Examples/sec: 1104.52 | Hit@1: 0.75 PERR: 0.60 GAP: 0.64
INFO:tensorflow:training step 2510 | Loss: 9.50 Examples/sec: 1070.70 | Hit@1: 0.77 PERR: 0.61 GAP: 0.67
INFO:tensorflow:training step 3010 | Loss: 8.96 Examples/sec: 1074.41 | Hit@1: 0.75 PERR: 0.59 GAP: 0.65

 

tensorboardを確認するために

tcp:6006のFWルール追加と「HTTPからの接続を許可」をしたがつながらず。

まあ再起動したらうまくいく気もするし明日やろう。

 

submit結果↓

f:id:kapipara18:20170410001900p:plain

 

現在262位!

 

以上