Regression With TensorFlow
In [25]:
Copied!
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
In [26]:
Copied!
X = tf.range(-100, 100, 4)
X
X = tf.range(-100, 100, 4)
X
Out[26]:
<tf.Tensor: shape=(50,), dtype=int32, numpy= array([-100, -96, -92, -88, -84, -80, -76, -72, -68, -64, -60, -56, -52, -48, -44, -40, -36, -32, -28, -24, -20, -16, -12, -8, -4, 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, 96], dtype=int32)>
In [27]:
Copied!
y = X + 10
y
y = X + 10
y
Out[27]:
<tf.Tensor: shape=(50,), dtype=int32, numpy= array([-90, -86, -82, -78, -74, -70, -66, -62, -58, -54, -50, -46, -42, -38, -34, -30, -26, -22, -18, -14, -10, -6, -2, 2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 66, 70, 74, 78, 82, 86, 90, 94, 98, 102, 106], dtype=int32)>
In [28]:
Copied!
X_train = X[:40]
X_test = X[40:]
X_train = X[:40]
X_test = X[40:]
In [29]:
Copied!
X_train, X_test
X_train, X_test
Out[29]:
(<tf.Tensor: shape=(40,), dtype=int32, numpy= array([-100, -96, -92, -88, -84, -80, -76, -72, -68, -64, -60, -56, -52, -48, -44, -40, -36, -32, -28, -24, -20, -16, -12, -8, -4, 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56], dtype=int32)>, <tf.Tensor: shape=(10,), dtype=int32, numpy=array([60, 64, 68, 72, 76, 80, 84, 88, 92, 96], dtype=int32)>)
In [30]:
Copied!
y_train = y[:40]
y_test = y[40:]
y_train = y[:40]
y_test = y[40:]
In [31]:
Copied!
plt.scatter(X, y)
plt.scatter(X, y)
Out[31]:
<matplotlib.collections.PathCollection at 0x7f8c5d722690>
MODEL 1¶
In [32]:
Copied!
# 1. Creating a model
model_1 = tf.keras.Sequential([
tf.keras.layers.Dense(100, activation="relu"),
tf.keras.layers.Dense(100, activation="relu"),
tf.keras.layers.Dense(1)
])
# 2. Compiling a model
model_1.compile(loss=tf.keras.losses.mae,
optimizer=tf.keras.optimizers.Adam(lr=0.01),
metrics=["mae"])
# 3. Model fitting
model_1.fit(X_train, y_train, epochs=200)
# 1. Creating a model
model_1 = tf.keras.Sequential([
tf.keras.layers.Dense(100, activation="relu"),
tf.keras.layers.Dense(100, activation="relu"),
tf.keras.layers.Dense(1)
])
# 2. Compiling a model
model_1.compile(loss=tf.keras.losses.mae,
optimizer=tf.keras.optimizers.Adam(lr=0.01),
metrics=["mae"])
# 3. Model fitting
model_1.fit(X_train, y_train, epochs=200)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/optimizer_v2/optimizer_v2.py:375: UserWarning: The `lr` argument is deprecated, use `learning_rate` instead. "The `lr` argument is deprecated, use `learning_rate` instead.")
Epoch 1/200 2/2 [==============================] - 0s 7ms/step - loss: 33.4998 - mae: 33.4998 Epoch 2/200 2/2 [==============================] - 0s 8ms/step - loss: 14.6662 - mae: 14.6662 Epoch 3/200 2/2 [==============================] - 0s 8ms/step - loss: 5.7571 - mae: 5.7571 Epoch 4/200 2/2 [==============================] - 0s 8ms/step - loss: 10.2666 - mae: 10.2666 Epoch 5/200 2/2 [==============================] - 0s 7ms/step - loss: 5.4345 - mae: 5.4345 Epoch 6/200 2/2 [==============================] - 0s 7ms/step - loss: 5.8424 - mae: 5.8424 Epoch 7/200 2/2 [==============================] - 0s 9ms/step - loss: 6.5238 - mae: 6.5238 Epoch 8/200 2/2 [==============================] - 0s 8ms/step - loss: 7.8366 - mae: 7.8366 Epoch 9/200 2/2 [==============================] - 0s 5ms/step - loss: 4.4315 - mae: 4.4315 Epoch 10/200 2/2 [==============================] - 0s 7ms/step - loss: 6.9566 - mae: 6.9566 Epoch 11/200 2/2 [==============================] - 0s 7ms/step - loss: 6.9313 - mae: 6.9313 Epoch 12/200 2/2 [==============================] - 0s 7ms/step - loss: 7.5538 - mae: 7.5538 Epoch 13/200 2/2 [==============================] - 0s 14ms/step - loss: 5.2471 - mae: 5.2471 Epoch 14/200 2/2 [==============================] - 0s 6ms/step - loss: 6.1510 - mae: 6.1510 Epoch 15/200 2/2 [==============================] - 0s 8ms/step - loss: 7.6283 - mae: 7.6283 Epoch 16/200 2/2 [==============================] - 0s 6ms/step - loss: 4.8112 - mae: 4.8112 Epoch 17/200 2/2 [==============================] - 0s 7ms/step - loss: 4.5546 - mae: 4.5546 Epoch 18/200 2/2 [==============================] - 0s 4ms/step - loss: 4.6694 - mae: 4.6694 Epoch 19/200 2/2 [==============================] - 0s 6ms/step - loss: 4.9823 - mae: 4.9823 Epoch 20/200 2/2 [==============================] - 0s 6ms/step - loss: 3.9814 - mae: 3.9814 Epoch 21/200 2/2 [==============================] - 0s 9ms/step - loss: 4.2304 - mae: 4.2304 Epoch 22/200 2/2 [==============================] - 0s 9ms/step - loss: 4.3159 - mae: 4.3159 Epoch 23/200 2/2 [==============================] - 0s 9ms/step - loss: 3.8669 - mae: 3.8669 Epoch 24/200 2/2 [==============================] - 0s 9ms/step - loss: 4.7890 - mae: 4.7890 Epoch 25/200 2/2 [==============================] - 0s 10ms/step - loss: 3.7393 - mae: 3.7393 Epoch 26/200 2/2 [==============================] - 0s 9ms/step - loss: 3.3427 - mae: 3.3427 Epoch 27/200 2/2 [==============================] - 0s 6ms/step - loss: 3.7530 - mae: 3.7530 Epoch 28/200 2/2 [==============================] - 0s 10ms/step - loss: 3.4674 - mae: 3.4674 Epoch 29/200 2/2 [==============================] - 0s 6ms/step - loss: 3.2236 - mae: 3.2236 Epoch 30/200 2/2 [==============================] - 0s 4ms/step - loss: 3.0503 - mae: 3.0503 Epoch 31/200 2/2 [==============================] - 0s 4ms/step - loss: 3.1492 - mae: 3.1492 Epoch 32/200 2/2 [==============================] - 0s 5ms/step - loss: 3.0918 - mae: 3.0918 Epoch 33/200 2/2 [==============================] - 0s 7ms/step - loss: 4.2897 - mae: 4.2897 Epoch 34/200 2/2 [==============================] - 0s 4ms/step - loss: 5.1382 - mae: 5.1382 Epoch 35/200 2/2 [==============================] - 0s 5ms/step - loss: 2.7321 - mae: 2.7321 Epoch 36/200 2/2 [==============================] - 0s 4ms/step - loss: 3.7811 - mae: 3.7811 Epoch 37/200 2/2 [==============================] - 0s 5ms/step - loss: 3.4870 - mae: 3.4870 Epoch 38/200 2/2 [==============================] - 0s 5ms/step - loss: 4.0065 - mae: 4.0065 Epoch 39/200 2/2 [==============================] - 0s 5ms/step - loss: 2.8087 - mae: 2.8087 Epoch 40/200 2/2 [==============================] - 0s 5ms/step - loss: 5.5579 - mae: 5.5579 Epoch 41/200 2/2 [==============================] - 0s 5ms/step - loss: 3.4942 - mae: 3.4942 Epoch 42/200 2/2 [==============================] - 0s 6ms/step - loss: 4.5331 - mae: 4.5331 Epoch 43/200 2/2 [==============================] - 0s 5ms/step - loss: 3.2288 - mae: 3.2288 Epoch 44/200 2/2 [==============================] - 0s 7ms/step - loss: 2.7930 - mae: 2.7930 Epoch 45/200 2/2 [==============================] - 0s 5ms/step - loss: 2.2368 - mae: 2.2368 Epoch 46/200 2/2 [==============================] - 0s 8ms/step - loss: 2.5162 - mae: 2.5162 Epoch 47/200 2/2 [==============================] - 0s 6ms/step - loss: 1.8075 - mae: 1.8075 Epoch 48/200 2/2 [==============================] - 0s 16ms/step - loss: 1.7967 - mae: 1.7967 Epoch 49/200 2/2 [==============================] - 0s 6ms/step - loss: 3.5144 - mae: 3.5144 Epoch 50/200 2/2 [==============================] - 0s 8ms/step - loss: 1.4333 - mae: 1.4333 Epoch 51/200 2/2 [==============================] - 0s 16ms/step - loss: 2.2264 - mae: 2.2264 Epoch 52/200 2/2 [==============================] - 0s 5ms/step - loss: 2.5455 - mae: 2.5455 Epoch 53/200 2/2 [==============================] - 0s 5ms/step - loss: 3.7465 - mae: 3.7465 Epoch 54/200 2/2 [==============================] - 0s 6ms/step - loss: 2.7280 - mae: 2.7280 Epoch 55/200 2/2 [==============================] - 0s 8ms/step - loss: 4.5768 - mae: 4.5768 Epoch 56/200 2/2 [==============================] - 0s 10ms/step - loss: 4.3048 - mae: 4.3048 Epoch 57/200 2/2 [==============================] - 0s 5ms/step - loss: 3.1470 - mae: 3.1470 Epoch 58/200 2/2 [==============================] - 0s 6ms/step - loss: 4.4435 - mae: 4.4435 Epoch 59/200 2/2 [==============================] - 0s 4ms/step - loss: 1.3467 - mae: 1.3467 Epoch 60/200 2/2 [==============================] - 0s 9ms/step - loss: 2.1156 - mae: 2.1156 Epoch 61/200 2/2 [==============================] - 0s 5ms/step - loss: 1.7453 - mae: 1.7453 Epoch 62/200 2/2 [==============================] - 0s 7ms/step - loss: 0.8955 - mae: 0.8955 Epoch 63/200 2/2 [==============================] - 0s 6ms/step - loss: 1.7791 - mae: 1.7791 Epoch 64/200 2/2 [==============================] - 0s 6ms/step - loss: 1.5303 - mae: 1.5303 Epoch 65/200 2/2 [==============================] - 0s 6ms/step - loss: 2.5697 - mae: 2.5697 Epoch 66/200 2/2 [==============================] - 0s 7ms/step - loss: 4.5673 - mae: 4.5673 Epoch 67/200 2/2 [==============================] - 0s 9ms/step - loss: 2.4660 - mae: 2.4660 Epoch 68/200 2/2 [==============================] - 0s 5ms/step - loss: 2.2682 - mae: 2.2682 Epoch 69/200 2/2 [==============================] - 0s 5ms/step - loss: 2.6227 - mae: 2.6227 Epoch 70/200 2/2 [==============================] - 0s 4ms/step - loss: 1.8975 - mae: 1.8975 Epoch 71/200 2/2 [==============================] - 0s 7ms/step - loss: 1.3195 - mae: 1.3195 Epoch 72/200 2/2 [==============================] - 0s 6ms/step - loss: 1.1433 - mae: 1.1433 Epoch 73/200 2/2 [==============================] - 0s 14ms/step - loss: 1.5640 - mae: 1.5640 Epoch 74/200 2/2 [==============================] - 0s 5ms/step - loss: 0.9789 - mae: 0.9789 Epoch 75/200 2/2 [==============================] - 0s 5ms/step - loss: 1.0397 - mae: 1.0397 Epoch 76/200 2/2 [==============================] - 0s 8ms/step - loss: 1.5036 - mae: 1.5036 Epoch 77/200 2/2 [==============================] - 0s 10ms/step - loss: 1.7913 - mae: 1.7913 Epoch 78/200 2/2 [==============================] - 0s 5ms/step - loss: 1.0374 - mae: 1.0374 Epoch 79/200 2/2 [==============================] - 0s 7ms/step - loss: 2.5242 - mae: 2.5242 Epoch 80/200 2/2 [==============================] - 0s 5ms/step - loss: 1.0206 - mae: 1.0206 Epoch 81/200 2/2 [==============================] - 0s 10ms/step - loss: 0.9791 - mae: 0.9791 Epoch 82/200 2/2 [==============================] - 0s 5ms/step - loss: 1.5257 - mae: 1.5257 Epoch 83/200 2/2 [==============================] - 0s 5ms/step - loss: 0.4607 - mae: 0.4607 Epoch 84/200 2/2 [==============================] - 0s 6ms/step - loss: 0.5927 - mae: 0.5927 Epoch 85/200 2/2 [==============================] - 0s 5ms/step - loss: 0.7238 - mae: 0.7238 Epoch 86/200 2/2 [==============================] - 0s 5ms/step - loss: 0.7476 - mae: 0.7476 Epoch 87/200 2/2 [==============================] - 0s 12ms/step - loss: 0.6609 - mae: 0.6609 Epoch 88/200 2/2 [==============================] - 0s 6ms/step - loss: 0.3275 - mae: 0.3275 Epoch 89/200 2/2 [==============================] - 0s 5ms/step - loss: 1.3446 - mae: 1.3446 Epoch 90/200 2/2 [==============================] - 0s 5ms/step - loss: 0.7690 - mae: 0.7690 Epoch 91/200 2/2 [==============================] - 0s 5ms/step - loss: 2.8775 - mae: 2.8775 Epoch 92/200 2/2 [==============================] - 0s 5ms/step - loss: 0.7588 - mae: 0.7588 Epoch 93/200 2/2 [==============================] - 0s 6ms/step - loss: 5.1250 - mae: 5.1250 Epoch 94/200 2/2 [==============================] - 0s 8ms/step - loss: 3.9512 - mae: 3.9512 Epoch 95/200 2/2 [==============================] - 0s 9ms/step - loss: 2.1860 - mae: 2.1860 Epoch 96/200 2/2 [==============================] - 0s 5ms/step - loss: 3.5597 - mae: 3.5597 Epoch 97/200 2/2 [==============================] - 0s 13ms/step - loss: 1.3250 - mae: 1.3250 Epoch 98/200 2/2 [==============================] - 0s 5ms/step - loss: 4.0799 - mae: 4.0799 Epoch 99/200 2/2 [==============================] - 0s 7ms/step - loss: 3.0083 - mae: 3.0083 Epoch 100/200 2/2 [==============================] - 0s 13ms/step - loss: 2.4633 - mae: 2.4633 Epoch 101/200 2/2 [==============================] - 0s 11ms/step - loss: 3.7092 - mae: 3.7092 Epoch 102/200 2/2 [==============================] - 0s 4ms/step - loss: 1.7028 - mae: 1.7028 Epoch 103/200 2/2 [==============================] - 0s 10ms/step - loss: 3.7462 - mae: 3.7462 Epoch 104/200 2/2 [==============================] - 0s 4ms/step - loss: 3.5765 - mae: 3.5765 Epoch 105/200 2/2 [==============================] - 0s 9ms/step - loss: 0.6709 - mae: 0.6709 Epoch 106/200 2/2 [==============================] - 0s 5ms/step - loss: 2.5038 - mae: 2.5038 Epoch 107/200 2/2 [==============================] - 0s 10ms/step - loss: 1.0662 - mae: 1.0662 Epoch 108/200 2/2 [==============================] - 0s 7ms/step - loss: 3.2977 - mae: 3.2977 Epoch 109/200 2/2 [==============================] - 0s 11ms/step - loss: 1.7277 - mae: 1.7277 Epoch 110/200 2/2 [==============================] - 0s 8ms/step - loss: 1.7222 - mae: 1.7222 Epoch 111/200 2/2 [==============================] - 0s 4ms/step - loss: 2.4556 - mae: 2.4556 Epoch 112/200 2/2 [==============================] - 0s 4ms/step - loss: 1.2323 - mae: 1.2323 Epoch 113/200 2/2 [==============================] - 0s 3ms/step - loss: 2.3107 - mae: 2.3107 Epoch 114/200 2/2 [==============================] - 0s 5ms/step - loss: 1.1657 - mae: 1.1657 Epoch 115/200 2/2 [==============================] - 0s 6ms/step - loss: 0.5163 - mae: 0.5163 Epoch 116/200 2/2 [==============================] - 0s 11ms/step - loss: 0.9971 - mae: 0.9971 Epoch 117/200 2/2 [==============================] - 0s 4ms/step - loss: 0.5883 - mae: 0.5883 Epoch 118/200 2/2 [==============================] - 0s 4ms/step - loss: 1.3641 - mae: 1.3641 Epoch 119/200 2/2 [==============================] - 0s 6ms/step - loss: 1.2354 - mae: 1.2354 Epoch 120/200 2/2 [==============================] - 0s 8ms/step - loss: 2.1195 - mae: 2.1195 Epoch 121/200 2/2 [==============================] - 0s 8ms/step - loss: 1.5836 - mae: 1.5836 Epoch 122/200 2/2 [==============================] - 0s 4ms/step - loss: 1.6398 - mae: 1.6398 Epoch 123/200 2/2 [==============================] - 0s 4ms/step - loss: 1.2508 - mae: 1.2508 Epoch 124/200 2/2 [==============================] - 0s 5ms/step - loss: 1.4922 - mae: 1.4922 Epoch 125/200 2/2 [==============================] - 0s 5ms/step - loss: 1.3658 - mae: 1.3658 Epoch 126/200 2/2 [==============================] - 0s 9ms/step - loss: 1.2253 - mae: 1.2253 Epoch 127/200 2/2 [==============================] - 0s 5ms/step - loss: 1.1196 - mae: 1.1196 Epoch 128/200 2/2 [==============================] - 0s 5ms/step - loss: 0.9335 - mae: 0.9335 Epoch 129/200 2/2 [==============================] - 0s 4ms/step - loss: 0.8113 - mae: 0.8113 Epoch 130/200 2/2 [==============================] - 0s 10ms/step - loss: 1.0733 - mae: 1.0733 Epoch 131/200 2/2 [==============================] - 0s 4ms/step - loss: 1.8052 - mae: 1.8052 Epoch 132/200 2/2 [==============================] - 0s 4ms/step - loss: 2.5612 - mae: 2.5612 Epoch 133/200 2/2 [==============================] - 0s 4ms/step - loss: 1.4219 - mae: 1.4219 Epoch 134/200 2/2 [==============================] - 0s 7ms/step - loss: 1.4680 - mae: 1.4680 Epoch 135/200 2/2 [==============================] - 0s 5ms/step - loss: 1.8870 - mae: 1.8870 Epoch 136/200 2/2 [==============================] - 0s 4ms/step - loss: 2.2592 - mae: 2.2592 Epoch 137/200 2/2 [==============================] - 0s 7ms/step - loss: 1.9956 - mae: 1.9956 Epoch 138/200 2/2 [==============================] - 0s 5ms/step - loss: 3.0650 - mae: 3.0650 Epoch 139/200 2/2 [==============================] - 0s 6ms/step - loss: 1.0014 - mae: 1.0014 Epoch 140/200 2/2 [==============================] - 0s 9ms/step - loss: 3.2610 - mae: 3.2610 Epoch 141/200 2/2 [==============================] - 0s 6ms/step - loss: 1.6062 - mae: 1.6062 Epoch 142/200 2/2 [==============================] - 0s 7ms/step - loss: 1.2257 - mae: 1.2257 Epoch 143/200 2/2 [==============================] - 0s 18ms/step - loss: 0.8448 - mae: 0.8448 Epoch 144/200 2/2 [==============================] - 0s 8ms/step - loss: 1.0984 - mae: 1.0984 Epoch 145/200 2/2 [==============================] - 0s 13ms/step - loss: 2.4422 - mae: 2.4422 Epoch 146/200 2/2 [==============================] - 0s 7ms/step - loss: 2.6819 - mae: 2.6819 Epoch 147/200 2/2 [==============================] - 0s 5ms/step - loss: 2.7767 - mae: 2.7767 Epoch 148/200 2/2 [==============================] - 0s 3ms/step - loss: 1.4457 - mae: 1.4457 Epoch 149/200 2/2 [==============================] - 0s 14ms/step - loss: 2.2885 - mae: 2.2885 Epoch 150/200 2/2 [==============================] - 0s 6ms/step - loss: 2.1808 - mae: 2.1808 Epoch 151/200 2/2 [==============================] - 0s 5ms/step - loss: 1.7162 - mae: 1.7162 Epoch 152/200 2/2 [==============================] - 0s 5ms/step - loss: 2.5100 - mae: 2.5100 Epoch 153/200 2/2 [==============================] - 0s 11ms/step - loss: 3.0009 - mae: 3.0009 Epoch 154/200 2/2 [==============================] - 0s 4ms/step - loss: 1.3393 - mae: 1.3393 Epoch 155/200 2/2 [==============================] - 0s 5ms/step - loss: 1.4204 - mae: 1.4204 Epoch 156/200 2/2 [==============================] - 0s 9ms/step - loss: 0.8329 - mae: 0.8329 Epoch 157/200 2/2 [==============================] - 0s 8ms/step - loss: 0.8151 - mae: 0.8151 Epoch 158/200 2/2 [==============================] - 0s 6ms/step - loss: 0.4740 - mae: 0.4740 Epoch 159/200 2/2 [==============================] - 0s 6ms/step - loss: 0.5993 - mae: 0.5993 Epoch 160/200 2/2 [==============================] - 0s 7ms/step - loss: 0.8892 - mae: 0.8892 Epoch 161/200 2/2 [==============================] - 0s 5ms/step - loss: 1.3737 - mae: 1.3737 Epoch 162/200 2/2 [==============================] - 0s 6ms/step - loss: 1.3816 - mae: 1.3816 Epoch 163/200 2/2 [==============================] - 0s 12ms/step - loss: 0.4873 - mae: 0.4873 Epoch 164/200 2/2 [==============================] - 0s 10ms/step - loss: 2.6898 - mae: 2.6898 Epoch 165/200 2/2 [==============================] - 0s 9ms/step - loss: 2.1343 - mae: 2.1343 Epoch 166/200 2/2 [==============================] - 0s 8ms/step - loss: 2.5751 - mae: 2.5751 Epoch 167/200 2/2 [==============================] - 0s 11ms/step - loss: 3.2341 - mae: 3.2341 Epoch 168/200 2/2 [==============================] - 0s 4ms/step - loss: 1.3389 - mae: 1.3389 Epoch 169/200 2/2 [==============================] - 0s 5ms/step - loss: 3.1156 - mae: 3.1156 Epoch 170/200 2/2 [==============================] - 0s 5ms/step - loss: 3.9627 - mae: 3.9627 Epoch 171/200 2/2 [==============================] - 0s 7ms/step - loss: 2.9557 - mae: 2.9557 Epoch 172/200 2/2 [==============================] - 0s 5ms/step - loss: 2.7741 - mae: 2.7741 Epoch 173/200 2/2 [==============================] - 0s 8ms/step - loss: 1.7854 - mae: 1.7854 Epoch 174/200 2/2 [==============================] - 0s 5ms/step - loss: 2.7852 - mae: 2.7852 Epoch 175/200 2/2 [==============================] - 0s 6ms/step - loss: 1.6089 - mae: 1.6089 Epoch 176/200 2/2 [==============================] - 0s 5ms/step - loss: 1.1539 - mae: 1.1539 Epoch 177/200 2/2 [==============================] - 0s 9ms/step - loss: 1.7511 - mae: 1.7511 Epoch 178/200 2/2 [==============================] - 0s 5ms/step - loss: 1.5213 - mae: 1.5213 Epoch 179/200 2/2 [==============================] - 0s 5ms/step - loss: 0.4070 - mae: 0.4070 Epoch 180/200 2/2 [==============================] - 0s 9ms/step - loss: 0.7122 - mae: 0.7122 Epoch 181/200 2/2 [==============================] - 0s 5ms/step - loss: 1.0361 - mae: 1.0361 Epoch 182/200 2/2 [==============================] - 0s 6ms/step - loss: 1.0402 - mae: 1.0402 Epoch 183/200 2/2 [==============================] - 0s 9ms/step - loss: 0.8103 - mae: 0.8103 Epoch 184/200 2/2 [==============================] - 0s 5ms/step - loss: 1.1456 - mae: 1.1456 Epoch 185/200 2/2 [==============================] - 0s 5ms/step - loss: 2.6328 - mae: 2.6328 Epoch 186/200 2/2 [==============================] - 0s 8ms/step - loss: 0.6912 - mae: 0.6912 Epoch 187/200 2/2 [==============================] - 0s 5ms/step - loss: 3.9797 - mae: 3.9797 Epoch 188/200 2/2 [==============================] - 0s 5ms/step - loss: 3.8691 - mae: 3.8691 Epoch 189/200 2/2 [==============================] - 0s 8ms/step - loss: 1.5077 - mae: 1.5077 Epoch 190/200 2/2 [==============================] - 0s 6ms/step - loss: 4.3976 - mae: 4.3976 Epoch 191/200 2/2 [==============================] - 0s 6ms/step - loss: 3.6373 - mae: 3.6373 Epoch 192/200 2/2 [==============================] - 0s 5ms/step - loss: 2.1293 - mae: 2.1293 Epoch 193/200 2/2 [==============================] - 0s 8ms/step - loss: 3.2316 - mae: 3.2316 Epoch 194/200 2/2 [==============================] - 0s 7ms/step - loss: 1.7595 - mae: 1.7595 Epoch 195/200 2/2 [==============================] - 0s 5ms/step - loss: 1.8424 - mae: 1.8424 Epoch 196/200 2/2 [==============================] - 0s 6ms/step - loss: 1.7401 - mae: 1.7401 Epoch 197/200 2/2 [==============================] - 0s 5ms/step - loss: 1.1691 - mae: 1.1691 Epoch 198/200 2/2 [==============================] - 0s 7ms/step - loss: 1.0087 - mae: 1.0087 Epoch 199/200 2/2 [==============================] - 0s 7ms/step - loss: 1.4872 - mae: 1.4872 Epoch 200/200 2/2 [==============================] - 0s 6ms/step - loss: 0.9445 - mae: 0.9445
Out[32]:
<tensorflow.python.keras.callbacks.History at 0x7f8c5d8365d0>
In [33]:
Copied!
model_1.summary()
model_1.summary()
Model: "sequential_3" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= dense_9 (Dense) (None, 100) 200 _________________________________________________________________ dense_10 (Dense) (None, 100) 10100 _________________________________________________________________ dense_11 (Dense) (None, 1) 101 ================================================================= Total params: 10,401 Trainable params: 10,401 Non-trainable params: 0 _________________________________________________________________
MODEL 2¶
In [34]:
Copied!
# 1. Creating a model
model_2 = tf.keras.Sequential([
tf.keras.layers.Dense(100, activation="relu"),
tf.keras.layers.Dense(50, activation="relu"),
tf.keras.layers.Dense(1)
])
#2. COmppiling the model
model_2.compile(loss=tf.keras.losses.mae,
optimizer=tf.keras.optimizers.Adam(lr=0.01),
metrics=["mae"])
#3. Fitting the model
model_2.fit(X_train, y_train, epochs=210)
# 1. Creating a model
model_2 = tf.keras.Sequential([
tf.keras.layers.Dense(100, activation="relu"),
tf.keras.layers.Dense(50, activation="relu"),
tf.keras.layers.Dense(1)
])
#2. COmppiling the model
model_2.compile(loss=tf.keras.losses.mae,
optimizer=tf.keras.optimizers.Adam(lr=0.01),
metrics=["mae"])
#3. Fitting the model
model_2.fit(X_train, y_train, epochs=210)
Epoch 1/210
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/optimizer_v2/optimizer_v2.py:375: UserWarning: The `lr` argument is deprecated, use `learning_rate` instead. "The `lr` argument is deprecated, use `learning_rate` instead.")
2/2 [==============================] - 0s 8ms/step - loss: 40.9351 - mae: 40.9351 Epoch 2/210 2/2 [==============================] - 0s 6ms/step - loss: 19.7538 - mae: 19.7538 Epoch 3/210 2/2 [==============================] - 0s 5ms/step - loss: 6.8715 - mae: 6.8715 Epoch 4/210 2/2 [==============================] - 0s 3ms/step - loss: 11.5456 - mae: 11.5456 Epoch 5/210 2/2 [==============================] - 0s 7ms/step - loss: 7.8229 - mae: 7.8229 Epoch 6/210 2/2 [==============================] - 0s 7ms/step - loss: 8.5973 - mae: 8.5973 Epoch 7/210 2/2 [==============================] - 0s 7ms/step - loss: 5.6946 - mae: 5.6946 Epoch 8/210 2/2 [==============================] - 0s 9ms/step - loss: 5.0799 - mae: 5.0799 Epoch 9/210 2/2 [==============================] - 0s 4ms/step - loss: 5.5372 - mae: 5.5372 Epoch 10/210 2/2 [==============================] - 0s 4ms/step - loss: 6.2204 - mae: 6.2204 Epoch 11/210 2/2 [==============================] - 0s 5ms/step - loss: 4.3710 - mae: 4.3710 Epoch 12/210 2/2 [==============================] - 0s 4ms/step - loss: 4.5278 - mae: 4.5278 Epoch 13/210 2/2 [==============================] - 0s 6ms/step - loss: 4.8974 - mae: 4.8974 Epoch 14/210 2/2 [==============================] - 0s 6ms/step - loss: 5.8988 - mae: 5.8988 Epoch 15/210 2/2 [==============================] - 0s 5ms/step - loss: 5.0977 - mae: 5.0977 Epoch 16/210 2/2 [==============================] - 0s 10ms/step - loss: 5.0082 - mae: 5.0082 Epoch 17/210 2/2 [==============================] - 0s 8ms/step - loss: 5.9184 - mae: 5.9184 Epoch 18/210 2/2 [==============================] - 0s 9ms/step - loss: 3.7560 - mae: 3.7560 Epoch 19/210 2/2 [==============================] - 0s 10ms/step - loss: 5.0354 - mae: 5.0354 Epoch 20/210 2/2 [==============================] - 0s 6ms/step - loss: 5.3906 - mae: 5.3906 Epoch 21/210 2/2 [==============================] - 0s 5ms/step - loss: 4.3119 - mae: 4.3119 Epoch 22/210 2/2 [==============================] - 0s 7ms/step - loss: 4.0914 - mae: 4.0914 Epoch 23/210 2/2 [==============================] - 0s 7ms/step - loss: 3.5067 - mae: 3.5067 Epoch 24/210 2/2 [==============================] - 0s 7ms/step - loss: 3.7444 - mae: 3.7444 Epoch 25/210 2/2 [==============================] - 0s 4ms/step - loss: 3.4558 - mae: 3.4558 Epoch 26/210 2/2 [==============================] - 0s 6ms/step - loss: 3.3452 - mae: 3.3452 Epoch 27/210 2/2 [==============================] - 0s 5ms/step - loss: 3.3669 - mae: 3.3669 Epoch 28/210 2/2 [==============================] - 0s 6ms/step - loss: 3.1544 - mae: 3.1544 Epoch 29/210 2/2 [==============================] - 0s 7ms/step - loss: 3.3645 - mae: 3.3645 Epoch 30/210 2/2 [==============================] - 0s 4ms/step - loss: 3.0552 - mae: 3.0552 Epoch 31/210 2/2 [==============================] - 0s 10ms/step - loss: 3.4643 - mae: 3.4643 Epoch 32/210 2/2 [==============================] - 0s 8ms/step - loss: 3.1348 - mae: 3.1348 Epoch 33/210 2/2 [==============================] - 0s 5ms/step - loss: 3.0246 - mae: 3.0246 Epoch 34/210 2/2 [==============================] - 0s 18ms/step - loss: 2.8322 - mae: 2.8322 Epoch 35/210 2/2 [==============================] - 0s 6ms/step - loss: 3.2354 - mae: 3.2354 Epoch 36/210 2/2 [==============================] - 0s 10ms/step - loss: 2.7716 - mae: 2.7716 Epoch 37/210 2/2 [==============================] - 0s 6ms/step - loss: 4.3061 - mae: 4.3061 Epoch 38/210 2/2 [==============================] - 0s 12ms/step - loss: 2.9324 - mae: 2.9324 Epoch 39/210 2/2 [==============================] - 0s 8ms/step - loss: 3.2347 - mae: 3.2347 Epoch 40/210 2/2 [==============================] - 0s 5ms/step - loss: 2.3673 - mae: 2.3673 Epoch 41/210 2/2 [==============================] - 0s 5ms/step - loss: 2.4462 - mae: 2.4462 Epoch 42/210 2/2 [==============================] - 0s 9ms/step - loss: 2.9135 - mae: 2.9135 Epoch 43/210 2/2 [==============================] - 0s 9ms/step - loss: 2.4955 - mae: 2.4955 Epoch 44/210 2/2 [==============================] - 0s 7ms/step - loss: 2.3365 - mae: 2.3365 Epoch 45/210 2/2 [==============================] - 0s 5ms/step - loss: 2.8339 - mae: 2.8339 Epoch 46/210 2/2 [==============================] - 0s 9ms/step - loss: 1.7937 - mae: 1.7937 Epoch 47/210 2/2 [==============================] - 0s 7ms/step - loss: 3.0757 - mae: 3.0757 Epoch 48/210 2/2 [==============================] - 0s 6ms/step - loss: 1.7305 - mae: 1.7305 Epoch 49/210 2/2 [==============================] - 0s 10ms/step - loss: 3.1400 - mae: 3.1400 Epoch 50/210 2/2 [==============================] - 0s 5ms/step - loss: 2.4909 - mae: 2.4909 Epoch 51/210 2/2 [==============================] - 0s 9ms/step - loss: 2.0234 - mae: 2.0234 Epoch 52/210 2/2 [==============================] - 0s 10ms/step - loss: 3.2417 - mae: 3.2417 Epoch 53/210 2/2 [==============================] - 0s 4ms/step - loss: 2.2664 - mae: 2.2664 Epoch 54/210 2/2 [==============================] - 0s 10ms/step - loss: 1.7532 - mae: 1.7532 Epoch 55/210 2/2 [==============================] - 0s 7ms/step - loss: 1.4831 - mae: 1.4831 Epoch 56/210 2/2 [==============================] - 0s 10ms/step - loss: 1.0309 - mae: 1.0309 Epoch 57/210 2/2 [==============================] - 0s 8ms/step - loss: 0.7118 - mae: 0.7118 Epoch 58/210 2/2 [==============================] - 0s 7ms/step - loss: 0.8425 - mae: 0.8425 Epoch 59/210 2/2 [==============================] - 0s 11ms/step - loss: 1.7186 - mae: 1.7186 Epoch 60/210 2/2 [==============================] - 0s 7ms/step - loss: 1.1274 - mae: 1.1274 Epoch 61/210 2/2 [==============================] - 0s 4ms/step - loss: 2.4831 - mae: 2.4831 Epoch 62/210 2/2 [==============================] - 0s 6ms/step - loss: 2.6176 - mae: 2.6176 Epoch 63/210 2/2 [==============================] - 0s 7ms/step - loss: 2.8625 - mae: 2.8625 Epoch 64/210 2/2 [==============================] - 0s 7ms/step - loss: 2.0290 - mae: 2.0290 Epoch 65/210 2/2 [==============================] - 0s 7ms/step - loss: 2.8852 - mae: 2.8852 Epoch 66/210 2/2 [==============================] - 0s 5ms/step - loss: 1.4067 - mae: 1.4067 Epoch 67/210 2/2 [==============================] - 0s 6ms/step - loss: 1.4066 - mae: 1.4066 Epoch 68/210 2/2 [==============================] - 0s 5ms/step - loss: 1.6937 - mae: 1.6937 Epoch 69/210 2/2 [==============================] - 0s 5ms/step - loss: 0.9554 - mae: 0.9554 Epoch 70/210 2/2 [==============================] - 0s 4ms/step - loss: 0.9344 - mae: 0.9344 Epoch 71/210 2/2 [==============================] - 0s 5ms/step - loss: 2.4489 - mae: 2.4489 Epoch 72/210 2/2 [==============================] - 0s 6ms/step - loss: 1.7987 - mae: 1.7987 Epoch 73/210 2/2 [==============================] - 0s 9ms/step - loss: 4.2098 - mae: 4.2098 Epoch 74/210 2/2 [==============================] - 0s 6ms/step - loss: 2.7456 - mae: 2.7456 Epoch 75/210 2/2 [==============================] - 0s 6ms/step - loss: 3.7931 - mae: 3.7931 Epoch 76/210 2/2 [==============================] - 0s 4ms/step - loss: 5.4268 - mae: 5.4268 Epoch 77/210 2/2 [==============================] - 0s 4ms/step - loss: 3.4310 - mae: 3.4310 Epoch 78/210 2/2 [==============================] - 0s 4ms/step - loss: 2.4441 - mae: 2.4441 Epoch 79/210 2/2 [==============================] - 0s 5ms/step - loss: 3.6209 - mae: 3.6209 Epoch 80/210 2/2 [==============================] - 0s 6ms/step - loss: 0.5217 - mae: 0.5217 Epoch 81/210 2/2 [==============================] - 0s 7ms/step - loss: 1.9092 - mae: 1.9092 Epoch 82/210 2/2 [==============================] - 0s 6ms/step - loss: 0.8684 - mae: 0.8684 Epoch 83/210 2/2 [==============================] - 0s 7ms/step - loss: 0.8802 - mae: 0.8802 Epoch 84/210 2/2 [==============================] - 0s 5ms/step - loss: 1.7133 - mae: 1.7133 Epoch 85/210 2/2 [==============================] - 0s 5ms/step - loss: 0.8196 - mae: 0.8196 Epoch 86/210 2/2 [==============================] - 0s 10ms/step - loss: 1.8599 - mae: 1.8599 Epoch 87/210 2/2 [==============================] - 0s 4ms/step - loss: 0.9053 - mae: 0.9053 Epoch 88/210 2/2 [==============================] - 0s 13ms/step - loss: 0.9107 - mae: 0.9107 Epoch 89/210 2/2 [==============================] - 0s 7ms/step - loss: 1.2858 - mae: 1.2858 Epoch 90/210 2/2 [==============================] - 0s 7ms/step - loss: 0.5374 - mae: 0.5374 Epoch 91/210 2/2 [==============================] - 0s 5ms/step - loss: 0.9030 - mae: 0.9030 Epoch 92/210 2/2 [==============================] - 0s 6ms/step - loss: 1.7772 - mae: 1.7772 Epoch 93/210 2/2 [==============================] - 0s 6ms/step - loss: 1.8618 - mae: 1.8618 Epoch 94/210 2/2 [==============================] - 0s 4ms/step - loss: 2.0607 - mae: 2.0607 Epoch 95/210 2/2 [==============================] - 0s 5ms/step - loss: 2.8777 - mae: 2.8777 Epoch 96/210 2/2 [==============================] - 0s 4ms/step - loss: 0.7386 - mae: 0.7386 Epoch 97/210 2/2 [==============================] - 0s 4ms/step - loss: 2.8049 - mae: 2.8049 Epoch 98/210 2/2 [==============================] - 0s 6ms/step - loss: 1.1087 - mae: 1.1087 Epoch 99/210 2/2 [==============================] - 0s 6ms/step - loss: 2.6545 - mae: 2.6545 Epoch 100/210 2/2 [==============================] - 0s 8ms/step - loss: 1.4348 - mae: 1.4348 Epoch 101/210 2/2 [==============================] - 0s 7ms/step - loss: 2.3339 - mae: 2.3339 Epoch 102/210 2/2 [==============================] - 0s 11ms/step - loss: 1.9062 - mae: 1.9062 Epoch 103/210 2/2 [==============================] - 0s 5ms/step - loss: 2.2477 - mae: 2.2477 Epoch 104/210 2/2 [==============================] - 0s 4ms/step - loss: 1.4148 - mae: 1.4148 Epoch 105/210 2/2 [==============================] - 0s 6ms/step - loss: 2.0923 - mae: 2.0923 Epoch 106/210 2/2 [==============================] - 0s 8ms/step - loss: 2.3238 - mae: 2.3238 Epoch 107/210 2/2 [==============================] - 0s 7ms/step - loss: 1.9052 - mae: 1.9052 Epoch 108/210 2/2 [==============================] - 0s 9ms/step - loss: 2.7566 - mae: 2.7566 Epoch 109/210 2/2 [==============================] - 0s 5ms/step - loss: 2.7271 - mae: 2.7271 Epoch 110/210 2/2 [==============================] - 0s 6ms/step - loss: 1.9361 - mae: 1.9361 Epoch 111/210 2/2 [==============================] - 0s 6ms/step - loss: 0.5295 - mae: 0.5295 Epoch 112/210 2/2 [==============================] - 0s 7ms/step - loss: 2.4236 - mae: 2.4236 Epoch 113/210 2/2 [==============================] - 0s 4ms/step - loss: 2.7980 - mae: 2.7980 Epoch 114/210 2/2 [==============================] - 0s 6ms/step - loss: 0.7440 - mae: 0.7440 Epoch 115/210 2/2 [==============================] - 0s 6ms/step - loss: 0.6299 - mae: 0.6299 Epoch 116/210 2/2 [==============================] - 0s 7ms/step - loss: 0.7008 - mae: 0.7008 Epoch 117/210 2/2 [==============================] - 0s 6ms/step - loss: 0.7745 - mae: 0.7745 Epoch 118/210 2/2 [==============================] - 0s 4ms/step - loss: 0.4657 - mae: 0.4657 Epoch 119/210 2/2 [==============================] - 0s 6ms/step - loss: 0.7751 - mae: 0.7751 Epoch 120/210 2/2 [==============================] - 0s 10ms/step - loss: 0.6514 - mae: 0.6514 Epoch 121/210 2/2 [==============================] - 0s 11ms/step - loss: 1.1230 - mae: 1.1230 Epoch 122/210 2/2 [==============================] - 0s 9ms/step - loss: 0.9754 - mae: 0.9754 Epoch 123/210 2/2 [==============================] - 0s 9ms/step - loss: 0.9105 - mae: 0.9105 Epoch 124/210 2/2 [==============================] - 0s 13ms/step - loss: 0.5790 - mae: 0.5790 Epoch 125/210 2/2 [==============================] - 0s 6ms/step - loss: 1.0840 - mae: 1.0840 Epoch 126/210 2/2 [==============================] - 0s 7ms/step - loss: 0.8570 - mae: 0.8570 Epoch 127/210 2/2 [==============================] - 0s 7ms/step - loss: 0.8023 - mae: 0.8023 Epoch 128/210 2/2 [==============================] - 0s 9ms/step - loss: 0.8632 - mae: 0.8632 Epoch 129/210 2/2 [==============================] - 0s 8ms/step - loss: 1.0138 - mae: 1.0138 Epoch 130/210 2/2 [==============================] - 0s 5ms/step - loss: 2.5399 - mae: 2.5399 Epoch 131/210 2/2 [==============================] - 0s 7ms/step - loss: 1.7454 - mae: 1.7454 Epoch 132/210 2/2 [==============================] - 0s 8ms/step - loss: 0.8864 - mae: 0.8864 Epoch 133/210 2/2 [==============================] - 0s 6ms/step - loss: 2.3999 - mae: 2.3999 Epoch 134/210 2/2 [==============================] - 0s 3ms/step - loss: 1.9659 - mae: 1.9659 Epoch 135/210 2/2 [==============================] - 0s 6ms/step - loss: 2.0174 - mae: 2.0174 Epoch 136/210 2/2 [==============================] - 0s 8ms/step - loss: 2.4927 - mae: 2.4927 Epoch 137/210 2/2 [==============================] - 0s 7ms/step - loss: 0.6498 - mae: 0.6498 Epoch 138/210 2/2 [==============================] - 0s 6ms/step - loss: 0.7374 - mae: 0.7374 Epoch 139/210 2/2 [==============================] - 0s 9ms/step - loss: 0.4689 - mae: 0.4689 Epoch 140/210 2/2 [==============================] - 0s 5ms/step - loss: 0.9127 - mae: 0.9127 Epoch 141/210 2/2 [==============================] - 0s 5ms/step - loss: 0.8833 - mae: 0.8833 Epoch 142/210 2/2 [==============================] - 0s 5ms/step - loss: 0.5901 - mae: 0.5901 Epoch 143/210 2/2 [==============================] - 0s 6ms/step - loss: 1.1828 - mae: 1.1828 Epoch 144/210 2/2 [==============================] - 0s 5ms/step - loss: 1.2800 - mae: 1.2800 Epoch 145/210 2/2 [==============================] - 0s 4ms/step - loss: 1.3633 - mae: 1.3633 Epoch 146/210 2/2 [==============================] - 0s 5ms/step - loss: 2.4257 - mae: 2.4257 Epoch 147/210 2/2 [==============================] - 0s 9ms/step - loss: 0.8584 - mae: 0.8584 Epoch 148/210 2/2 [==============================] - 0s 4ms/step - loss: 3.0708 - mae: 3.0708 Epoch 149/210 2/2 [==============================] - 0s 5ms/step - loss: 2.1043 - mae: 2.1043 Epoch 150/210 2/2 [==============================] - 0s 4ms/step - loss: 1.5102 - mae: 1.5102 Epoch 151/210 2/2 [==============================] - 0s 5ms/step - loss: 1.8070 - mae: 1.8070 Epoch 152/210 2/2 [==============================] - 0s 4ms/step - loss: 1.4216 - mae: 1.4216 Epoch 153/210 2/2 [==============================] - 0s 5ms/step - loss: 1.9647 - mae: 1.9647 Epoch 154/210 2/2 [==============================] - 0s 15ms/step - loss: 1.9341 - mae: 1.9341 Epoch 155/210 2/2 [==============================] - 0s 7ms/step - loss: 1.6531 - mae: 1.6531 Epoch 156/210 2/2 [==============================] - 0s 7ms/step - loss: 1.8322 - mae: 1.8322 Epoch 157/210 2/2 [==============================] - 0s 6ms/step - loss: 0.7070 - mae: 0.7070 Epoch 158/210 2/2 [==============================] - 0s 8ms/step - loss: 1.2598 - mae: 1.2598 Epoch 159/210 2/2 [==============================] - 0s 6ms/step - loss: 1.1934 - mae: 1.1934 Epoch 160/210 2/2 [==============================] - 0s 14ms/step - loss: 1.8699 - mae: 1.8699 Epoch 161/210 2/2 [==============================] - 0s 5ms/step - loss: 2.0104 - mae: 2.0104 Epoch 162/210 2/2 [==============================] - 0s 8ms/step - loss: 2.2555 - mae: 2.2555 Epoch 163/210 2/2 [==============================] - 0s 7ms/step - loss: 1.6957 - mae: 1.6957 Epoch 164/210 2/2 [==============================] - 0s 11ms/step - loss: 2.0672 - mae: 2.0672 Epoch 165/210 2/2 [==============================] - 0s 17ms/step - loss: 0.8550 - mae: 0.8550 Epoch 166/210 2/2 [==============================] - 0s 9ms/step - loss: 1.9163 - mae: 1.9163 Epoch 167/210 2/2 [==============================] - 0s 8ms/step - loss: 0.8698 - mae: 0.8698 Epoch 168/210 2/2 [==============================] - 0s 4ms/step - loss: 1.9434 - mae: 1.9434 Epoch 169/210 2/2 [==============================] - 0s 9ms/step - loss: 0.9729 - mae: 0.9729 Epoch 170/210 2/2 [==============================] - 0s 7ms/step - loss: 0.7842 - mae: 0.7842 Epoch 171/210 2/2 [==============================] - 0s 6ms/step - loss: 0.8120 - mae: 0.8120 Epoch 172/210 2/2 [==============================] - 0s 6ms/step - loss: 1.1547 - mae: 1.1547 Epoch 173/210 2/2 [==============================] - 0s 6ms/step - loss: 0.7852 - mae: 0.7852 Epoch 174/210 2/2 [==============================] - 0s 6ms/step - loss: 0.9087 - mae: 0.9087 Epoch 175/210 2/2 [==============================] - 0s 5ms/step - loss: 0.6243 - mae: 0.6243 Epoch 176/210 2/2 [==============================] - 0s 11ms/step - loss: 0.5617 - mae: 0.5617 Epoch 177/210 2/2 [==============================] - 0s 6ms/step - loss: 0.8467 - mae: 0.8467 Epoch 178/210 2/2 [==============================] - 0s 10ms/step - loss: 0.8652 - mae: 0.8652 Epoch 179/210 2/2 [==============================] - 0s 9ms/step - loss: 0.4983 - mae: 0.4983 Epoch 180/210 2/2 [==============================] - 0s 6ms/step - loss: 1.2310 - mae: 1.2310 Epoch 181/210 2/2 [==============================] - 0s 8ms/step - loss: 0.5272 - mae: 0.5272 Epoch 182/210 2/2 [==============================] - 0s 5ms/step - loss: 0.4467 - mae: 0.4467 Epoch 183/210 2/2 [==============================] - 0s 4ms/step - loss: 1.8793 - mae: 1.8793 Epoch 184/210 2/2 [==============================] - 0s 6ms/step - loss: 0.8299 - mae: 0.8299 Epoch 185/210 2/2 [==============================] - 0s 4ms/step - loss: 1.2196 - mae: 1.2196 Epoch 186/210 2/2 [==============================] - 0s 5ms/step - loss: 0.5875 - mae: 0.5875 Epoch 187/210 2/2 [==============================] - 0s 9ms/step - loss: 0.5685 - mae: 0.5685 Epoch 188/210 2/2 [==============================] - 0s 5ms/step - loss: 0.5309 - mae: 0.5309 Epoch 189/210 2/2 [==============================] - 0s 11ms/step - loss: 0.3358 - mae: 0.3358 Epoch 190/210 2/2 [==============================] - 0s 4ms/step - loss: 0.6681 - mae: 0.6681 Epoch 191/210 2/2 [==============================] - 0s 5ms/step - loss: 1.0028 - mae: 1.0028 Epoch 192/210 2/2 [==============================] - 0s 4ms/step - loss: 0.7211 - mae: 0.7211 Epoch 193/210 2/2 [==============================] - 0s 4ms/step - loss: 0.6490 - mae: 0.6490 Epoch 194/210 2/2 [==============================] - 0s 4ms/step - loss: 1.4121 - mae: 1.4121 Epoch 195/210 2/2 [==============================] - 0s 5ms/step - loss: 1.5574 - mae: 1.5574 Epoch 196/210 2/2 [==============================] - 0s 4ms/step - loss: 1.1966 - mae: 1.1966 Epoch 197/210 2/2 [==============================] - 0s 6ms/step - loss: 1.1823 - mae: 1.1823 Epoch 198/210 2/2 [==============================] - 0s 5ms/step - loss: 0.7966 - mae: 0.7966 Epoch 199/210 2/2 [==============================] - 0s 9ms/step - loss: 0.7818 - mae: 0.7818 Epoch 200/210 2/2 [==============================] - 0s 4ms/step - loss: 1.2106 - mae: 1.2106 Epoch 201/210 2/2 [==============================] - 0s 10ms/step - loss: 0.9856 - mae: 0.9856 Epoch 202/210 2/2 [==============================] - 0s 4ms/step - loss: 0.9638 - mae: 0.9638 Epoch 203/210 2/2 [==============================] - 0s 8ms/step - loss: 0.8076 - mae: 0.8076 Epoch 204/210 2/2 [==============================] - 0s 5ms/step - loss: 1.4806 - mae: 1.4806 Epoch 205/210 2/2 [==============================] - 0s 10ms/step - loss: 0.8523 - mae: 0.8523 Epoch 206/210 2/2 [==============================] - 0s 6ms/step - loss: 2.4696 - mae: 2.4696 Epoch 207/210 2/2 [==============================] - 0s 5ms/step - loss: 1.8450 - mae: 1.8450 Epoch 208/210 2/2 [==============================] - 0s 5ms/step - loss: 1.7544 - mae: 1.7544 Epoch 209/210 2/2 [==============================] - 0s 7ms/step - loss: 2.2677 - mae: 2.2677 Epoch 210/210 2/2 [==============================] - 0s 7ms/step - loss: 0.6536 - mae: 0.6536
Out[34]:
<tensorflow.python.keras.callbacks.History at 0x7f8c5d6bac50>
MODEL 3¶
In [35]:
Copied!
# 1. Creating a model
model_3 = tf.keras.Sequential([
tf.keras.layers.Dense(75, activation="relu"),
tf.keras.layers.Dense(75, activation="relu"),
tf.keras.layers.Dense(1)
])
#2. COmppiling the model
model_3.compile(loss=tf.keras.losses.mae,
optimizer=tf.keras.optimizers.Adam(lr=0.01),
metrics=["mae"])
#3. Fitting the model
model_3.fit(X_train, y_train, epochs=200)
# 1. Creating a model
model_3 = tf.keras.Sequential([
tf.keras.layers.Dense(75, activation="relu"),
tf.keras.layers.Dense(75, activation="relu"),
tf.keras.layers.Dense(1)
])
#2. COmppiling the model
model_3.compile(loss=tf.keras.losses.mae,
optimizer=tf.keras.optimizers.Adam(lr=0.01),
metrics=["mae"])
#3. Fitting the model
model_3.fit(X_train, y_train, epochs=200)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/optimizer_v2/optimizer_v2.py:375: UserWarning: The `lr` argument is deprecated, use `learning_rate` instead. "The `lr` argument is deprecated, use `learning_rate` instead.")
Epoch 1/200 2/2 [==============================] - 0s 6ms/step - loss: 41.1289 - mae: 41.1289 Epoch 2/200 2/2 [==============================] - 0s 7ms/step - loss: 19.5215 - mae: 19.5215 Epoch 3/200 2/2 [==============================] - 0s 5ms/step - loss: 7.0380 - mae: 7.0380 Epoch 4/200 2/2 [==============================] - 0s 6ms/step - loss: 12.3443 - mae: 12.3443 Epoch 5/200 2/2 [==============================] - 0s 8ms/step - loss: 8.4949 - mae: 8.4949 Epoch 6/200 2/2 [==============================] - 0s 8ms/step - loss: 6.2283 - mae: 6.2283 Epoch 7/200 2/2 [==============================] - 0s 8ms/step - loss: 9.3871 - mae: 9.3871 Epoch 8/200 2/2 [==============================] - 0s 7ms/step - loss: 7.3160 - mae: 7.3160 Epoch 9/200 2/2 [==============================] - 0s 8ms/step - loss: 4.4906 - mae: 4.4906 Epoch 10/200 2/2 [==============================] - 0s 7ms/step - loss: 6.2689 - mae: 6.2689 Epoch 11/200 2/2 [==============================] - 0s 7ms/step - loss: 4.4471 - mae: 4.4471 Epoch 12/200 2/2 [==============================] - 0s 7ms/step - loss: 5.8056 - mae: 5.8056 Epoch 13/200 2/2 [==============================] - 0s 9ms/step - loss: 6.7199 - mae: 6.7199 Epoch 14/200 2/2 [==============================] - 0s 10ms/step - loss: 5.5459 - mae: 5.5459 Epoch 15/200 2/2 [==============================] - 0s 11ms/step - loss: 4.6035 - mae: 4.6035 Epoch 16/200 2/2 [==============================] - 0s 6ms/step - loss: 4.3060 - mae: 4.3060 Epoch 17/200 2/2 [==============================] - 0s 5ms/step - loss: 5.2975 - mae: 5.2975 Epoch 18/200 2/2 [==============================] - 0s 8ms/step - loss: 6.2361 - mae: 6.2361 Epoch 19/200 2/2 [==============================] - 0s 10ms/step - loss: 5.4398 - mae: 5.4398 Epoch 20/200 2/2 [==============================] - 0s 6ms/step - loss: 4.3869 - mae: 4.3869 Epoch 21/200 2/2 [==============================] - 0s 4ms/step - loss: 3.7468 - mae: 3.7468 Epoch 22/200 2/2 [==============================] - 0s 6ms/step - loss: 3.8847 - mae: 3.8847 Epoch 23/200 2/2 [==============================] - 0s 5ms/step - loss: 3.4379 - mae: 3.4379 Epoch 24/200 2/2 [==============================] - 0s 5ms/step - loss: 3.4881 - mae: 3.4881 Epoch 25/200 2/2 [==============================] - 0s 5ms/step - loss: 3.4063 - mae: 3.4063 Epoch 26/200 2/2 [==============================] - 0s 6ms/step - loss: 3.7933 - mae: 3.7933 Epoch 27/200 2/2 [==============================] - 0s 8ms/step - loss: 3.2673 - mae: 3.2673 Epoch 28/200 2/2 [==============================] - 0s 6ms/step - loss: 3.1937 - mae: 3.1937 Epoch 29/200 2/2 [==============================] - 0s 6ms/step - loss: 3.1845 - mae: 3.1845 Epoch 30/200 2/2 [==============================] - 0s 5ms/step - loss: 3.1045 - mae: 3.1045 Epoch 31/200 2/2 [==============================] - 0s 6ms/step - loss: 3.1574 - mae: 3.1574 Epoch 32/200 2/2 [==============================] - 0s 6ms/step - loss: 2.9285 - mae: 2.9285 Epoch 33/200 2/2 [==============================] - 0s 7ms/step - loss: 2.8956 - mae: 2.8956 Epoch 34/200 2/2 [==============================] - 0s 6ms/step - loss: 2.8111 - mae: 2.8111 Epoch 35/200 2/2 [==============================] - 0s 6ms/step - loss: 2.7699 - mae: 2.7699 Epoch 36/200 2/2 [==============================] - 0s 6ms/step - loss: 2.6578 - mae: 2.6578 Epoch 37/200 2/2 [==============================] - 0s 6ms/step - loss: 2.7879 - mae: 2.7879 Epoch 38/200 2/2 [==============================] - 0s 6ms/step - loss: 2.9494 - mae: 2.9494 Epoch 39/200 2/2 [==============================] - 0s 6ms/step - loss: 2.2748 - mae: 2.2748 Epoch 40/200 2/2 [==============================] - 0s 7ms/step - loss: 3.7555 - mae: 3.7555 Epoch 41/200 2/2 [==============================] - 0s 6ms/step - loss: 2.4248 - mae: 2.4248 Epoch 42/200 2/2 [==============================] - 0s 18ms/step - loss: 3.0332 - mae: 3.0332 Epoch 43/200 2/2 [==============================] - 0s 7ms/step - loss: 2.0923 - mae: 2.0923 Epoch 44/200 2/2 [==============================] - 0s 10ms/step - loss: 1.9709 - mae: 1.9709 Epoch 45/200 2/2 [==============================] - 0s 9ms/step - loss: 1.7119 - mae: 1.7119 Epoch 46/200 2/2 [==============================] - 0s 9ms/step - loss: 1.4175 - mae: 1.4175 Epoch 47/200 2/2 [==============================] - 0s 11ms/step - loss: 1.9366 - mae: 1.9366 Epoch 48/200 2/2 [==============================] - 0s 16ms/step - loss: 1.2003 - mae: 1.2003 Epoch 49/200 2/2 [==============================] - 0s 8ms/step - loss: 1.5288 - mae: 1.5288 Epoch 50/200 2/2 [==============================] - 0s 12ms/step - loss: 1.6784 - mae: 1.6784 Epoch 51/200 2/2 [==============================] - 0s 10ms/step - loss: 2.5784 - mae: 2.5784 Epoch 52/200 2/2 [==============================] - 0s 7ms/step - loss: 2.8497 - mae: 2.8497 Epoch 53/200 2/2 [==============================] - 0s 7ms/step - loss: 2.0333 - mae: 2.0333 Epoch 54/200 2/2 [==============================] - 0s 10ms/step - loss: 2.7066 - mae: 2.7066 Epoch 55/200 2/2 [==============================] - 0s 9ms/step - loss: 1.4759 - mae: 1.4759 Epoch 56/200 2/2 [==============================] - 0s 6ms/step - loss: 1.7415 - mae: 1.7415 Epoch 57/200 2/2 [==============================] - 0s 8ms/step - loss: 1.7518 - mae: 1.7518 Epoch 58/200 2/2 [==============================] - 0s 6ms/step - loss: 1.2377 - mae: 1.2377 Epoch 59/200 2/2 [==============================] - 0s 5ms/step - loss: 1.6128 - mae: 1.6128 Epoch 60/200 2/2 [==============================] - 0s 13ms/step - loss: 2.8634 - mae: 2.8634 Epoch 61/200 2/2 [==============================] - 0s 7ms/step - loss: 1.5915 - mae: 1.5915 Epoch 62/200 2/2 [==============================] - 0s 11ms/step - loss: 1.7314 - mae: 1.7314 Epoch 63/200 2/2 [==============================] - 0s 7ms/step - loss: 1.1843 - mae: 1.1843 Epoch 64/200 2/2 [==============================] - 0s 12ms/step - loss: 2.2412 - mae: 2.2412 Epoch 65/200 2/2 [==============================] - 0s 8ms/step - loss: 2.7530 - mae: 2.7530 Epoch 66/200 2/2 [==============================] - 0s 9ms/step - loss: 2.4460 - mae: 2.4460 Epoch 67/200 2/2 [==============================] - 0s 6ms/step - loss: 2.4389 - mae: 2.4389 Epoch 68/200 2/2 [==============================] - 0s 15ms/step - loss: 0.9443 - mae: 0.9443 Epoch 69/200 2/2 [==============================] - 0s 9ms/step - loss: 2.6949 - mae: 2.6949 Epoch 70/200 2/2 [==============================] - 0s 7ms/step - loss: 1.4199 - mae: 1.4199 Epoch 71/200 2/2 [==============================] - 0s 7ms/step - loss: 1.6733 - mae: 1.6733 Epoch 72/200 2/2 [==============================] - 0s 8ms/step - loss: 1.2866 - mae: 1.2866 Epoch 73/200 2/2 [==============================] - 0s 9ms/step - loss: 1.2760 - mae: 1.2760 Epoch 74/200 2/2 [==============================] - 0s 8ms/step - loss: 1.6047 - mae: 1.6047 Epoch 75/200 2/2 [==============================] - 0s 7ms/step - loss: 0.8391 - mae: 0.8391 Epoch 76/200 2/2 [==============================] - 0s 11ms/step - loss: 0.8350 - mae: 0.8350 Epoch 77/200 2/2 [==============================] - 0s 6ms/step - loss: 0.9546 - mae: 0.9546 Epoch 78/200 2/2 [==============================] - 0s 6ms/step - loss: 1.0579 - mae: 1.0579 Epoch 79/200 2/2 [==============================] - 0s 9ms/step - loss: 0.4193 - mae: 0.4193 Epoch 80/200 2/2 [==============================] - 0s 6ms/step - loss: 1.6906 - mae: 1.6906 Epoch 81/200 2/2 [==============================] - 0s 7ms/step - loss: 1.7759 - mae: 1.7759 Epoch 82/200 2/2 [==============================] - 0s 6ms/step - loss: 1.7221 - mae: 1.7221 Epoch 83/200 2/2 [==============================] - 0s 7ms/step - loss: 2.9398 - mae: 2.9398 Epoch 84/200 2/2 [==============================] - 0s 9ms/step - loss: 2.4558 - mae: 2.4558 Epoch 85/200 2/2 [==============================] - 0s 12ms/step - loss: 2.0620 - mae: 2.0620 Epoch 86/200 2/2 [==============================] - 0s 7ms/step - loss: 2.4766 - mae: 2.4766 Epoch 87/200 2/2 [==============================] - 0s 11ms/step - loss: 0.7302 - mae: 0.7302 Epoch 88/200 2/2 [==============================] - 0s 6ms/step - loss: 1.3501 - mae: 1.3501 Epoch 89/200 2/2 [==============================] - 0s 8ms/step - loss: 1.6824 - mae: 1.6824 Epoch 90/200 2/2 [==============================] - 0s 9ms/step - loss: 0.9305 - mae: 0.9305 Epoch 91/200 2/2 [==============================] - 0s 6ms/step - loss: 2.1000 - mae: 2.1000 Epoch 92/200 2/2 [==============================] - 0s 6ms/step - loss: 2.1390 - mae: 2.1390 Epoch 93/200 2/2 [==============================] - 0s 9ms/step - loss: 2.1296 - mae: 2.1296 Epoch 94/200 2/2 [==============================] - 0s 9ms/step - loss: 1.0818 - mae: 1.0818 Epoch 95/200 2/2 [==============================] - 0s 11ms/step - loss: 0.9694 - mae: 0.9694 Epoch 96/200 2/2 [==============================] - 0s 8ms/step - loss: 2.4078 - mae: 2.4078 Epoch 97/200 2/2 [==============================] - 0s 7ms/step - loss: 1.9811 - mae: 1.9811 Epoch 98/200 2/2 [==============================] - 0s 7ms/step - loss: 2.2951 - mae: 2.2951 Epoch 99/200 2/2 [==============================] - 0s 5ms/step - loss: 2.5898 - mae: 2.5898 Epoch 100/200 2/2 [==============================] - 0s 9ms/step - loss: 1.0213 - mae: 1.0213 Epoch 101/200 2/2 [==============================] - 0s 6ms/step - loss: 1.2439 - mae: 1.2439 Epoch 102/200 2/2 [==============================] - 0s 10ms/step - loss: 1.6630 - mae: 1.6630 Epoch 103/200 2/2 [==============================] - 0s 14ms/step - loss: 1.5021 - mae: 1.5021 Epoch 104/200 2/2 [==============================] - 0s 10ms/step - loss: 2.0826 - mae: 2.0826 Epoch 105/200 2/2 [==============================] - 0s 9ms/step - loss: 1.6183 - mae: 1.6183 Epoch 106/200 2/2 [==============================] - 0s 7ms/step - loss: 2.1318 - mae: 2.1318 Epoch 107/200 2/2 [==============================] - 0s 8ms/step - loss: 1.0657 - mae: 1.0657 Epoch 108/200 2/2 [==============================] - 0s 9ms/step - loss: 1.0688 - mae: 1.0688 Epoch 109/200 2/2 [==============================] - 0s 15ms/step - loss: 1.2223 - mae: 1.2223 Epoch 110/200 2/2 [==============================] - 0s 5ms/step - loss: 0.7085 - mae: 0.7085 Epoch 111/200 2/2 [==============================] - 0s 7ms/step - loss: 0.5997 - mae: 0.5997 Epoch 112/200 2/2 [==============================] - 0s 5ms/step - loss: 0.3767 - mae: 0.3767 Epoch 113/200 2/2 [==============================] - 0s 6ms/step - loss: 0.5839 - mae: 0.5839 Epoch 114/200 2/2 [==============================] - 0s 7ms/step - loss: 0.9787 - mae: 0.9787 Epoch 115/200 2/2 [==============================] - 0s 10ms/step - loss: 1.3361 - mae: 1.3361 Epoch 116/200 2/2 [==============================] - 0s 5ms/step - loss: 0.8628 - mae: 0.8628 Epoch 117/200 2/2 [==============================] - 0s 8ms/step - loss: 3.5464 - mae: 3.5464 Epoch 118/200 2/2 [==============================] - 0s 6ms/step - loss: 3.5992 - mae: 3.5992 Epoch 119/200 2/2 [==============================] - 0s 6ms/step - loss: 1.3739 - mae: 1.3739 Epoch 120/200 2/2 [==============================] - 0s 17ms/step - loss: 1.6595 - mae: 1.6595 Epoch 121/200 2/2 [==============================] - 0s 8ms/step - loss: 1.0235 - mae: 1.0235 Epoch 122/200 2/2 [==============================] - 0s 5ms/step - loss: 1.8700 - mae: 1.8700 Epoch 123/200 2/2 [==============================] - 0s 18ms/step - loss: 2.0862 - mae: 2.0862 Epoch 124/200 2/2 [==============================] - 0s 8ms/step - loss: 1.1830 - mae: 1.1830 Epoch 125/200 2/2 [==============================] - 0s 5ms/step - loss: 1.3957 - mae: 1.3957 Epoch 126/200 2/2 [==============================] - 0s 7ms/step - loss: 2.6202 - mae: 2.6202 Epoch 127/200 2/2 [==============================] - 0s 5ms/step - loss: 4.2999 - mae: 4.2999 Epoch 128/200 2/2 [==============================] - 0s 6ms/step - loss: 2.4253 - mae: 2.4253 Epoch 129/200 2/2 [==============================] - 0s 6ms/step - loss: 1.4112 - mae: 1.4112 Epoch 130/200 2/2 [==============================] - 0s 5ms/step - loss: 1.7903 - mae: 1.7903 Epoch 131/200 2/2 [==============================] - 0s 6ms/step - loss: 0.8653 - mae: 0.8653 Epoch 132/200 2/2 [==============================] - 0s 12ms/step - loss: 2.1391 - mae: 2.1391 Epoch 133/200 2/2 [==============================] - 0s 5ms/step - loss: 1.3911 - mae: 1.3911 Epoch 134/200 2/2 [==============================] - 0s 12ms/step - loss: 1.1253 - mae: 1.1253 Epoch 135/200 2/2 [==============================] - 0s 7ms/step - loss: 1.7845 - mae: 1.7845 Epoch 136/200 2/2 [==============================] - 0s 12ms/step - loss: 1.5779 - mae: 1.5779 Epoch 137/200 2/2 [==============================] - 0s 10ms/step - loss: 0.6124 - mae: 0.6124 Epoch 138/200 2/2 [==============================] - 0s 10ms/step - loss: 2.1694 - mae: 2.1694 Epoch 139/200 2/2 [==============================] - 0s 14ms/step - loss: 0.8609 - mae: 0.8609 Epoch 140/200 2/2 [==============================] - 0s 8ms/step - loss: 2.2875 - mae: 2.2875 Epoch 141/200 2/2 [==============================] - 0s 8ms/step - loss: 2.3581 - mae: 2.3581 Epoch 142/200 2/2 [==============================] - 0s 5ms/step - loss: 0.5700 - mae: 0.5700 Epoch 143/200 2/2 [==============================] - 0s 6ms/step - loss: 1.2420 - mae: 1.2420 Epoch 144/200 2/2 [==============================] - 0s 11ms/step - loss: 0.9949 - mae: 0.9949 Epoch 145/200 2/2 [==============================] - 0s 6ms/step - loss: 0.7412 - mae: 0.7412 Epoch 146/200 2/2 [==============================] - 0s 6ms/step - loss: 1.6675 - mae: 1.6675 Epoch 147/200 2/2 [==============================] - 0s 14ms/step - loss: 1.8967 - mae: 1.8967 Epoch 148/200 2/2 [==============================] - 0s 5ms/step - loss: 0.6390 - mae: 0.6390 Epoch 149/200 2/2 [==============================] - 0s 6ms/step - loss: 2.0457 - mae: 2.0457 Epoch 150/200 2/2 [==============================] - 0s 6ms/step - loss: 1.6658 - mae: 1.6658 Epoch 151/200 2/2 [==============================] - 0s 6ms/step - loss: 1.2185 - mae: 1.2185 Epoch 152/200 2/2 [==============================] - 0s 6ms/step - loss: 1.7930 - mae: 1.7930 Epoch 153/200 2/2 [==============================] - 0s 8ms/step - loss: 1.2255 - mae: 1.2255 Epoch 154/200 2/2 [==============================] - 0s 10ms/step - loss: 0.9245 - mae: 0.9245 Epoch 155/200 2/2 [==============================] - 0s 10ms/step - loss: 0.7340 - mae: 0.7340 Epoch 156/200 2/2 [==============================] - 0s 9ms/step - loss: 0.5897 - mae: 0.5897 Epoch 157/200 2/2 [==============================] - 0s 6ms/step - loss: 1.6752 - mae: 1.6752 Epoch 158/200 2/2 [==============================] - 0s 9ms/step - loss: 1.4592 - mae: 1.4592 Epoch 159/200 2/2 [==============================] - 0s 10ms/step - loss: 1.5713 - mae: 1.5713 Epoch 160/200 2/2 [==============================] - 0s 6ms/step - loss: 2.8214 - mae: 2.8214 Epoch 161/200 2/2 [==============================] - 0s 7ms/step - loss: 1.9762 - mae: 1.9762 Epoch 162/200 2/2 [==============================] - 0s 19ms/step - loss: 3.6855 - mae: 3.6855 Epoch 163/200 2/2 [==============================] - 0s 13ms/step - loss: 2.4482 - mae: 2.4482 Epoch 164/200 2/2 [==============================] - 0s 10ms/step - loss: 1.1538 - mae: 1.1538 Epoch 165/200 2/2 [==============================] - 0s 9ms/step - loss: 1.8930 - mae: 1.8930 Epoch 166/200 2/2 [==============================] - 0s 7ms/step - loss: 0.7947 - mae: 0.7947 Epoch 167/200 2/2 [==============================] - 0s 12ms/step - loss: 2.0803 - mae: 2.0803 Epoch 168/200 2/2 [==============================] - 0s 6ms/step - loss: 1.6438 - mae: 1.6438 Epoch 169/200 2/2 [==============================] - 0s 15ms/step - loss: 1.5302 - mae: 1.5302 Epoch 170/200 2/2 [==============================] - 0s 10ms/step - loss: 2.2502 - mae: 2.2502 Epoch 171/200 2/2 [==============================] - 0s 7ms/step - loss: 1.3565 - mae: 1.3565 Epoch 172/200 2/2 [==============================] - 0s 5ms/step - loss: 1.7005 - mae: 1.7005 Epoch 173/200 2/2 [==============================] - 0s 13ms/step - loss: 0.5689 - mae: 0.5689 Epoch 174/200 2/2 [==============================] - 0s 6ms/step - loss: 1.4057 - mae: 1.4057 Epoch 175/200 2/2 [==============================] - 0s 13ms/step - loss: 0.9480 - mae: 0.9480 Epoch 176/200 2/2 [==============================] - 0s 5ms/step - loss: 1.3511 - mae: 1.3511 Epoch 177/200 2/2 [==============================] - 0s 5ms/step - loss: 0.7883 - mae: 0.7883 Epoch 178/200 2/2 [==============================] - 0s 6ms/step - loss: 1.0327 - mae: 1.0327 Epoch 179/200 2/2 [==============================] - 0s 9ms/step - loss: 0.4363 - mae: 0.4363 Epoch 180/200 2/2 [==============================] - 0s 7ms/step - loss: 0.5013 - mae: 0.5013 Epoch 181/200 2/2 [==============================] - 0s 7ms/step - loss: 0.8895 - mae: 0.8895 Epoch 182/200 2/2 [==============================] - 0s 13ms/step - loss: 1.3899 - mae: 1.3899 Epoch 183/200 2/2 [==============================] - 0s 12ms/step - loss: 1.7968 - mae: 1.7968 Epoch 184/200 2/2 [==============================] - 0s 11ms/step - loss: 1.6880 - mae: 1.6880 Epoch 185/200 2/2 [==============================] - 0s 9ms/step - loss: 1.6186 - mae: 1.6186 Epoch 186/200 2/2 [==============================] - 0s 5ms/step - loss: 1.2189 - mae: 1.2189 Epoch 187/200 2/2 [==============================] - 0s 5ms/step - loss: 1.5934 - mae: 1.5934 Epoch 188/200 2/2 [==============================] - 0s 4ms/step - loss: 0.9925 - mae: 0.9925 Epoch 189/200 2/2 [==============================] - 0s 6ms/step - loss: 1.4474 - mae: 1.4474 Epoch 190/200 2/2 [==============================] - 0s 9ms/step - loss: 0.6325 - mae: 0.6325 Epoch 191/200 2/2 [==============================] - 0s 13ms/step - loss: 0.6227 - mae: 0.6227 Epoch 192/200 2/2 [==============================] - 0s 17ms/step - loss: 0.4163 - mae: 0.4163 Epoch 193/200 2/2 [==============================] - 0s 17ms/step - loss: 0.5070 - mae: 0.5070 Epoch 194/200 2/2 [==============================] - 0s 8ms/step - loss: 0.3083 - mae: 0.3083 Epoch 195/200 2/2 [==============================] - 0s 6ms/step - loss: 0.3470 - mae: 0.3470 Epoch 196/200 2/2 [==============================] - 0s 11ms/step - loss: 0.5570 - mae: 0.5570 Epoch 197/200 2/2 [==============================] - 0s 7ms/step - loss: 0.4510 - mae: 0.4510 Epoch 198/200 2/2 [==============================] - 0s 6ms/step - loss: 0.6438 - mae: 0.6438 Epoch 199/200 2/2 [==============================] - 0s 5ms/step - loss: 0.4387 - mae: 0.4387 Epoch 200/200 2/2 [==============================] - 0s 5ms/step - loss: 1.3176 - mae: 1.3176
Out[35]:
<tensorflow.python.keras.callbacks.History at 0x7f8c63355210>
In [36]:
Copied!
model_1.summary()
model_1.summary()
Model: "sequential_3" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= dense_9 (Dense) (None, 100) 200 _________________________________________________________________ dense_10 (Dense) (None, 100) 10100 _________________________________________________________________ dense_11 (Dense) (None, 1) 101 ================================================================= Total params: 10,401 Trainable params: 10,401 Non-trainable params: 0 _________________________________________________________________
In [37]:
Copied!
model_2.summary()
model_2.summary()
Model: "sequential_4" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= dense_12 (Dense) (None, 100) 200 _________________________________________________________________ dense_13 (Dense) (None, 50) 5050 _________________________________________________________________ dense_14 (Dense) (None, 1) 51 ================================================================= Total params: 5,301 Trainable params: 5,301 Non-trainable params: 0 _________________________________________________________________
In [38]:
Copied!
model_3.summary()
model_3.summary()
Model: "sequential_5" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= dense_15 (Dense) (None, 75) 150 _________________________________________________________________ dense_16 (Dense) (None, 75) 5700 _________________________________________________________________ dense_17 (Dense) (None, 1) 76 ================================================================= Total params: 5,926 Trainable params: 5,926 Non-trainable params: 0 _________________________________________________________________
In [39]:
Copied!
X_test2 = tf.range(100, 200, 4)
X_test2
X_test2 = tf.range(100, 200, 4)
X_test2
Out[39]:
<tf.Tensor: shape=(25,), dtype=int32, numpy= array([100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144, 148, 152, 156, 160, 164, 168, 172, 176, 180, 184, 188, 192, 196], dtype=int32)>
In [40]:
Copied!
y_test2 = X_test2 + 10
y_test2
y_test2 = X_test2 + 10
y_test2
Out[40]:
<tf.Tensor: shape=(25,), dtype=int32, numpy= array([110, 114, 118, 122, 126, 130, 134, 138, 142, 146, 150, 154, 158, 162, 166, 170, 174, 178, 182, 186, 190, 194, 198, 202, 206], dtype=int32)>
In [41]:
Copied!
plt.scatter(X_test2, y_test2);
plt.scatter(X_test2, y_test2);
In [42]:
Copied!
y_preds_1 = tf.squeeze(model_1.predict(X_test))
y_preds_1 = tf.squeeze(model_1.predict(X_test))
In [43]:
Copied!
plt.figure(figsize=(10,7))
# Training data
plt.scatter(X_train, y_train, c="b", label="Training data")
# Testing data
plt.scatter(X_test, y_test, c="g", label="Testing data")
# Show a legend
plt.legend()
plt.figure(figsize=(10,7))
# Training data
plt.scatter(X_train, y_train, c="b", label="Training data")
# Testing data
plt.scatter(X_test, y_test, c="g", label="Testing data")
# Show a legend
plt.legend()
Out[43]:
<matplotlib.legend.Legend at 0x7f8c5b503c50>
In [44]:
Copied!
def plot_predictions(train_data=X_train,
train_labels=y_train,
test_data=X_test,
test_labels=y_test,
predictions=y_preds_1,
name="Model"):
"""
Plots training data, test data and compares predictions.
"""
plt.figure(figsize=(10, 7),)
plt.title(name)
# Plot training data in blue
plt.scatter(train_data, train_labels, c="b", label="Training data")
# Plot test data in green
plt.scatter(test_data, test_labels, c="g", label="Testing data")
# Plot the predictions in red (predictions were made on the test data)
plt.scatter(test_data, predictions, c="r", label="Predictions")
# Show the legend
plt.legend();
def plot_predictions(train_data=X_train,
train_labels=y_train,
test_data=X_test,
test_labels=y_test,
predictions=y_preds_1,
name="Model"):
"""
Plots training data, test data and compares predictions.
"""
plt.figure(figsize=(10, 7),)
plt.title(name)
# Plot training data in blue
plt.scatter(train_data, train_labels, c="b", label="Training data")
# Plot test data in green
plt.scatter(test_data, test_labels, c="g", label="Testing data")
# Plot the predictions in red (predictions were made on the test data)
plt.scatter(test_data, predictions, c="r", label="Predictions")
# Show the legend
plt.legend();
In [45]:
Copied!
y_preds_1 = tf.squeeze(model_1.predict(X_test))
y_preds_2 = tf.squeeze(model_2.predict(X_test))
y_preds_3 = tf.squeeze(model_3.predict(X_test))
y_preds_1 = tf.squeeze(model_1.predict(X_test))
y_preds_2 = tf.squeeze(model_2.predict(X_test))
y_preds_3 = tf.squeeze(model_3.predict(X_test))
WARNING:tensorflow:5 out of the last 7 calls to <function Model.make_predict_function.<locals>.predict_function at 0x7f8c5dfe10e0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details. WARNING:tensorflow:6 out of the last 8 calls to <function Model.make_predict_function.<locals>.predict_function at 0x7f8c5b489cb0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details.
In [46]:
Copied!
# Model 1
plot_predictions(predictions=y_preds_1, name="model_1")
# Model 1
plot_predictions(predictions=y_preds_1, name="model_1")
In [47]:
Copied!
# Model 2
plot_predictions(predictions=y_preds_2, name="model_2")
# Model 2
plot_predictions(predictions=y_preds_2, name="model_2")
In [48]:
Copied!
# Model 3
plot_predictions(predictions=y_preds_3, name="model_3")
# Model 3
plot_predictions(predictions=y_preds_3, name="model_3")