Dogs

In [1]:
# For neural networks.
import keras as kr
# For data frames.
import pandas as pd
# For numerical arrays.
import numpy as np
# For preprocessing data.
import sklearn.preprocessing as pre
# For splitting data sets.
import sklearn.model_selection as mod
# For whitening.
import sklearn.decomposition as dec
Using TensorFlow backend.

Preparing

In [2]:
df = pd.read_csv("https://raw.githubusercontent.com/ianmcloughlin/datasets/master/dogs.csv")
df
Out[2]:
pure age weight height lifespan
0 True 3 7.94 49.6 15
1 True 7 5.05 63.5 17
2 True 6 16.15 68.2 11
3 False 3 15.50 64.7 12
4 False 3 12.17 59.7 14
... ... ... ... ... ...
95 False 4 20.76 52.2 10
96 False 4 17.40 47.5 11
97 False 6 15.60 51.4 12
98 False 3 8.37 54.1 16
99 True 7 9.09 50.3 14

100 rows × 5 columns

In [3]:
pureenc = pre.LabelBinarizer()
pureenc.fit(df['pure'])
df['pureenc'] = pureenc.transform(df['pure'])
In [4]:
x = df[['pureenc', 'age', 'weight', 'height']]
y = df['lifespan']
In [5]:
x
Out[5]:
pureenc age weight height
0 1 3 7.94 49.6
1 1 7 5.05 63.5
2 1 6 16.15 68.2
3 0 3 15.50 64.7
4 0 3 12.17 59.7
... ... ... ... ...
95 0 4 20.76 52.2
96 0 4 17.40 47.5
97 0 6 15.60 51.4
98 0 3 8.37 54.1
99 1 7 9.09 50.3

100 rows × 4 columns

In [6]:
y
Out[6]:
0     15
1     17
2     11
3     12
4     14
      ..
95    10
96    11
97    12
98    16
99    14
Name: lifespan, Length: 100, dtype: int64
In [7]:
x_train, x_test, y_train, y_test = mod.train_test_split(x, y, test_size=0.3)

Building and training

In [8]:
m = kr.models.Sequential()

m.add(kr.layers.Dense(20, input_dim=4, activation="relu"))
m.add(kr.layers.Dense(1, activation="linear"))

m.compile(loss="mean_squared_error", optimizer="adam")
WARNING:tensorflow:From C:\Users\mclou\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:74: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

WARNING:tensorflow:From C:\Users\mclou\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:517: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

WARNING:tensorflow:From C:\Users\mclou\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:4138: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.

WARNING:tensorflow:From C:\Users\mclou\Anaconda3\lib\site-packages\keras\optimizers.py:790: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.

In [9]:
m.fit(x_train, y_train, epochs=100, batch_size=10)
WARNING:tensorflow:From C:\Users\mclou\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:986: The name tf.assign_add is deprecated. Please use tf.compat.v1.assign_add instead.

WARNING:tensorflow:From C:\Users\mclou\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py:973: The name tf.assign is deprecated. Please use tf.compat.v1.assign instead.

