In [86]:
import tensorflow as tf
import pandas as pd
import numpy as np
In [87]:
def read_csv(file):
    return pd.read_csv(file)

def cleanup_data(data):
    # remove games when he didn't play
    data = data.drop(data[data.G.isnull()].index)

    # normalize age to years
    data['Age'] = data['Age'].str.split('-', 1).str[0].astype(int)

    # normalize minutes to exclude seconds
    data['MP'] = data["MP"].str.split(":").str[0].astype(int)
    
    data['PTS'] = data['PTS'].astype(int)
    return data

def read_and_clean_csv(file, columns=[]):
    data = read_csv(file)
    clean_data = cleanup_data(data)
    return clean_data[columns]

csv_label_name = "PTS" # points per game "+/-"
feature_names = ["G", "MP", "Age"]
csv_column_names = feature_names + [csv_label_name]

feature_columns = [
    tf.feature_column.numeric_column(feature) for feature in feature_names
]

def read_seasons(seasons=range(2002, 2018)):
    stats = []
    for season in seasons:
        file = str(season) + ".csv"
        season_stat = read_and_clean_csv(file, columns=csv_column_names)
        stats.append(season_stat)
    return pd.concat(stats)

stats = read_seasons()
train_factor = 0.8
train, test = stats[:int(len(stats)*train_factor)], stats[int(len(stats)*train_factor):]
In [88]:
print("test:" + str(test.shape) + " train: " + str(train.shape) + " stats: " + str(stats.shape))
test:(212, 4) train: (845, 4) stats: (1057, 4)
In [89]:
input_fn_train = tf.estimator.inputs.pandas_input_fn(
    x = pd.DataFrame({
        "Age" : train["Age"].values,
        "MP" : train["MP"].values,
        "G" : train["G"].values
    }),
    y = pd.Series(train.PTS.values),
    shuffle=False,
    num_epochs=20000
)
In [90]:
estimator = tf.estimator.DNNRegressor(hidden_units=[5, 5], feature_columns=feature_columns)
# estimator = tf.estimator.LinearRegressor(feature_columns=feature_columns)
INFO:tensorflow:Using default config.
WARNING:tensorflow:Using temporary folder as model directory: /var/folders/55/qkrngbr949x1jzs0c0dt70wc0000gn/T/tmp6aleB_
INFO:tensorflow:Using config: {'_save_checkpoints_secs': 600, '_session_config': None, '_keep_checkpoint_max': 5, '_task_type': 'worker', '_train_distribute': None, '_is_chief': True, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x119d64a90>, '_evaluation_master': '', '_save_checkpoints_steps': None, '_keep_checkpoint_every_n_hours': 10000, '_service': None, '_num_ps_replicas': 0, '_tf_random_seed': None, '_master': '', '_num_worker_replicas': 1, '_task_id': 0, '_log_step_count_steps': 100, '_model_dir': '/var/folders/55/qkrngbr949x1jzs0c0dt70wc0000gn/T/tmp6aleB_', '_global_id_in_cluster': 0, '_save_summary_steps': 100}
In [91]:
# train
estimator.train(input_fn=input_fn_train, steps=20000)
INFO:tensorflow:Calling model_fn.
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Create CheckpointSaverHook.
INFO:tensorflow:Graph was finalized.
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
INFO:tensorflow:Saving checkpoints for 1 into /var/folders/55/qkrngbr949x1jzs0c0dt70wc0000gn/T/tmp6aleB_/model.ckpt.
INFO:tensorflow:loss = 11780.277, step = 1
INFO:tensorflow:global_step/sec: 483.334
INFO:tensorflow:loss = 4870.778, step = 101 (0.211 sec)
INFO:tensorflow:global_step/sec: 542.573
INFO:tensorflow:loss = 5737.624, step = 201 (0.182 sec)
INFO:tensorflow:global_step/sec: 567.927
INFO:tensorflow:loss = 6592.8374, step = 301 (0.178 sec)
INFO:tensorflow:global_step/sec: 555.549
INFO:tensorflow:loss = 4664.8516, step = 401 (0.178 sec)
INFO:tensorflow:global_step/sec: 551.746
INFO:tensorflow:loss = 3528.5503, step = 501 (0.181 sec)
INFO:tensorflow:global_step/sec: 576.426
INFO:tensorflow:loss = 3874.3115, step = 601 (0.174 sec)
INFO:tensorflow:global_step/sec: 521.251
INFO:tensorflow:loss = 5857.655, step = 701 (0.191 sec)
INFO:tensorflow:global_step/sec: 513.901
INFO:tensorflow:loss = 3966.4067, step = 801 (0.196 sec)
INFO:tensorflow:global_step/sec: 547.201
INFO:tensorflow:loss = 7186.493, step = 901 (0.182 sec)
INFO:tensorflow:global_step/sec: 574.564
INFO:tensorflow:loss = 5782.948, step = 1001 (0.174 sec)
INFO:tensorflow:global_step/sec: 559.51
INFO:tensorflow:loss = 4811.618, step = 1101 (0.180 sec)
INFO:tensorflow:global_step/sec: 553.752
INFO:tensorflow:loss = 3870.3435, step = 1201 (0.179 sec)
INFO:tensorflow:global_step/sec: 570.246
INFO:tensorflow:loss = 3749.3418, step = 1301 (0.175 sec)
INFO:tensorflow:global_step/sec: 527.544
INFO:tensorflow:loss = 5511.0107, step = 1401 (0.191 sec)
INFO:tensorflow:global_step/sec: 366.987
INFO:tensorflow:loss = 4344.091, step = 1501 (0.272 sec)
INFO:tensorflow:global_step/sec: 336.878
INFO:tensorflow:loss = 7747.7563, step = 1601 (0.297 sec)
INFO:tensorflow:global_step/sec: 338.764
INFO:tensorflow:loss = 5185.41, step = 1701 (0.295 sec)
INFO:tensorflow:global_step/sec: 346.239
INFO:tensorflow:loss = 3679.4768, step = 1801 (0.287 sec)
INFO:tensorflow:global_step/sec: 401.96
INFO:tensorflow:loss = 4050.9236, step = 1901 (0.253 sec)
INFO:tensorflow:global_step/sec: 365.803
INFO:tensorflow:loss = 4030.0234, step = 2001 (0.273 sec)
INFO:tensorflow:global_step/sec: 357.944
INFO:tensorflow:loss = 5182.0327, step = 2101 (0.275 sec)
INFO:tensorflow:global_step/sec: 371.273
INFO:tensorflow:loss = 4995.22, step = 2201 (0.271 sec)
INFO:tensorflow:global_step/sec: 394.449
INFO:tensorflow:loss = 6698.9805, step = 2301 (0.252 sec)
INFO:tensorflow:global_step/sec: 549.478
INFO:tensorflow:loss = 5240.0957, step = 2401 (0.183 sec)
INFO:tensorflow:global_step/sec: 514.165
INFO:tensorflow:loss = 3489.7217, step = 2501 (0.194 sec)
INFO:tensorflow:global_step/sec: 505.349
INFO:tensorflow:loss = 4176.119, step = 2601 (0.199 sec)
INFO:tensorflow:global_step/sec: 440.651
INFO:tensorflow:loss = 4459.413, step = 2701 (0.226 sec)
INFO:tensorflow:global_step/sec: 469.974
INFO:tensorflow:loss = 4645.6396, step = 2801 (0.213 sec)
INFO:tensorflow:global_step/sec: 515.876
INFO:tensorflow:loss = 5204.7305, step = 2901 (0.194 sec)
INFO:tensorflow:global_step/sec: 537.646
INFO:tensorflow:loss = 6583.518, step = 3001 (0.186 sec)
INFO:tensorflow:global_step/sec: 458.192
INFO:tensorflow:loss = 4836.042, step = 3101 (0.219 sec)
INFO:tensorflow:global_step/sec: 454.263
INFO:tensorflow:loss = 3439.2175, step = 3201 (0.230 sec)
INFO:tensorflow:global_step/sec: 515.727
INFO:tensorflow:loss = 3828.8867, step = 3301 (0.184 sec)
INFO:tensorflow:global_step/sec: 469.708
INFO:tensorflow:loss = 5444.339, step = 3401 (0.212 sec)
INFO:tensorflow:global_step/sec: 394.09
INFO:tensorflow:loss = 4030.0417, step = 3501 (0.254 sec)
INFO:tensorflow:global_step/sec: 498.338
INFO:tensorflow:loss = 6109.638, step = 3601 (0.202 sec)
INFO:tensorflow:global_step/sec: 455.934
INFO:tensorflow:loss = 5989.081, step = 3701 (0.219 sec)
INFO:tensorflow:global_step/sec: 490.701
INFO:tensorflow:loss = 4816.375, step = 3801 (0.204 sec)
INFO:tensorflow:global_step/sec: 436.668
INFO:tensorflow:loss = 3673.1335, step = 3901 (0.228 sec)
INFO:tensorflow:global_step/sec: 368.906
INFO:tensorflow:loss = 3722.8765, step = 4001 (0.276 sec)
INFO:tensorflow:global_step/sec: 333.957
INFO:tensorflow:loss = 4966.284, step = 4101 (0.295 sec)
INFO:tensorflow:global_step/sec: 382.572
INFO:tensorflow:loss = 4202.1304, step = 4201 (0.262 sec)
INFO:tensorflow:global_step/sec: 411.362
INFO:tensorflow:loss = 7648.96, step = 4301 (0.243 sec)
INFO:tensorflow:global_step/sec: 462.849
INFO:tensorflow:loss = 5257.1445, step = 4401 (0.217 sec)
INFO:tensorflow:global_step/sec: 470.593
INFO:tensorflow:loss = 3706.5845, step = 4501 (0.212 sec)
INFO:tensorflow:global_step/sec: 451.953
INFO:tensorflow:loss = 4114.921, step = 4601 (0.222 sec)
INFO:tensorflow:global_step/sec: 434.633
INFO:tensorflow:loss = 3751.5884, step = 4701 (0.231 sec)
INFO:tensorflow:global_step/sec: 468.259
INFO:tensorflow:loss = 5397.9043, step = 4801 (0.212 sec)
INFO:tensorflow:global_step/sec: 353.731
INFO:tensorflow:loss = 4894.784, step = 4901 (0.283 sec)
INFO:tensorflow:global_step/sec: 437.336
INFO:tensorflow:loss = 6761.6475, step = 5001 (0.230 sec)
INFO:tensorflow:global_step/sec: 532.121
INFO:tensorflow:loss = 5478.8926, step = 5101 (0.186 sec)
INFO:tensorflow:global_step/sec: 447.958
INFO:tensorflow:loss = 3512.8433, step = 5201 (0.226 sec)
INFO:tensorflow:global_step/sec: 448.66
INFO:tensorflow:loss = 4183.913, step = 5301 (0.220 sec)
INFO:tensorflow:global_step/sec: 348.015
INFO:tensorflow:loss = 4291.868, step = 5401 (0.287 sec)
INFO:tensorflow:global_step/sec: 373.997
INFO:tensorflow:loss = 4740.181, step = 5501 (0.270 sec)
INFO:tensorflow:global_step/sec: 336.315
INFO:tensorflow:loss = 5155.1074, step = 5601 (0.297 sec)
INFO:tensorflow:global_step/sec: 378.175
INFO:tensorflow:loss = 6573.7427, step = 5701 (0.263 sec)
INFO:tensorflow:global_step/sec: 367.032
INFO:tensorflow:loss = 4946.9824, step = 5801 (0.272 sec)
INFO:tensorflow:global_step/sec: 393.223
INFO:tensorflow:loss = 3399.7397, step = 5901 (0.258 sec)
INFO:tensorflow:global_step/sec: 347.199
INFO:tensorflow:loss = 3829.4702, step = 6001 (0.284 sec)
INFO:tensorflow:global_step/sec: 351.685
INFO:tensorflow:loss = 5130.5527, step = 6101 (0.285 sec)
INFO:tensorflow:global_step/sec: 311.098
INFO:tensorflow:loss = 4161.697, step = 6201 (0.324 sec)
INFO:tensorflow:global_step/sec: 499.069
INFO:tensorflow:loss = 6083.8726, step = 6301 (0.200 sec)
INFO:tensorflow:global_step/sec: 454.812
INFO:tensorflow:loss = 6115.707, step = 6401 (0.220 sec)
INFO:tensorflow:global_step/sec: 555.957
INFO:tensorflow:loss = 4760.1914, step = 6501 (0.178 sec)
INFO:tensorflow:global_step/sec: 518.783
INFO:tensorflow:loss = 3624.0525, step = 6601 (0.194 sec)
INFO:tensorflow:global_step/sec: 447.589
INFO:tensorflow:loss = 3605.4634, step = 6701 (0.224 sec)
INFO:tensorflow:global_step/sec: 476.431
INFO:tensorflow:loss = 5181.7847, step = 6801 (0.209 sec)
INFO:tensorflow:global_step/sec: 432.324
INFO:tensorflow:loss = 4053.286, step = 6901 (0.235 sec)
INFO:tensorflow:global_step/sec: 339.118
INFO:tensorflow:loss = 7981.2734, step = 7001 (0.294 sec)
INFO:tensorflow:global_step/sec: 453.032
INFO:tensorflow:loss = 5413.915, step = 7101 (0.219 sec)
INFO:tensorflow:global_step/sec: 426.991
INFO:tensorflow:loss = 3578.809, step = 7201 (0.232 sec)
INFO:tensorflow:global_step/sec: 484.313
INFO:tensorflow:loss = 3843.3804, step = 7301 (0.208 sec)
INFO:tensorflow:global_step/sec: 525.876
INFO:tensorflow:loss = 3648.895, step = 7401 (0.192 sec)
INFO:tensorflow:global_step/sec: 512.634
INFO:tensorflow:loss = 5340.581, step = 7501 (0.196 sec)
INFO:tensorflow:global_step/sec: 377.922
INFO:tensorflow:loss = 4206.8423, step = 7601 (0.265 sec)
INFO:tensorflow:global_step/sec: 485.062
INFO:tensorflow:loss = 6940.9297, step = 7701 (0.205 sec)
INFO:tensorflow:global_step/sec: 479.72
INFO:tensorflow:loss = 5468.972, step = 7801 (0.207 sec)
INFO:tensorflow:global_step/sec: 508.006
INFO:tensorflow:loss = 3550.361, step = 7901 (0.196 sec)
INFO:tensorflow:global_step/sec: 611.098
INFO:tensorflow:loss = 4245.5166, step = 8001 (0.166 sec)
INFO:tensorflow:global_step/sec: 512.004
INFO:tensorflow:loss = 4224.4185, step = 8101 (0.194 sec)
INFO:tensorflow:global_step/sec: 457.153
INFO:tensorflow:loss = 4763.1113, step = 8201 (0.219 sec)
INFO:tensorflow:global_step/sec: 488.945
INFO:tensorflow:loss = 5006.2485, step = 8301 (0.205 sec)
INFO:tensorflow:global_step/sec: 477.587
INFO:tensorflow:loss = 6695.896, step = 8401 (0.210 sec)
INFO:tensorflow:global_step/sec: 500.225
INFO:tensorflow:loss = 4853.832, step = 8501 (0.200 sec)
INFO:tensorflow:global_step/sec: 526.56
INFO:tensorflow:loss = 3623.959, step = 8601 (0.189 sec)
INFO:tensorflow:global_step/sec: 471.191
INFO:tensorflow:loss = 3920.1594, step = 8701 (0.212 sec)
INFO:tensorflow:global_step/sec: 530.58
INFO:tensorflow:loss = 4875.375, step = 8801 (0.190 sec)
INFO:tensorflow:global_step/sec: 386.957
INFO:tensorflow:loss = 4199.698, step = 8901 (0.258 sec)
INFO:tensorflow:global_step/sec: 497.46
INFO:tensorflow:loss = 5908.7407, step = 9001 (0.202 sec)
INFO:tensorflow:global_step/sec: 379.126
INFO:tensorflow:loss = 6221.7275, step = 9101 (0.266 sec)
INFO:tensorflow:global_step/sec: 407.385
INFO:tensorflow:loss = 4707.6016, step = 9201 (0.245 sec)
INFO:tensorflow:global_step/sec: 289.098
INFO:tensorflow:loss = 3693.6064, step = 9301 (0.343 sec)
INFO:tensorflow:global_step/sec: 391.103
INFO:tensorflow:loss = 3372.0454, step = 9401 (0.255 sec)
INFO:tensorflow:global_step/sec: 469.814
INFO:tensorflow:loss = 5300.765, step = 9501 (0.215 sec)
INFO:tensorflow:global_step/sec: 452.086
INFO:tensorflow:loss = 3798.6987, step = 9601 (0.220 sec)
INFO:tensorflow:global_step/sec: 428.339
INFO:tensorflow:loss = 7758.498, step = 9701 (0.235 sec)
INFO:tensorflow:global_step/sec: 436.304
INFO:tensorflow:loss = 5619.3203, step = 9801 (0.228 sec)
INFO:tensorflow:global_step/sec: 427.586
INFO:tensorflow:loss = 4159.982, step = 9901 (0.235 sec)
INFO:tensorflow:global_step/sec: 429.938
INFO:tensorflow:loss = 3895.9048, step = 10001 (0.231 sec)
INFO:tensorflow:global_step/sec: 439.725
INFO:tensorflow:loss = 3674.1162, step = 10101 (0.227 sec)
INFO:tensorflow:global_step/sec: 434.649
INFO:tensorflow:loss = 5228.0225, step = 10201 (0.230 sec)
INFO:tensorflow:global_step/sec: 447.181
INFO:tensorflow:loss = 4177.0693, step = 10301 (0.225 sec)
INFO:tensorflow:global_step/sec: 448.093
INFO:tensorflow:loss = 7234.9385, step = 10401 (0.223 sec)
INFO:tensorflow:global_step/sec: 566.091
INFO:tensorflow:loss = 5400.456, step = 10501 (0.175 sec)
INFO:tensorflow:global_step/sec: 504.21
INFO:tensorflow:loss = 3606.3901, step = 10601 (0.200 sec)
INFO:tensorflow:global_step/sec: 583.54
INFO:tensorflow:loss = 4087.1985, step = 10701 (0.170 sec)
INFO:tensorflow:global_step/sec: 522.035
INFO:tensorflow:loss = 4070.295, step = 10801 (0.193 sec)
INFO:tensorflow:global_step/sec: 516.961
INFO:tensorflow:loss = 4830.3564, step = 10901 (0.193 sec)
INFO:tensorflow:global_step/sec: 583.683
INFO:tensorflow:loss = 4790.125, step = 11001 (0.170 sec)
INFO:tensorflow:global_step/sec: 484.029
INFO:tensorflow:loss = 6541.174, step = 11101 (0.208 sec)
INFO:tensorflow:global_step/sec: 516.94
INFO:tensorflow:loss = 4901.622, step = 11201 (0.195 sec)
INFO:tensorflow:global_step/sec: 488.532
INFO:tensorflow:loss = 3708.2627, step = 11301 (0.203 sec)
INFO:tensorflow:global_step/sec: 516.908
INFO:tensorflow:loss = 3930.5657, step = 11401 (0.193 sec)
INFO:tensorflow:global_step/sec: 648.732
INFO:tensorflow:loss = 4565.949, step = 11501 (0.155 sec)
INFO:tensorflow:global_step/sec: 564.668
INFO:tensorflow:loss = 4491.5586, step = 11601 (0.176 sec)
INFO:tensorflow:global_step/sec: 503.221
INFO:tensorflow:loss = 5727.6836, step = 11701 (0.199 sec)
INFO:tensorflow:global_step/sec: 601.457
INFO:tensorflow:loss = 6331.369, step = 11801 (0.167 sec)
INFO:tensorflow:global_step/sec: 451.376
INFO:tensorflow:loss = 4631.177, step = 11901 (0.220 sec)
INFO:tensorflow:global_step/sec: 480.277
INFO:tensorflow:loss = 3445.2388, step = 12001 (0.208 sec)
INFO:tensorflow:global_step/sec: 500.561
INFO:tensorflow:loss = 3634.268, step = 12101 (0.201 sec)
INFO:tensorflow:global_step/sec: 508.963
INFO:tensorflow:loss = 5332.153, step = 12201 (0.195 sec)
INFO:tensorflow:global_step/sec: 524.725
INFO:tensorflow:loss = 3827.2754, step = 12301 (0.191 sec)
INFO:tensorflow:global_step/sec: 572
INFO:tensorflow:loss = 7469.954, step = 12401 (0.177 sec)
INFO:tensorflow:global_step/sec: 501.809
INFO:tensorflow:loss = 5112.865, step = 12501 (0.197 sec)
INFO:tensorflow:global_step/sec: 445.957
INFO:tensorflow:loss = 4349.967, step = 12601 (0.226 sec)
INFO:tensorflow:global_step/sec: 468.011
INFO:tensorflow:loss = 3832.1284, step = 12701 (0.213 sec)
INFO:tensorflow:global_step/sec: 453.673
INFO:tensorflow:loss = 3624.3105, step = 12801 (0.220 sec)
INFO:tensorflow:global_step/sec: 555.028
INFO:tensorflow:loss = 5314.712, step = 12901 (0.180 sec)
INFO:tensorflow:global_step/sec: 522.793
INFO:tensorflow:loss = 3963.271, step = 13001 (0.193 sec)
INFO:tensorflow:global_step/sec: 427.635
INFO:tensorflow:loss = 7261.0635, step = 13101 (0.232 sec)
INFO:tensorflow:global_step/sec: 422.792
INFO:tensorflow:loss = 5316.6904, step = 13201 (0.240 sec)
INFO:tensorflow:global_step/sec: 398.584
INFO:tensorflow:loss = 3509.518, step = 13301 (0.250 sec)
INFO:tensorflow:global_step/sec: 477.676
INFO:tensorflow:loss = 3950.3757, step = 13401 (0.208 sec)
INFO:tensorflow:global_step/sec: 537.323
INFO:tensorflow:loss = 4207.055, step = 13501 (0.187 sec)
INFO:tensorflow:global_step/sec: 514.973
INFO:tensorflow:loss = 4895.705, step = 13601 (0.195 sec)
INFO:tensorflow:global_step/sec: 549.701
INFO:tensorflow:loss = 4922.595, step = 13701 (0.182 sec)
INFO:tensorflow:global_step/sec: 550.727
INFO:tensorflow:loss = 6584.413, step = 13801 (0.181 sec)
INFO:tensorflow:global_step/sec: 529.659
INFO:tensorflow:loss = 4810.9863, step = 13901 (0.188 sec)
INFO:tensorflow:global_step/sec: 522.122
INFO:tensorflow:loss = 3672.9873, step = 14001 (0.192 sec)
INFO:tensorflow:global_step/sec: 512.361
INFO:tensorflow:loss = 3960.1, step = 14101 (0.194 sec)
INFO:tensorflow:global_step/sec: 482.565
INFO:tensorflow:loss = 4306.886, step = 14201 (0.213 sec)
INFO:tensorflow:global_step/sec: 505.015
INFO:tensorflow:loss = 4530.63, step = 14301 (0.195 sec)
INFO:tensorflow:global_step/sec: 505.712
INFO:tensorflow:loss = 5932.661, step = 14401 (0.196 sec)
INFO:tensorflow:global_step/sec: 540.883
INFO:tensorflow:loss = 6007.171, step = 14501 (0.184 sec)
INFO:tensorflow:global_step/sec: 470.354
INFO:tensorflow:loss = 4717.772, step = 14601 (0.213 sec)
INFO:tensorflow:global_step/sec: 567.682
INFO:tensorflow:loss = 3565.5312, step = 14701 (0.176 sec)
INFO:tensorflow:global_step/sec: 546.726
INFO:tensorflow:loss = 3784.0513, step = 14801 (0.184 sec)
INFO:tensorflow:global_step/sec: 515.349
INFO:tensorflow:loss = 5295.657, step = 14901 (0.194 sec)
INFO:tensorflow:global_step/sec: 504.783
INFO:tensorflow:loss = 3765.6045, step = 15001 (0.197 sec)
INFO:tensorflow:global_step/sec: 551.953
INFO:tensorflow:loss = 7169.092, step = 15101 (0.180 sec)
INFO:tensorflow:global_step/sec: 515.185
INFO:tensorflow:loss = 5117.5986, step = 15201 (0.197 sec)
INFO:tensorflow:global_step/sec: 537.582
INFO:tensorflow:loss = 4515.6133, step = 15301 (0.185 sec)
INFO:tensorflow:global_step/sec: 481.512
INFO:tensorflow:loss = 3737.886, step = 15401 (0.207 sec)
INFO:tensorflow:global_step/sec: 432.814
INFO:tensorflow:loss = 3527.7324, step = 15501 (0.232 sec)
INFO:tensorflow:global_step/sec: 545.697
INFO:tensorflow:loss = 5352.289, step = 15601 (0.183 sec)
INFO:tensorflow:global_step/sec: 545.363
INFO:tensorflow:loss = 3984.9607, step = 15701 (0.184 sec)
INFO:tensorflow:global_step/sec: 614.711
INFO:tensorflow:loss = 7259.448, step = 15801 (0.163 sec)
INFO:tensorflow:global_step/sec: 433.372
INFO:tensorflow:loss = 5304.165, step = 15901 (0.232 sec)
INFO:tensorflow:global_step/sec: 478.396
INFO:tensorflow:loss = 3635.9912, step = 16001 (0.207 sec)
INFO:tensorflow:global_step/sec: 499.388
INFO:tensorflow:loss = 4024.7393, step = 16101 (0.202 sec)
INFO:tensorflow:global_step/sec: 582.245
INFO:tensorflow:loss = 4102.973, step = 16201 (0.169 sec)
INFO:tensorflow:global_step/sec: 558.176
INFO:tensorflow:loss = 4943.475, step = 16301 (0.179 sec)
INFO:tensorflow:global_step/sec: 477.92
INFO:tensorflow:loss = 4897.615, step = 16401 (0.210 sec)
INFO:tensorflow:global_step/sec: 471.332
INFO:tensorflow:loss = 6711.3145, step = 16501 (0.212 sec)
INFO:tensorflow:global_step/sec: 501.063
INFO:tensorflow:loss = 4922.823, step = 16601 (0.200 sec)
INFO:tensorflow:global_step/sec: 511.312
INFO:tensorflow:loss = 3605.7017, step = 16701 (0.196 sec)
INFO:tensorflow:global_step/sec: 488.274
INFO:tensorflow:loss = 4116.338, step = 16801 (0.204 sec)
INFO:tensorflow:global_step/sec: 475.763
INFO:tensorflow:loss = 4373.8354, step = 16901 (0.210 sec)
INFO:tensorflow:global_step/sec: 505.359
INFO:tensorflow:loss = 4523.6562, step = 17001 (0.198 sec)
INFO:tensorflow:global_step/sec: 544.784
INFO:tensorflow:loss = 5399.242, step = 17101 (0.186 sec)
INFO:tensorflow:global_step/sec: 473.718
INFO:tensorflow:loss = 6535.8184, step = 17201 (0.210 sec)
INFO:tensorflow:global_step/sec: 489.707
INFO:tensorflow:loss = 4712.4453, step = 17301 (0.203 sec)
INFO:tensorflow:global_step/sec: 518.672
INFO:tensorflow:loss = 3440.6655, step = 17401 (0.192 sec)
INFO:tensorflow:global_step/sec: 473.913
INFO:tensorflow:loss = 3774.4985, step = 17501 (0.211 sec)
INFO:tensorflow:global_step/sec: 532.439
INFO:tensorflow:loss = 5482.442, step = 17601 (0.188 sec)
INFO:tensorflow:global_step/sec: 521.939
INFO:tensorflow:loss = 3954.7568, step = 17701 (0.192 sec)
INFO:tensorflow:global_step/sec: 520.82
INFO:tensorflow:loss = 6967.4224, step = 17801 (0.193 sec)
INFO:tensorflow:global_step/sec: 566.698
INFO:tensorflow:loss = 5766.056, step = 17901 (0.176 sec)
INFO:tensorflow:global_step/sec: 587.306
INFO:tensorflow:loss = 4789.04, step = 18001 (0.170 sec)
INFO:tensorflow:global_step/sec: 487.843
INFO:tensorflow:loss = 3840.3052, step = 18101 (0.207 sec)
INFO:tensorflow:global_step/sec: 360.971
INFO:tensorflow:loss = 3528.114, step = 18201 (0.277 sec)
INFO:tensorflow:global_step/sec: 389.903
INFO:tensorflow:loss = 5389.16, step = 18301 (0.256 sec)
INFO:tensorflow:global_step/sec: 470.386
INFO:tensorflow:loss = 4320.253, step = 18401 (0.210 sec)
INFO:tensorflow:global_step/sec: 478.822
INFO:tensorflow:loss = 7631.6104, step = 18501 (0.212 sec)
INFO:tensorflow:global_step/sec: 554.699
INFO:tensorflow:loss = 5169.927, step = 18601 (0.177 sec)
INFO:tensorflow:global_step/sec: 565.966
INFO:tensorflow:loss = 3669.042, step = 18701 (0.177 sec)
INFO:tensorflow:global_step/sec: 384.36
INFO:tensorflow:loss = 4044.535, step = 18801 (0.262 sec)
INFO:tensorflow:global_step/sec: 391.002
INFO:tensorflow:loss = 3768.8938, step = 18901 (0.254 sec)
INFO:tensorflow:global_step/sec: 499.62
INFO:tensorflow:loss = 5151.9043, step = 19001 (0.203 sec)
INFO:tensorflow:global_step/sec: 521.428
INFO:tensorflow:loss = 4927.2476, step = 19101 (0.191 sec)
INFO:tensorflow:global_step/sec: 456.784
INFO:tensorflow:loss = 6653.1714, step = 19201 (0.216 sec)
INFO:tensorflow:global_step/sec: 449.305
INFO:tensorflow:loss = 5210.455, step = 19301 (0.223 sec)
INFO:tensorflow:global_step/sec: 538.251
INFO:tensorflow:loss = 3470.4531, step = 19401 (0.186 sec)
INFO:tensorflow:global_step/sec: 419.939
INFO:tensorflow:loss = 4187.2314, step = 19501 (0.240 sec)
INFO:tensorflow:global_step/sec: 324.793
INFO:tensorflow:loss = 4155.7354, step = 19601 (0.306 sec)
INFO:tensorflow:global_step/sec: 458.222
INFO:tensorflow:loss = 4642.956, step = 19701 (0.221 sec)
INFO:tensorflow:global_step/sec: 539.276
INFO:tensorflow:loss = 5173.722, step = 19801 (0.184 sec)
INFO:tensorflow:global_step/sec: 463.3
INFO:tensorflow:loss = 6550.7397, step = 19901 (0.215 sec)
INFO:tensorflow:Saving checkpoints for 20000 into /var/folders/55/qkrngbr949x1jzs0c0dt70wc0000gn/T/tmp6aleB_/model.ckpt.
INFO:tensorflow:Loss for final step: 6522.2236.
Out[91]:
<tensorflow.python.estimator.canned.dnn.DNNRegressor at 0x11a60e1d0>
In [92]:
input_fn_test = tf.estimator.inputs.pandas_input_fn(
    x = pd.DataFrame({
        "Age" : test["Age"].values,
        "MP" : test["MP"].values,
        "G" : test["G"].values
    }),
    y = pd.Series(test.PTS.values),
    shuffle=False
)
evaluation = estimator.evaluate(input_fn=input_fn_test)
loss_score = evaluation["loss"]
print("Loss: {0:f}".format(loss_score))
INFO:tensorflow:Calling model_fn.
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Starting evaluation at 2018-05-09-23:46:48
INFO:tensorflow:Graph was finalized.
INFO:tensorflow:Restoring parameters from /var/folders/55/qkrngbr949x1jzs0c0dt70wc0000gn/T/tmp6aleB_/model.ckpt-20000
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
INFO:tensorflow:Finished evaluation at 2018-05-09-23:46:48
INFO:tensorflow:Saving dict for global step 20000: average_loss = 21.1875, global_step = 20000, loss = 2245.875
Loss: 2245.875000
In [93]:
import itertools

input_fn_predict = tf.estimator.inputs.pandas_input_fn(
    x = pd.DataFrame({
        "Age" : test["Age"].values,
        "MP" : test["MP"].values,
        "G" : test["G"].values
    }),
    y=None, # we are predicting
    shuffle=False
)

predictions = estimator.predict(input_fn=input_fn_predict)
predictions = list(p["predictions"][0] for p in predictions)
INFO:tensorflow:Calling model_fn.
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Graph was finalized.
INFO:tensorflow:Restoring parameters from /var/folders/55/qkrngbr949x1jzs0c0dt70wc0000gn/T/tmp6aleB_/model.ckpt-20000
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
In [94]:
%matplotlib inline

import matplotlib.pyplot as plt
plt.figure(figsize=(10,10))
plt.plot(test.PTS.values)
plt.plot(predictions)
Out[94]:
[<matplotlib.lines.Line2D at 0x119f38210>]
In [95]:
delta=test.PTS-predictions
np.abs(np.mean(delta)).round() # mean prediction error
Out[95]:
1.0
In [96]:
plt.plot(stats.Age, stats.PTS)
plt.show()
In [100]:
plt.scatter(stats["Age"], stats["PTS"])
plt.show()