モデルの学習と評価

Keras で学ぶ高度な Deep Learning

Zach Deane-Mayer

Data Scientist

バスケットボールデータ

目標: トーナメントの結果を予測する

利用可能なデータ: 大会主催者によるチームレーティング

import pandas as pd
games_tourney = pd.read_csv('datasets/games_tourney.csv')
games_tourney.head()

Out[1]:
   season  team_1  team_2  home  seed_diff  score_diff  score_1  score_2  won
0    1985     288      73     0         -3          -9       41       50    0
1    1985    5929      73     0          4           6       61       55    1
2    1985    9884      73     0          5          -4       59       63    0
3    1985      73     288     0          3           9       50       41    1
4    1985    3920     410     0          1          -9       54       63    0
Keras で学ぶ高度な Deep Learning

バスケットボールデータ

入力: シード差

import pandas as pd
games_tourney = pd.read_csv('datasets/games_tourney.csv')
games_tourney.head()

Keras で学ぶ高度な Deep Learning

バスケットボールデータ

出力: 得点差

import pandas as pd
games_tourney = pd.read_csv('datasets/games_tourney.csv')
games_tourney.head()

Keras で学ぶ高度な Deep Learning

バスケットボールデータ

入力:

  • シード差 - 1つの数値: -15〜+15
  • シードの範囲: 1〜16
  • 最大差: 16-1 = +15
  • 最小差: 1-16 = -15

出力:

  • 得点差 - 1つの数値: -50〜+50
Keras で学ぶ高度な Deep Learning

バスケットボールデータ

  • シード差: 15
    • チーム1: 16
    • チーム2: 1
  • シード差: -15
    • チーム1: 1
    • チーム2: 16

Keras で学ぶ高度な Deep Learning

バスケットボールデータ

  • 得点差: -9
    • チーム1: 41
    • チーム2: 50
  • 得点差: 6
    • チーム1: 61
    • チーム2: 55

Keras で学ぶ高度な Deep Learning

バスケットボールデータ

import pandas as pd
games_tourney = pd.read_csv('datasets/games_tourney_samp.csv')
games_tourney.head()

Out[1]:
   season  team_1  team_2  home  seed_diff  score_diff  score_1  score_2  won
0    2017     320    6323     0         13          18      100       82    1
1    2017    6323     320     0        -13         -18       82      100    0
Keras で学ぶ高度な Deep Learning

モデルの構築

from tensorflow.keras.models import Model
from tensorflow.keras.layers import Input, Dense
input_tensor = Input(shape=(1,))
output_tensor = Dense(1)(input_tensor)
model = Model(input_tensor, output_tensor)
model.compile(optimizer='adam', loss='mae')

Keras で学ぶ高度な Deep Learning

モデルの学習

from pandas import read_csv
games = read_csv('datasets/games_tourney.csv')
model.fit(games['seed_diff'],
          games['score_diff'],
          batch_size=64,
          validation_split=.20,
          verbose=True)

Keras で学ぶ高度な Deep Learning

モデルの評価

model.evaluate(games_test['seed_diff'],
               games_test['score_diff'])

1000/1000 [==============================] - 0s 26us/step
Out[1]: 9.145421981811523
Keras で学ぶ高度な Deep Learning

さあ、練習しましょう!

Keras で学ぶ高度な Deep Learning

Preparing Video For Download...