Epoch 1/100
70/70 [==============================] - 1s 20ms/step - loss: 82.2761
Epoch 2/100
70/70 [==============================] - 0s 692us/step - loss: 67.1725
Epoch 3/100
70/70 [==============================] - 0s 422us/step - loss: 53.3654
Epoch 4/100
70/70 [==============================] - 0s 289us/step - loss: 41.6396
Epoch 5/100
70/70 [==============================] - 0s 946us/step - loss: 31.3539
Epoch 6/100
70/70 [==============================] - 0s 522us/step - loss: 23.0326
Epoch 7/100
70/70 [==============================] - 0s 357us/step - loss: 17.3949
Epoch 8/100
70/70 [==============================] - 0s 557us/step - loss: 13.7291
Epoch 9/100
70/70 [==============================] - 0s 390us/step - loss: 11.4647
Epoch 10/100
70/70 [==============================] - 0s 576us/step - loss: 10.7647
Epoch 11/100
70/70 [==============================] - ETA: 0s - loss: 10.29 - 0s 667us/step - loss: 10.5220
Epoch 12/100
70/70 [==============================] - 0s 435us/step - loss: 10.4761
Epoch 13/100
70/70 [==============================] - 0s 459us/step - loss: 10.3777
Epoch 14/100
70/70 [==============================] - 0s 418us/step - loss: 10.3235
Epoch 15/100
70/70 [==============================] - 0s 338us/step - loss: 10.2707
Epoch 16/100
70/70 [==============================] - 0s 411us/step - loss: 10.2266
Epoch 17/100
70/70 [==============================] - 0s 497us/step - loss: 10.1489
Epoch 18/100
70/70 [==============================] - 0s 484us/step - loss: 10.0842
Epoch 19/100
70/70 [==============================] - 0s 302us/step - loss: 10.0381
Epoch 20/100
70/70 [==============================] - 0s 266us/step - loss: 9.9915
Epoch 21/100
70/70 [==============================] - 0s 247us/step - loss: 9.9914
Epoch 22/100
70/70 [==============================] - 0s 215us/step - loss: 9.9310
Epoch 23/100
70/70 [==============================] - 0s 247us/step - loss: 9.8634
Epoch 24/100
70/70 [==============================] - 0s 317us/step - loss: 9.8128
Epoch 25/100
70/70 [==============================] - 0s 280us/step - loss: 9.7799
Epoch 26/100
70/70 [==============================] - 0s 447us/step - loss: 9.7363
Epoch 27/100
70/70 [==============================] - 0s 382us/step - loss: 9.7200
Epoch 28/100
70/70 [==============================] - 0s 317us/step - loss: 9.6617
Epoch 29/100
70/70 [==============================] - 0s 462us/step - loss: 9.6107
Epoch 30/100
70/70 [==============================] - 0s 360us/step - loss: 9.6162
Epoch 31/100
70/70 [==============================] - 0s 433us/step - loss: 9.5384
Epoch 32/100
70/70 [==============================] - 0s 283us/step - loss: 9.4969
Epoch 33/100
70/70 [==============================] - 0s 331us/step - loss: 9.4572
Epoch 34/100
70/70 [==============================] - 0s 495us/step - loss: 9.4314
Epoch 35/100
70/70 [==============================] - 0s 318us/step - loss: 9.3960
Epoch 36/100
70/70 [==============================] - 0s 357us/step - loss: 9.3735
Epoch 37/100
70/70 [==============================] - 0s 484us/step - loss: 9.3285
Epoch 38/100
70/70 [==============================] - 0s 338us/step - loss: 9.3046
Epoch 39/100
70/70 [==============================] - 0s 300us/step - loss: 9.2933
Epoch 40/100
70/70 [==============================] - 0s 237us/step - loss: 9.2556
Epoch 41/100
70/70 [==============================] - 0s 433us/step - loss: 9.2031
Epoch 42/100
70/70 [==============================] - 0s 483us/step - loss: 9.1793
Epoch 43/100
70/70 [==============================] - 0s 469us/step - loss: 9.1638
Epoch 44/100
70/70 [==============================] - 0s 298us/step - loss: 9.1685
Epoch 45/100
70/70 [==============================] - 0s 396us/step - loss: 9.0885
Epoch 46/100
70/70 [==============================] - 0s 267us/step - loss: 9.0598
Epoch 47/100
70/70 [==============================] - 0s 471us/step - loss: 9.0490
Epoch 48/100
70/70 [==============================] - 0s 460us/step - loss: 9.0071
Epoch 49/100
70/70 [==============================] - 0s 445us/step - loss: 9.0192
Epoch 50/100
70/70 [==============================] - 0s 745us/step - loss: 8.9426
Epoch 51/100
70/70 [==============================] - 0s 228us/step - loss: 8.9896
Epoch 52/100
70/70 [==============================] - 0s 373us/step - loss: 8.9232
Epoch 53/100
70/70 [==============================] - 0s 498us/step - loss: 8.8778
Epoch 54/100
70/70 [==============================] - 0s 518us/step - loss: 8.8944
Epoch 55/100
70/70 [==============================] - 0s 245us/step - loss: 8.8366
Epoch 56/100
70/70 [==============================] - 0s 487us/step - loss: 8.8115
Epoch 57/100
70/70 [==============================] - 0s 305us/step - loss: 8.7740
Epoch 58/100
70/70 [==============================] - 0s 429us/step - loss: 8.7726
Epoch 59/100
70/70 [==============================] - 0s 328us/step - loss: 8.7519
Epoch 60/100
70/70 [==============================] - 0s 215us/step - loss: 8.8279
Epoch 61/100
70/70 [==============================] - 0s 192us/step - loss: 8.7753
Epoch 62/100
70/70 [==============================] - 0s 782us/step - loss: 8.6782
Epoch 63/100
70/70 [==============================] - 0s 311us/step - loss: 8.6576
Epoch 64/100
70/70 [==============================] - 0s 731us/step - loss: 8.6372
Epoch 65/100
70/70 [==============================] - 0s 229us/step - loss: 8.6175
Epoch 66/100
70/70 [==============================] - 0s 250us/step - loss: 8.6006
Epoch 67/100
70/70 [==============================] - 0s 444us/step - loss: 8.5786
Epoch 68/100
70/70 [==============================] - 0s 503us/step - loss: 8.5650
Epoch 69/100
70/70 [==============================] - 0s 220us/step - loss: 8.5685
Epoch 70/100
70/70 [==============================] - 0s 468us/step - loss: 8.5482
Epoch 71/100
70/70 [==============================] - 0s 236us/step - loss: 8.5696
Epoch 72/100
70/70 [==============================] - 0s 760us/step - loss: 8.4903
Epoch 73/100
70/70 [==============================] - 0s 260us/step - loss: 8.4781
Epoch 74/100
70/70 [==============================] - 0s 208us/step - loss: 8.4704
Epoch 75/100
70/70 [==============================] - 0s 565us/step - loss: 8.4438
Epoch 76/100
70/70 [==============================] - 0s 344us/step - loss: 8.4287
Epoch 77/100
70/70 [==============================] - 0s 513us/step - loss: 8.4249
Epoch 78/100
70/70 [==============================] - 0s 763us/step - loss: 8.4753
Epoch 79/100
70/70 [==============================] - 0s 432us/step - loss: 8.4190
Epoch 80/100
70/70 [==============================] - 0s 357us/step - loss: 8.4153
Epoch 81/100
70/70 [==============================] - 0s 695us/step - loss: 8.4126
Epoch 82/100
70/70 [==============================] - 0s 382us/step - loss: 8.3536
Epoch 83/100
70/70 [==============================] - 0s 266us/step - loss: 8.3587
Epoch 84/100
70/70 [==============================] - 0s 350us/step - loss: 8.3529
Epoch 85/100
70/70 [==============================] - 0s 247us/step - loss: 8.3182
Epoch 86/100
70/70 [==============================] - 0s 263us/step - loss: 8.3057
Epoch 87/100
70/70 [==============================] - 0s 756us/step - loss: 8.3287
Epoch 88/100
70/70 [==============================] - 0s 236us/step - loss: 8.3327
Epoch 89/100
70/70 [==============================] - 0s 167us/step - loss: 8.3229
Epoch 90/100
70/70 [==============================] - 0s 280us/step - loss: 8.2677
Epoch 91/100
70/70 [==============================] - 0s 209us/step - loss: 8.2756
Epoch 92/100
70/70 [==============================] - 0s 242us/step - loss: 8.2387
Epoch 93/100
70/70 [==============================] - 0s 234us/step - loss: 8.2565
Epoch 94/100
70/70 [==============================] - 0s 248us/step - loss: 8.2692
Epoch 95/100
70/70 [==============================] - 0s 499us/step - loss: 8.2066
Epoch 96/100
70/70 [==============================] - 0s 833us/step - loss: 8.2100
Epoch 97/100
70/70 [==============================] - 0s 208us/step - loss: 8.1870
Epoch 98/100
70/70 [==============================] - 0s 426us/step - loss: 8.2335
Epoch 99/100
70/70 [==============================] - 0s 264us/step - loss: 8.2002
Epoch 100/100
70/70 [==============================] - 0s 256us/step - loss: 8.2091
Out[9]:
<keras.callbacks.History at 0x26df76a0248>
In [10]:
m.predict(x_test).round().T
Out[10]:
array([[11., 11., 12.,  8., 12., 10.,  9.,  8., 11., 16.,  9.,  8., 13.,
        16., 13., 13., 14., 13., 13., 12., 11., 13., 14., 18., 11., 12.,
         9., 10., 12., 12.]], dtype=float32)
