In [1]:
import pandas as pd
import keras
from keras.models import Sequential
from keras.layers import *
C:\Users\rstancut\AppData\Local\Continuum\anaconda2\envs\keras\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
In [2]:
training_data_df = pd.read_csv("Exercise Files/06/sales_data_training_scaled.csv")

X = training_data_df.drop('total_earnings', axis=1).values
Y = training_data_df[['total_earnings']].values

# Define the model
model = Sequential()
model.add(Dense(50, input_dim=9, activation='relu', name='layer_1'))
model.add(Dense(100, activation='relu', name='layer_2'))
model.add(Dense(50, activation='relu', name='layer_3'))
model.add(Dense(1, activation='linear', name='output_layer'))
model.compile(loss='mean_squared_error', optimizer='adam')
In [4]:
# Create a TensorBoard logger
logger = keras.callbacks.TensorBoard(
    log_dir='Exercise Files/06/logs',
    write_graph=True, 
#     histogram_freq=5
)

# Train the model
model.fit(
    X,
    Y,
    epochs=50,
    shuffle=True,
    verbose=2,
    callbacks=[logger]
)
Epoch 1/50
 - 0s - loss: 0.0028
Epoch 2/50
 - 0s - loss: 6.5589e-04
Epoch 3/50
 - 0s - loss: 3.2713e-04
Epoch 4/50
 - 0s - loss: 2.3221e-04
Epoch 5/50
 - 0s - loss: 1.5871e-04
Epoch 6/50
 - 0s - loss: 1.2781e-04
Epoch 7/50
 - 0s - loss: 1.1543e-04
Epoch 8/50
 - 0s - loss: 9.5294e-05
Epoch 9/50
 - 0s - loss: 7.5911e-05
Epoch 10/50
 - 0s - loss: 6.6415e-05
Epoch 11/50
 - 0s - loss: 6.5555e-05
Epoch 12/50
 - 0s - loss: 5.2470e-05
Epoch 13/50
 - 0s - loss: 4.8363e-05
Epoch 14/50
 - 0s - loss: 4.1335e-05
Epoch 15/50
 - 0s - loss: 3.6980e-05
Epoch 16/50
 - 0s - loss: 3.7616e-05
Epoch 17/50
 - 0s - loss: 4.1244e-05
Epoch 18/50
 - 0s - loss: 3.7625e-05
Epoch 19/50
 - 0s - loss: 4.5871e-05
Epoch 20/50
 - 0s - loss: 3.2658e-05
Epoch 21/50
 - 0s - loss: 3.4363e-05
Epoch 22/50
 - 0s - loss: 3.4616e-05
Epoch 23/50
 - 0s - loss: 2.4335e-05
Epoch 24/50
 - 0s - loss: 2.1786e-05
Epoch 25/50
 - 0s - loss: 2.2514e-05
Epoch 26/50
 - 0s - loss: 2.4651e-05
Epoch 27/50
 - 0s - loss: 2.4990e-05
Epoch 28/50
 - 0s - loss: 2.0687e-05
Epoch 29/50
 - 0s - loss: 2.2054e-05
Epoch 30/50
 - 0s - loss: 1.9816e-05
Epoch 31/50
 - 0s - loss: 1.9106e-05
Epoch 32/50
 - 0s - loss: 1.9186e-05
Epoch 33/50
 - 0s - loss: 1.9424e-05
Epoch 34/50
 - 0s - loss: 2.0040e-05
Epoch 35/50
 - 0s - loss: 3.0287e-05
Epoch 36/50
 - 0s - loss: 2.0204e-05
Epoch 37/50
 - 0s - loss: 2.0453e-05
Epoch 38/50
 - 0s - loss: 1.9729e-05
Epoch 39/50
 - 0s - loss: 1.6226e-05
Epoch 40/50
 - 0s - loss: 1.8246e-05
Epoch 41/50
 - 0s - loss: 1.8256e-05
Epoch 42/50
 - 0s - loss: 2.4322e-05
Epoch 43/50
 - 0s - loss: 2.0360e-05
Epoch 44/50
 - 0s - loss: 1.9182e-05
Epoch 45/50
 - 0s - loss: 2.2065e-05
Epoch 46/50
 - 0s - loss: 1.9467e-05
Epoch 47/50
 - 0s - loss: 2.0424e-05
Epoch 48/50
 - 0s - loss: 2.7942e-05
Epoch 49/50
 - 0s - loss: 4.0867e-05
Epoch 50/50
 - 0s - loss: 2.4847e-05
Out[4]:
<keras.callbacks.History at 0x222d2b23c50>
In [5]:
# Load the separate test data set
test_data_df = pd.read_csv("Exercise Files/06/sales_data_test_scaled.csv")

X_test = test_data_df.drop('total_earnings', axis=1).values
Y_test = test_data_df[['total_earnings']].values

test_error_rate = model.evaluate(X_test, Y_test, verbose=0)
print("The mean squared error (MSE) for the test data set is: {}".format(test_error_rate))
The mean squared error (MSE) for the test data set is: 4.612808406818658e-05