In [11]:
y_test.as_matrix().astype(np.float32)
C:\Users\mclou\Anaconda3\lib\site-packages\ipykernel_launcher.py:1: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.
  """Entry point for launching an IPython kernel.
Out[11]:
array([11., 10., 18., 12., 10., 11., 11.,  9., 12., 13., 15., 10., 14.,
       17., 19., 15., 10., 16., 14., 10., 14., 12., 16., 17., 12., 16.,
       10., 16., 15., 11.], dtype=float32)
In [12]:
m.evaluate(x_test, y_test)
30/30 [==============================] - 0s 5ms/step
Out[12]:
8.581741333007812

Scaling

In [13]:
scaler = pre.StandardScaler()
scaler.fit(x_train)
x_train_scaled = scaler.transform(x_train)
In [14]:
m = kr.models.Sequential()

m.add(kr.layers.Dense(20, input_dim=4, activation="relu"))
m.add(kr.layers.Dense(1, activation="linear"))

m.compile(loss="mean_squared_error", optimizer="adam")
In [15]:
m.fit(x_train_scaled, y_train, epochs=100, batch_size=10)
Epoch 1/100
70/70 [==============================] - 1s 13ms/step - loss: 163.2016
Epoch 2/100
70/70 [==============================] - 0s 427us/step - loss: 161.3515
Epoch 3/100
70/70 [==============================] - 0s 218us/step - loss: 159.5960
Epoch 4/100
70/70 [==============================] - 0s 318us/step - loss: 157.8161
Epoch 5/100
70/70 [==============================] - 0s 395us/step - loss: 156.0170
Epoch 6/100
70/70 [==============================] - 0s 237us/step - loss: 154.2581
Epoch 7/100
70/70 [==============================] - 0s 209us/step - loss: 152.4640
Epoch 8/100
70/70 [==============================] - 0s 229us/step - loss: 150.7070
Epoch 9/100
70/70 [==============================] - 0s 271us/step - loss: 149.0008
Epoch 10/100
70/70 [==============================] - 0s 229us/step - loss: 147.2024
Epoch 11/100
70/70 [==============================] - 0s 176us/step - loss: 145.4305
Epoch 12/100
70/70 [==============================] - 0s 319us/step - loss: 143.6739
Epoch 13/100
70/70 [==============================] - 0s 315us/step - loss: 141.9573
Epoch 14/100
70/70 [==============================] - 0s 169us/step - loss: 140.1693
Epoch 15/100
70/70 [==============================] - 0s 235us/step - loss: 138.4405
Epoch 16/100
70/70 [==============================] - 0s 197us/step - loss: 136.6349
Epoch 17/100
70/70 [==============================] - 0s 239us/step - loss: 134.8403
Epoch 18/100
70/70 [==============================] - 0s 169us/step - loss: 133.0442
Epoch 19/100
70/70 [==============================] - 0s 361us/step - loss: 131.2053
Epoch 20/100
70/70 [==============================] - 0s 270us/step - loss: 129.4241
Epoch 21/100
70/70 [==============================] - 0s 319us/step - loss: 127.5999
Epoch 22/100
70/70 [==============================] - 0s 364us/step - loss: 125.7326
Epoch 23/100
70/70 [==============================] - 0s 354us/step - loss: 123.8895
Epoch 24/100
70/70 [==============================] - 0s 346us/step - loss: 122.0276
Epoch 25/100
70/70 [==============================] - 0s 335us/step - loss: 120.0885
Epoch 26/100
70/70 [==============================] - 0s 433us/step - loss: 118.2117
Epoch 27/100
70/70 [==============================] - 0s 229us/step - loss: 116.2602
Epoch 28/100
70/70 [==============================] - 0s 309us/step - loss: 114.3297
Epoch 29/100
70/70 [==============================] - 0s 280us/step - loss: 112.3752
Epoch 30/100
70/70 [==============================] - 0s 181us/step - loss: 110.3743
Epoch 31/100
70/70 [==============================] - 0s 462us/step - loss: 108.3487
Epoch 32/100
70/70 [==============================] - 0s 240us/step - loss: 106.3910
Epoch 33/100
70/70 [==============================] - ETA: 0s - loss: 108.608 - 0s 321us/step - loss: 104.3074
Epoch 34/100
70/70 [==============================] - 0s 95us/step - loss: 102.3108
Epoch 35/100
70/70 [==============================] - 0s 150us/step - loss: 100.1895
Epoch 36/100
70/70 [==============================] - 0s 268us/step - loss: 98.2057
Epoch 37/100
70/70 [==============================] - 0s 231us/step - loss: 96.0959
Epoch 38/100
70/70 [==============================] - 0s 299us/step - loss: 94.0763
Epoch 39/100
70/70 [==============================] - 0s 328us/step - loss: 91.9584
Epoch 40/100
70/70 [==============================] - 0s 349us/step - loss: 89.8344
Epoch 41/100
70/70 [==============================] - 0s 217us/step - loss: 87.7292
Epoch 42/100
70/70 [==============================] - 0s 157us/step - loss: 85.6332
Epoch 43/100
70/70 [==============================] - 0s 281us/step - loss: 83.5132
Epoch 44/100
70/70 [==============================] - 0s 328us/step - loss: 81.4320
Epoch 45/100
70/70 [==============================] - 0s 353us/step - loss: 79.3205
Epoch 46/100
70/70 [==============================] - 0s 379us/step - loss: 77.2475
Epoch 47/100
70/70 [==============================] - 0s 462us/step - loss: 75.2589
Epoch 48/100
70/70 [==============================] - 0s 251us/step - loss: 73.1112
Epoch 49/100
70/70 [==============================] - 0s 298us/step - loss: 71.0867
Epoch 50/100
70/70 [==============================] - 0s 240us/step - loss: 69.0887
Epoch 51/100
70/70 [==============================] - ETA: 0s - loss: 81.96 - 0s 306us/step - loss: 67.0896
Epoch 52/100
70/70 [==============================] - 0s 232us/step - loss: 65.0617
Epoch 53/100
70/70 [==============================] - 0s 289us/step - loss: 63.0843
Epoch 54/100
70/70 [==============================] - 0s 137us/step - loss: 61.1856
Epoch 55/100
70/70 [==============================] - 0s 321us/step - loss: 59.2197
Epoch 56/100
70/70 [==============================] - 0s 282us/step - loss: 57.3756
Epoch 57/100
70/70 [==============================] - 0s 210us/step - loss: 55.5002
Epoch 58/100
70/70 [==============================] - 0s 110us/step - loss: 53.6478
Epoch 59/100
70/70 [==============================] - 0s 113us/step - loss: 51.8574
Epoch 60/100
70/70 [==============================] - 0s 236us/step - loss: 50.0846
Epoch 61/100
70/70 [==============================] - 0s 292us/step - loss: 48.3359
Epoch 62/100
70/70 [==============================] - 0s 355us/step - loss: 46.6628
Epoch 63/100
70/70 [==============================] - 0s 267us/step - loss: 44.9722
Epoch 64/100
70/70 [==============================] - 0s 242us/step - loss: 43.3070
Epoch 65/100
70/70 [==============================] - 0s 196us/step - loss: 41.7246
Epoch 66/100
70/70 [==============================] - 0s 339us/step - loss: 40.1180
Epoch 67/100
70/70 [==============================] - 0s 350us/step - loss: 38.5942
Epoch 68/100
70/70 [==============================] - 0s 339us/step - loss: 37.0664
Epoch 69/100
70/70 [==============================] - 0s 369us/step - loss: 35.6249
Epoch 70/100
70/70 [==============================] - 0s 219us/step - loss: 34.1969
Epoch 71/100
70/70 [==============================] - 0s 254us/step - loss: 32.8341
Epoch 72/100
70/70 [==============================] - 0s 255us/step - loss: 31.4789
Epoch 73/100
70/70 [==============================] - 0s 381us/step - loss: 30.1423
Epoch 74/100
70/70 [==============================] - 0s 346us/step - loss: 28.8645
Epoch 75/100
70/70 [==============================] - 0s 292us/step - loss: 27.6535
Epoch 76/100
70/70 [==============================] - 0s 266us/step - loss: 26.4875
Epoch 77/100
70/70 [==============================] - 0s 226us/step - loss: 25.3049
Epoch 78/100
70/70 [==============================] - 0s 467us/step - loss: 24.1778
Epoch 79/100
70/70 [==============================] - 0s 169us/step - loss: 23.1534
Epoch 80/100
70/70 [==============================] - 0s 256us/step - loss: 22.0908
Epoch 81/100
70/70 [==============================] - 0s 161us/step - loss: 21.0853
Epoch 82/100
70/70 [==============================] - 0s 296us/step - loss: 20.1253
Epoch 83/100
70/70 [==============================] - 0s 211us/step - loss: 19.2208
Epoch 84/100
70/70 [==============================] - 0s 175us/step - loss: 18.3440
Epoch 85/100
70/70 [==============================] - 0s 282us/step - loss: 17.4738
Epoch 86/100
70/70 [==============================] - 0s 343us/step - loss: 16.6541
Epoch 87/100
70/70 [==============================] - 0s 296us/step - loss: 15.8642
Epoch 88/100
70/70 [==============================] - 0s 296us/step - loss: 15.0896
Epoch 89/100
70/70 [==============================] - 0s 231us/step - loss: 14.3810
Epoch 90/100
70/70 [==============================] - 0s 58us/step - loss: 13.7196
Epoch 91/100
70/70 [==============================] - 0s 172us/step - loss: 13.0264
Epoch 92/100
70/70 [==============================] - 0s 529us/step - loss: 12.4084
Epoch 93/100
70/70 [==============================] - 0s 248us/step - loss: 11.8022
Epoch 94/100
70/70 [==============================] - 0s 315us/step - loss: 11.2260
Epoch 95/100
70/70 [==============================] - 0s 293us/step - loss: 10.6975
Epoch 96/100
70/70 [==============================] - 0s 194us/step - loss: 10.1607
Epoch 97/100
70/70 [==============================] - 0s 440us/step - loss: 9.6727
Epoch 98/100
70/70 [==============================] - 0s 391us/step - loss: 9.2124
Epoch 99/100
70/70 [==============================] - 0s 471us/step - loss: 8.7634
Epoch 100/100
70/70 [==============================] - 0s 264us/step - loss: 8.3478
Out[15]:
<keras.callbacks.History at 0x26df837da08>
In [16]:
x_test_scaled = scaler.transform(x_test)
m.predict(x_test_scaled).round().T
Out[16]:
array([[ 9.,  8., 17., 12., 12.,  8., 13.,  6.,  9., 13., 15.,  9., 12.,
        13., 17., 16., 11., 12., 11.,  9., 14., 10., 10., 13.,  7., 15.,
         8., 16., 13.,  6.]], dtype=float32)
In [17]:
y_test.as_matrix().astype(np.float32)
C:\Users\mclou\Anaconda3\lib\site-packages\ipykernel_launcher.py:1: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.
  """Entry point for launching an IPython kernel.
Out[17]:
array([11., 10., 18., 12., 10., 11., 11.,  9., 12., 13., 15., 10., 14.,
       17., 19., 15., 10., 16., 14., 10., 14., 12., 16., 17., 12., 16.,
       10., 16., 15., 11.], dtype=float32)
In [18]:
m.evaluate(x_test_scaled, y_test)
30/30 [==============================] - 0s 3ms/step
Out[18]:
7.1724853515625

Whitening

In [19]:
pca = dec.PCA(n_components=4, whiten=True)
pca.fit(x_train)
x_train_white = pd.DataFrame(pca.transform(x_train), columns=x.columns)
x_train_white
Out[19]:
pureenc age weight height
0 0.351231 -0.023006 -1.079929 -0.951374
1 -0.012764 -1.157900 -1.195173 -1.064293
2 0.941085 0.359779 -0.967660 -0.936212
3 0.743577 -1.088204 -0.515159 -1.113794
4 -0.611093 2.285833 -0.555464 -0.658486
... ... ... ... ...
65 0.894656 -1.621427 -0.512884 0.820352
66 0.197414 -0.899546 -0.027932 0.917350
67 -1.524036 -0.242519 -0.828242 -0.905044
68 -1.895772 -0.433372 0.782178 1.032982
69 -0.156841 -0.437033 1.055249 0.947214

70 rows × 4 columns

In [20]:
m = kr.models.Sequential()

m.add(kr.layers.Dense(100, input_dim=4, activation="tanh"))
m.add(kr.layers.Dense(1, activation="linear"))

m.compile(loss="mean_squared_error", optimizer="adam")
In [21]:
m.fit(x_train_white, y_train, epochs=100, batch_size=10)
Epoch 1/100
70/70 [==============================] - 1s 11ms/step - loss: 153.6590
Epoch 2/100
70/70 [==============================] - 0s 267us/step - loss: 151.0955
Epoch 3/100
70/70 [==============================] - 0s 292us/step - loss: 148.5965
Epoch 4/100
70/70 [==============================] - 0s 266us/step - loss: 146.1226
Epoch 5/100
70/70 [==============================] - 0s 179us/step - loss: 143.5247
Epoch 6/100
70/70 [==============================] - 0s 341us/step - loss: 141.0165
Epoch 7/100
70/70 [==============================] - 0s 271us/step - loss: 138.2976
Epoch 8/100
70/70 [==============================] - 0s 253us/step - loss: 135.4856
Epoch 9/100
70/70 [==============================] - 0s 147us/step - loss: 132.6652
Epoch 10/100
70/70 [==============================] - 0s 286us/step - loss: 129.5296
Epoch 11/100
70/70 [==============================] - 0s 334us/step - loss: 126.3123
Epoch 12/100
70/70 [==============================] - 0s 201us/step - loss: 122.7954
Epoch 13/100
70/70 [==============================] - 0s 91us/step - loss: 119.1640
Epoch 14/100
70/70 [==============================] - 0s 292us/step - loss: 115.3656
Epoch 15/100
70/70 [==============================] - 0s 304us/step - loss: 111.4007
Epoch 16/100
70/70 [==============================] - 0s 468us/step - loss: 107.0749
Epoch 17/100
70/70 [==============================] - 0s 366us/step - loss: 102.7457
Epoch 18/100
70/70 [==============================] - 0s 208us/step - loss: 98.2631
Epoch 19/100
70/70 [==============================] - 0s 250us/step - loss: 93.3432
Epoch 20/100
70/70 [==============================] - 0s 210us/step - loss: 88.4370
Epoch 21/100
70/70 [==============================] - 0s 334us/step - loss: 83.4655
Epoch 22/100
70/70 [==============================] - 0s 423us/step - loss: 78.4366
Epoch 23/100
70/70 [==============================] - 0s 480us/step - loss: 73.2393
Epoch 24/100
70/70 [==============================] - 0s 287us/step - loss: 68.2374
Epoch 25/100
70/70 [==============================] - 0s 266us/step - loss: 63.0511
Epoch 26/100
70/70 [==============================] - 0s 320us/step - loss: 58.0331
Epoch 27/100
70/70 [==============================] - 0s 214us/step - loss: 53.0649
Epoch 28/100
70/70 [==============================] - 0s 256us/step - loss: 48.2517
Epoch 29/100
70/70 [==============================] - 0s 473us/step - loss: 43.6102
Epoch 30/100
70/70 [==============================] - 0s 177us/step - loss: 39.1670
Epoch 31/100
70/70 [==============================] - 0s 443us/step - loss: 34.9231
Epoch 32/100
70/70 [==============================] - 0s 289us/step - loss: 31.0093
Epoch 33/100
70/70 [==============================] - 0s 412us/step - loss: 27.2159
Epoch 34/100
70/70 [==============================] - 0s 219us/step - loss: 23.6932
Epoch 35/100
70/70 [==============================] - 0s 516us/step - loss: 20.5628
Epoch 36/100
70/70 [==============================] - 0s 278us/step - loss: 17.6994
Epoch 37/100
70/70 [==============================] - 0s 308us/step - loss: 15.0863
Epoch 38/100
70/70 [==============================] - 0s 272us/step - loss: 12.7628
Epoch 39/100
70/70 [==============================] - 0s 467us/step - loss: 10.7408
Epoch 40/100
70/70 [==============================] - 0s 218us/step - loss: 8.9322
Epoch 41/100
70/70 [==============================] - 0s 469us/step - loss: 7.3697
Epoch 42/100
70/70 [==============================] - 0s 240us/step - loss: 6.0537
Epoch 43/100
70/70 [==============================] - 0s 335us/step - loss: 4.9524
Epoch 44/100
70/70 [==============================] - 0s 132us/step - loss: 3.9987
Epoch 45/100
70/70 [==============================] - 0s 320us/step - loss: 3.2156
Epoch 46/100
70/70 [==============================] - 0s 237us/step - loss: 2.5836
Epoch 47/100
70/70 [==============================] - 0s 251us/step - loss: 2.0591
Epoch 48/100
70/70 [==============================] - 0s 307us/step - loss: 1.6398
Epoch 49/100
70/70 [==============================] - 0s 151us/step - loss: 1.3177
Epoch 50/100
70/70 [==============================] - 0s 266us/step - loss: 1.0534
Epoch 51/100
70/70 [==============================] - 0s 524us/step - loss: 0.8552
Epoch 52/100
70/70 [==============================] - 0s 213us/step - loss: 0.6993
Epoch 53/100
70/70 [==============================] - 0s 162us/step - loss: 0.5739
Epoch 54/100
70/70 [==============================] - 0s 447us/step - loss: 0.4856
Epoch 55/100
70/70 [==============================] - 0s 222us/step - loss: 0.4174
Epoch 56/100
70/70 [==============================] - 0s 272us/step - loss: 0.3645
Epoch 57/100
70/70 [==============================] - 0s 444us/step - loss: 0.3275
Epoch 58/100
70/70 [==============================] - 0s 225us/step - loss: 0.3012
Epoch 59/100
70/70 [==============================] - 0s 259us/step - loss: 0.2790
Epoch 60/100
70/70 [==============================] - 0s 284us/step - loss: 0.2675
Epoch 61/100
70/70 [==============================] - 0s 250us/step - loss: 0.2567
Epoch 62/100
70/70 [==============================] - 0s 432us/step - loss: 0.2487
Epoch 63/100
70/70 [==============================] - 0s 263us/step - loss: 0.2424
Epoch 64/100
70/70 [==============================] - 0s 312us/step - loss: 0.2401
Epoch 65/100
70/70 [==============================] - 0s 238us/step - loss: 0.2366
Epoch 66/100
70/70 [==============================] - 0s 253us/step - loss: 0.2347
Epoch 67/100
70/70 [==============================] - 0s 155us/step - loss: 0.2338
Epoch 68/100
70/70 [==============================] - 0s 286us/step - loss: 0.2332
Epoch 69/100
70/70 [==============================] - 0s 286us/step - loss: 0.2313
Epoch 70/100
70/70 [==============================] - 0s 311us/step - loss: 0.2301
Epoch 71/100
70/70 [==============================] - 0s 292us/step - loss: 0.2296
Epoch 72/100
70/70 [==============================] - 0s 242us/step - loss: 0.2294
Epoch 73/100
70/70 [==============================] - 0s 660us/step - loss: 0.2289
Epoch 74/100
70/70 [==============================] - 0s 236us/step - loss: 0.2293
Epoch 75/100
70/70 [==============================] - 0s 200us/step - loss: 0.2282
Epoch 76/100
70/70 [==============================] - 0s 421us/step - loss: 0.2287
Epoch 77/100
70/70 [==============================] - 0s 483us/step - loss: 0.2280
Epoch 78/100
70/70 [==============================] - 0s 228us/step - loss: 0.2277
Epoch 79/100
70/70 [==============================] - 0s 354us/step - loss: 0.2274
Epoch 80/100
70/70 [==============================] - 0s 289us/step - loss: 0.2262
Epoch 81/100
70/70 [==============================] - 0s 247us/step - loss: 0.2268
Epoch 82/100
70/70 [==============================] - 0s 181us/step - loss: 0.2268
Epoch 83/100
70/70 [==============================] - 0s 293us/step - loss: 0.2261
Epoch 84/100
70/70 [==============================] - 0s 467us/step - loss: 0.2253
Epoch 85/100
70/70 [==============================] - 0s 243us/step - loss: 0.2247
Epoch 86/100
70/70 [==============================] - 0s 557us/step - loss: 0.2246
Epoch 87/100
70/70 [==============================] - 0s 279us/step - loss: 0.2250
Epoch 88/100
70/70 [==============================] - 0s 277us/step - loss: 0.2248
Epoch 89/100
70/70 [==============================] - 0s 460us/step - loss: 0.2236
Epoch 90/100
70/70 [==============================] - 0s 961us/step - loss: 0.2232
Epoch 91/100
70/70 [==============================] - 0s 422us/step - loss: 0.2233
Epoch 92/100
70/70 [==============================] - 0s 727us/step - loss: 0.2234
Epoch 93/100
70/70 [==============================] - 0s 366us/step - loss: 0.2226
Epoch 94/100
70/70 [==============================] - 0s 419us/step - loss: 0.2219
Epoch 95/100
70/70 [==============================] - 0s 499us/step - loss: 0.2215
Epoch 96/100
70/70 [==============================] - 0s 586us/step - loss: 0.2214
Epoch 97/100
70/70 [==============================] - 0s 294us/step - loss: 0.2210
Epoch 98/100
70/70 [==============================] - 0s 387us/step - loss: 0.2208
Epoch 99/100
70/70 [==============================] - 0s 402us/step - loss: 0.2212
Epoch 100/100
70/70 [==============================] - 0s 416us/step - loss: 0.2211
Out[21]:
<keras.callbacks.History at 0x26df96f1e08>
In [22]:
x_test_white = scaler.transform(x_test)
m.predict(x_test_white).round().T
Out[22]:
array([[14., 12.,  7., 10., 17., 13., 18., 12., 11., 14., 14., 17.,  7.,
        14., 13., 17., 14., 13., 16., 10., 16.,  6.,  9., 14., 12., 10.,
        10., 11., 15.,  9.]], dtype=float32)
In [23]:
y_test.as_matrix().astype(np.float32)
C:\Users\mclou\Anaconda3\lib\site-packages\ipykernel_launcher.py:1: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.
  """Entry point for launching an IPython kernel.
Out[23]:
array([11., 10., 18., 12., 10., 11., 11.,  9., 12., 13., 15., 10., 14.,
       17., 19., 15., 10., 16., 14., 10., 14., 12., 16., 17., 12., 16.,
       10., 16., 15., 11.], dtype=float32)
In [24]:
m.evaluate(x_test_white, y_test)
30/30 [==============================] - 1s 32ms/step
Out[24]:
19.537107467651367

End