Your first neural network

In this project, you'll build your first neural network and use it to predict daily bike rental ridership. We've provided some of the code, but left the implementation of the neural network up to you (for the most part). After you've submitted this project, feel free to explore the data and the model more.


In [63]:
%matplotlib inline
%config InlineBackend.figure_format = 'retina'

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.special import expit

Load and prepare the data

A critical step in working with neural networks is preparing the data correctly. Variables on different scales make it difficult for the network to efficiently learn the correct weights. Below, we've written the code to load and prepare the data. You'll learn more about this soon!


In [64]:
data_path = 'Bike-Sharing-Dataset/hour.csv'

rides = pd.read_csv(data_path)

In [65]:
rides.head()


Out[65]:
instant dteday season yr mnth hr holiday weekday workingday weathersit temp atemp hum windspeed casual registered cnt
0 1 2011-01-01 1 0 1 0 0 6 0 1 0.24 0.2879 0.81 0.0 3 13 16
1 2 2011-01-01 1 0 1 1 0 6 0 1 0.22 0.2727 0.80 0.0 8 32 40
2 3 2011-01-01 1 0 1 2 0 6 0 1 0.22 0.2727 0.80 0.0 5 27 32
3 4 2011-01-01 1 0 1 3 0 6 0 1 0.24 0.2879 0.75 0.0 3 10 13
4 5 2011-01-01 1 0 1 4 0 6 0 1 0.24 0.2879 0.75 0.0 0 1 1

Checking out the data

This dataset has the number of riders for each hour of each day from January 1 2011 to December 31 2012. The number of riders is split between casual and registered, summed up in the cnt column. You can see the first few rows of the data above.

Below is a plot showing the number of bike riders over the first 10 days in the data set. You can see the hourly rentals here. This data is pretty complicated! The weekends have lower over all ridership and there are spikes when people are biking to and from work during the week. Looking at the data above, we also have information about temperature, humidity, and windspeed, all of these likely affecting the number of riders. You'll be trying to capture all this with your model.


In [66]:
rides[:24*10].plot(x='dteday', y='cnt')


Out[66]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fe18c3e4358>

Dummy variables

Here we have some categorical variables like season, weather, month. To include these in our model, we'll need to make binary dummy variables. This is simple to do with Pandas thanks to get_dummies().


In [67]:
dummy_fields = ['season', 'weathersit', 'mnth', 'hr', 'weekday']
for each in dummy_fields:
    dummies = pd.get_dummies(rides[each], prefix=each, drop_first=False)
    rides = pd.concat([rides, dummies], axis=1)

fields_to_drop = ['instant', 'dteday', 'season', 'weathersit', 
                  'weekday', 'atemp', 'mnth', 'workingday', 'hr']
data = rides.drop(fields_to_drop, axis=1)
data.head()


Out[67]:
yr holiday temp hum windspeed casual registered cnt season_1 season_2 ... hr_21 hr_22 hr_23 weekday_0 weekday_1 weekday_2 weekday_3 weekday_4 weekday_5 weekday_6
0 0 0 0.24 0.81 0.0 3 13 16 1 0 ... 0 0 0 0 0 0 0 0 0 1
1 0 0 0.22 0.80 0.0 8 32 40 1 0 ... 0 0 0 0 0 0 0 0 0 1
2 0 0 0.22 0.80 0.0 5 27 32 1 0 ... 0 0 0 0 0 0 0 0 0 1
3 0 0 0.24 0.75 0.0 3 10 13 1 0 ... 0 0 0 0 0 0 0 0 0 1
4 0 0 0.24 0.75 0.0 0 1 1 1 0 ... 0 0 0 0 0 0 0 0 0 1

5 rows × 59 columns

Scaling target variables

To make training the network easier, we'll standardize each of the continuous variables. That is, we'll shift and scale the variables such that they have zero mean and a standard deviation of 1.

The scaling factors are saved so we can go backwards when we use the network for predictions.


In [68]:
quant_features = ['casual', 'registered', 'cnt', 'temp', 'hum', 'windspeed']
# Store scalings in a dictionary so we can convert back later
scaled_features = {}
for each in quant_features:
    mean, std = data[each].mean(), data[each].std()
    scaled_features[each] = [mean, std]
    data.loc[:, each] = (data[each] - mean)/std

Splitting the data into training, testing, and validation sets

We'll save the last 21 days of the data to use as a test set after we've trained the network. We'll use this set to make predictions and compare them with the actual number of riders.


In [69]:
# Save the last 21 days 
test_data = data[-21*24:]
data = data[:-21*24]

# Separate the data into features and targets
target_fields = ['cnt', 'casual', 'registered']
features, targets = data.drop(target_fields, axis=1), data[target_fields]
test_features, test_targets = test_data.drop(target_fields, axis=1), test_data[target_fields]

We'll split the data into two sets, one for training and one for validating as the network is being trained. Since this is time series data, we'll train on historical data, then try to predict on future data (the validation set).


In [70]:
# Hold out the last 60 days of the remaining data as a validation set
train_features, train_targets = features[:-60*24], targets[:-60*24]
val_features, val_targets = features[-60*24:], targets[-60*24:]

Time to build the network

Below you'll build your network. We've built out the structure and the backwards pass. You'll implement the forward pass through the network. You'll also set the hyperparameters: the learning rate, the number of hidden units, and the number of training passes.

The network has two layers, a hidden layer and an output layer. The hidden layer will use the sigmoid function for activations. The output layer has only one node and is used for the regression, the output of the node is the same as the input of the node. That is, the activation function is $f(x)=x$. A function that takes the input signal and generates an output signal, but takes into account the threshold, is called an activation function. We work through each layer of our network calculating the outputs for each neuron. All of the outputs from one layer become inputs to the neurons on the next layer. This process is called forward propagation.

We use the weights to propagate signals forward from the input to the output layers in a neural network. We use the weights to also propagate error backwards from the output back into the network to update our weights. This is called backpropagation.

Hint: You'll need the derivative of the output activation function ($f(x) = x$) for the backpropagation implementation. If you aren't familiar with calculus, this function is equivalent to the equation $y = x$. What is the slope of that equation? That is the derivative of $f(x)$.

Below, you have these tasks:

  1. Implement the sigmoid function to use as the activation function. Set self.activation_function in __init__ to your sigmoid function.
  2. Implement the forward pass in the train method.
  3. Implement the backpropagation algorithm in the train method, including calculating the output error.
  4. Implement the forward pass in the run method.

In [71]:
class NeuralNetwork(object):
    def __init__(self, input_nodes, hidden_nodes, output_nodes, learning_rate):
        # Set number of nodes in input, hidden and output layers.
        self.input_nodes = input_nodes
        self.hidden_nodes = hidden_nodes
        self.output_nodes = output_nodes
        
        # Initialize weights
        self.weights_input_to_hidden = np.random.normal(0.0, self.hidden_nodes**-0.5, 
                                       (self.hidden_nodes, self.input_nodes))

        self.weights_hidden_to_output = np.random.normal(0.0, self.output_nodes**-0.5, 
                                       (self.output_nodes, self.hidden_nodes))
        self.lr = learning_rate
        
        #### Set this to your implemented sigmoid function ####
        # Activation function is the sigmoid function
        self.activation_function = self.activation_function_hidden
        
    # In the class, we use the following code.
    #        return 1 / (1 + np.exp(-x))
    # It throws overflow exception when selecting hyper parameters.
    # I made the change according to the following link
    # http://arogozhnikov.github.io/2015/09/30/NumpyTipsAndTricks2.html
    def activation_function_hidden(self, x):
        return expit(x)
    
    def activation_function_hidden_derivative(self, x):
        return (1.0 - x) * x 
    
    # Added this function to make the code generic to all kinds of activation functions for output layer
    def activation_function_out(self, x):
        return x
    
    # Added this function to make the code generic to all kinds of activation functions for output layer
    def activation_function_out_derivative(self, x):
        return 1.0

    def train(self, inputs_list, targets_list):
        # Convert inputs list to 2d array
        inputs = np.array(inputs_list, ndmin=2).T
        targets = np.array(targets_list, ndmin=2).T
        
        #### Implement the forward pass here ####
        ### Forward pass ###
        # TODO: Hidden layer
        hidden_inputs = np.dot(self.weights_input_to_hidden, inputs) 
        hidden_outputs = self.activation_function_hidden(hidden_inputs)
        
        # TODO: Output layer
        final_inputs = np.dot(self.weights_hidden_to_output, hidden_outputs)
        final_outputs = self.activation_function_out(final_inputs)
        
        #### Implement the backward pass here ####
        ### Backward pass ###
        
        # TODO: Output error
        # Output layer error is the difference between desired target and actual output.
        output_errors = targets - final_outputs
        # The following value is the same as output_errors but I want to make the code more generic
        output_grad = output_errors * self.activation_function_out_derivative(final_outputs)
        
        # TODO: Backpropagated error
        # errors propagated to the hidden layer
        hidden_errors = np.dot(self.weights_hidden_to_output.T, output_grad)
        # hidden layer gradients
        hidden_grad = self.activation_function_hidden_derivative(hidden_outputs)
        # hidden layer gradients
        
        # TODO: Update the weights
        # update hidden-to-output weights with gradient descent step
        self.weights_hidden_to_output += self.lr * output_grad * hidden_outputs.T
        # update input-to-hidden weights with gradient descent step
        self.weights_input_to_hidden += self.lr * hidden_errors * hidden_grad * inputs.T
        # or self.lr * np.outer(hidden_errors * hidden_grad, inputs)
        # or self.lr * np.dot((hidden_errors * hidden_grad), inputs.T)
        # They the same to calculate outer product of (hidden_errors * hidden_grad) and input
 
        
    def run(self, inputs_list):
        # Run a forward pass through the network
        inputs = np.array(inputs_list, ndmin=2).T
        
        #### Implement the forward pass here ####
        # TODO: Hidden layer
        # signals into hidden layer
        hidden_inputs = np.dot(self.weights_input_to_hidden, inputs) 
        # signals from hidden layer
        hidden_outputs = self.activation_function(hidden_inputs)
        
        # TODO: Output layer
        # signals into final output layer
        final_inputs = np.dot(self.weights_hidden_to_output, hidden_outputs)
         # signals from final output layer 
        final_outputs = final_inputs
        
        return final_outputs

In [72]:
def MSE(y, Y):
    return np.mean((y-Y)**2)

Training the network

Here you'll set the hyperparameters for the network. The strategy here is to find hyperparameters such that the error on the training set is low, but you're not overfitting to the data. If you train the network too long or have too many hidden nodes, it can become overly specific to the training set and will fail to generalize to the validation set. That is, the loss on the validation set will start increasing as the training set loss drops.

You'll also be using a method know as Stochastic Gradient Descent (SGD) to train the network. The idea is that for each training pass, you grab a random sample of the data instead of using the whole data set. You use many more training passes than with normal gradient descent, but each pass is much faster. This ends up training the network more efficiently. You'll learn more about SGD later.

Choose the number of epochs

This is the number of times the dataset will pass through the network, each time updating the weights. As the number of epochs increases, the network becomes better and better at predicting the targets in the training set. You'll need to choose enough epochs to train the network well but not too many or you'll be overfitting.

Choose the learning rate

This scales the size of weight updates. If this is too big, the weights tend to explode and the network fails to fit the data. A good choice to start at is 0.1. If the network has problems fitting the data, try reducing the learning rate. Note that the lower the learning rate, the smaller the steps are in the weight updates and the longer it takes for the neural network to converge.

Choose the number of hidden nodes

The more hidden nodes you have, the more accurate predictions the model will make. Try a few different numbers and see how it affects the performance. You can look at the losses dictionary for a metric of the network performance. If the number of hidden units is too low, then the model won't have enough space to learn and if it is too high there are too many options for the direction that the learning can take. The trick here is to find the right balance in number of hidden units you choose.


In [73]:
import sys

### Set the hyperparameters here ###
epochs = 2000
learning_rate = 0.04
# Changed to 28 based on the feedback of the review
hidden_nodes = 28
output_nodes = 1

N_i = train_features.shape[1]
network = NeuralNetwork(N_i, hidden_nodes, output_nodes, learning_rate)

losses = {'train':[], 'validation':[]}
for e in range(epochs):
    # Go through a random batch of 128 records from the training data set
    batch = np.random.choice(train_features.index, size=128)
    for record, target in zip(train_features.ix[batch].values, 
                              train_targets.ix[batch]['cnt']):
        network.train(record, target)
    
    # Printing out the training progress
    train_loss = MSE(network.run(train_features), train_targets['cnt'].values)
    val_loss = MSE(network.run(val_features), val_targets['cnt'].values)
    sys.stdout.write("\rProgress: " + str(100 * e/float(epochs))[:4] \
                     + "% ... Training loss: " + str(train_loss)[:5] \
                     + " ... Validation loss: " + str(val_loss)[:5])
    
    losses['train'].append(train_loss)
    losses['validation'].append(val_loss)


Progress: 99.9% ... Training loss: 0.054 ... Validation loss: 0.136

Check out your predictions

Here, use the test data to view how well your network is modeling the data. If something is completely wrong here, make sure each step in your network is implemented correctly.


In [74]:
fig, ax = plt.subplots(figsize=(8,4))

mean, std = scaled_features['cnt']
predictions = network.run(test_features)*std + mean

test_loss = MSE(network.run(test_features), test_targets['cnt'].values)
sys.stdout.write("Test loss: " + str(test_loss))

ax.plot(predictions[0], label='Prediction')
ax.plot((test_targets['cnt']*std + mean).values, label='Data')
ax.set_xlim(right=len(predictions))
ax.legend()

dates = pd.to_datetime(rides.ix[test_data.index]['dteday'])
dates = dates.apply(lambda d: d.strftime('%b %d'))
ax.set_xticks(np.arange(len(dates))[12::24])
_ = ax.set_xticklabels(dates[12::24], rotation=45)


Test loss: 0.170332108664

Thinking about your results

Answer these questions about your results. How well does the model predict the data? Where does it fail? Why does it fail where it does?

Note: You can edit the text in this cell by double clicking on it. When you want to render the text, press control + enter

Your answer below

The model predicts well on the dates between Dec 11 and Dec 22 but it predicts higher usage of the bikes afterwards. The reason could be related to the Christmas day and the new year's day holiday.

  • For the working days in this date range, a lot of working people might take the days off because of the two holidays as well as winter breaks in schools. These days are more like holidays but the model treats them as weekdays.
  • For the holidays in this data range, the model predicted higher because it treats all holiday the same way. However, in reality, there are less people working on the Christmas day (as well as Thanksgiving day). So if we could add a holiday index which differentiate them, the result could be better.

Unit tests

Run these unit tests to check the correctness of your network implementation. These tests must all be successful to pass the project.


In [75]:
import unittest

inputs = [0.5, -0.2, 0.1]
targets = [0.4]
test_w_i_h = np.array([[0.1, 0.4, -0.3], 
                       [-0.2, 0.5, 0.2]])
test_w_h_o = np.array([[0.3, -0.1]])

class TestMethods(unittest.TestCase):
    
    ##########
    # Unit tests for data loading
    ##########
    
    def test_data_path(self):
        # Test that file path to dataset has been unaltered
        self.assertTrue(data_path.lower() == 'bike-sharing-dataset/hour.csv')
        
    def test_data_loaded(self):
        # Test that data frame loaded
        self.assertTrue(isinstance(rides, pd.DataFrame))
    
    ##########
    # Unit tests for network functionality
    ##########

    def test_activation(self):
        network = NeuralNetwork(3, 2, 1, 0.5)
        # Test that the activation function is a sigmoid
        self.assertTrue(np.all(network.activation_function(0.5) == 1/(1+np.exp(-0.5))))

    def test_train(self):
        # Test that weights are updated correctly on training
        network = NeuralNetwork(3, 2, 1, 0.5)
        network.weights_input_to_hidden = test_w_i_h.copy()
        network.weights_hidden_to_output = test_w_h_o.copy()
        
        network.train(inputs, targets)
        self.assertTrue(np.allclose(network.weights_hidden_to_output, 
                                    np.array([[ 0.37275328, -0.03172939]])))
        self.assertTrue(np.allclose(network.weights_input_to_hidden,
                                    np.array([[ 0.10562014,  0.39775194, -0.29887597],
                                              [-0.20185996,  0.50074398,  0.19962801]])))

    def test_run(self):
        # Test correctness of run method
        network = NeuralNetwork(3, 2, 1, 0.5)
        network.weights_input_to_hidden = test_w_i_h.copy()
        network.weights_hidden_to_output = test_w_h_o.copy()

        self.assertTrue(np.allclose(network.run(inputs), 0.09998924))

suite = unittest.TestLoader().loadTestsFromModule(TestMethods())
unittest.TextTestRunner().run(suite)


.....
----------------------------------------------------------------------
Ran 5 tests in 0.008s

OK
Out[75]:
<unittest.runner.TextTestResult run=5 errors=0 failures=0>

Extra Exploration - Choose Hyperparameters Programatically

Be careful that it takes a while to run the following code.

Suggested by the following link, the code is to choose the hyperparameters programatically. https://discussions.udacity.com/t/learning-rate-hyperparameter/216978/13 (I am not sure why I cannot bring the test loss under 0.05 as it mentioned.)

The steps are as follows.

  • Increase the hidden units
  • Decrease the learning rate
  • Increase the number of epochs

Because we are using SGD, I use the average of last 100 point to evaluate the validation loss. This is just a arbitrary number that I picked. It's better to run the optimization a few iterations but I just keep it simple here.


In [47]:
import sys

def train_with_hyperparameters(hidden_nodes, learning_rate = 0.1, epochs = 3000, output_nodes = 1, num_plot = 0):
    x_label = 'hidden_nodes: {}, learning_rate: {}, epochs: {}, num_plot: {}'.format(hidden_nodes, learning_rate, epochs, num_plot)
    print(x_label)

    N_i = train_features.shape[1]
    network = NeuralNetwork(N_i, hidden_nodes, output_nodes, learning_rate)

    losses = {'train':[], 'validation':[]}
    for e in range(epochs):
        # Go through a random batch of 128 records from the training data set
        batch = np.random.choice(train_features.index, size=128)

        for record, target in zip(train_features.ix[batch].values, 
                                  train_targets.ix[batch]['cnt']):
            network.train(record, target)

        # Printing out the training progress
        train_loss = MSE(network.run(train_features), train_targets['cnt'].values)
        val_loss = MSE(network.run(val_features), val_targets['cnt'].values)
        sys.stdout.write("\rProgress: " + str(100 * e/float(epochs))[:4] \
                         + "% ... Training loss: " + str(train_loss)[:5] \
                         + " ... Validation loss: " + str(val_loss)[:5]) 

        losses['train'].append(train_loss)
        losses['validation'].append(val_loss)

    plot(losses, num_plot, x_label)
    return avg_validation_loss(losses)

# Average loss of last 100 data points
def avg_validation_loss(losses):
    return sum(losses['validation'][-100:]) / 100

def plot(losses, num_plot, x_label):        
    fig = plt.figure(num_plot)
    plt.plot(losses['train'], label='Training loss')
    plt.plot(losses['validation'], label='Validation loss')
    plt.legend()
    plt.ylim(ymax=0.5)    
    ax = fig.add_subplot(111)
    ax.set_xlabel(x_label)

In [48]:
def plot_validation_loss(losses, num_plots, x_label):
    fig = plt.figure(num_plots)
    x = losses['num']
    y = losses['avg_validation_loss']
    print(x)
    print(y)
    plt.plot(x, y)
    ax = fig.add_subplot(111)
    ax.set_xlabel(x_label)
    ax.set_ylabel('Average Last 100 points validation Loss')
    
def best_param(losses):    
    return losses['num'][np.argmin(losses['avg_validation_loss'])]

Using partial function makes the code looks neat but don't know why it throws overflow error frequently. So I commented the code.


In [49]:
# from functools import partial

# def train_func(hidden_nodes, learning_rate, epochs, num_plot):
#     return train_with_hyperparameters(hidden_nodes, learning_rate, epochs, 1, num_plot)

# def find_best_params(param_list, train_func):
#     losses = {'num': [], 'avg_validation_loss': []}

#     for (index, param_value) in enumerate(param_list):
#         avg_validation_error = train_func(param_value, num_plot = index)
#         losses['num'].append(param_value)
#         losses['avg_validation_loss'].append(avg_validation_error)
        
#     return losses

# For step 1.
# def find_best_hidden_nodes():
#     param_list = range(28, 112, 28)
#     func = partial(train_func, learning_rate = 1.0, epochs = 100)
#     losses = find_best_params(param_list, func)
#     num_plots = len(param_list)
#     plot_validation_loss(losses, num_plots, 'hidden_nodes')
    
#     return best_param(losses)

Step 1. Optimize the hidden_nodes


In [62]:
param_list = range(14, 70, 14)

def find_best_hidden_nodes():
    losses = {'num': [], 'avg_validation_loss': []}

    for (index, param_value) in enumerate(param_list):
        avg_validation_error = train_with_hyperparameters(hidden_nodes = param_value, learning_rate = 0.1, epochs = 1000, num_plot = index)
        losses['num'].append(param_value)
        losses['avg_validation_loss'].append(avg_validation_error)

    return losses

losses = find_best_hidden_nodes()
best_hidden_nodes = best_param(losses)
print(best_hidden_nodes)
plot_validation_loss(losses,  len(param_list), 'hidden_nodes')


hidden_nodes: 14, learning_rate: 0.1, epochs: 1000, num_plot: 0
Progress: 99.9% ... Training loss: 0.068 ... Validation loss: 0.199hidden_nodes: 28, learning_rate: 0.1, epochs: 1000, num_plot: 1
Progress: 99.9% ... Training loss: 0.062 ... Validation loss: 0.147hidden_nodes: 42, learning_rate: 0.1, epochs: 1000, num_plot: 2
Progress: 99.9% ... Training loss: 0.064 ... Validation loss: 0.127hidden_nodes: 56, learning_rate: 0.1, epochs: 1000, num_plot: 3
Progress: 99.9% ... Training loss: 0.058 ... Validation loss: 0.14156
[14, 28, 42, 56]
[0.19982260315244565, 0.14621541682701431, 0.16491224674071589, 0.13853538488365927]

Step 2. Decrease learning rate


In [35]:
param_list = range(1, 10, 3)

def find_best_learning_rate():
    losses = {'num': [], 'avg_validation_loss': []}

    for (index, param_value) in enumerate(param_list):
        learning_rate = param_value / 100.0
        avg_validation_error = train_with_hyperparameters(hidden_nodes = best_hidden_nodes, learning_rate = learning_rate, epochs = 1000, num_plot = index)
        losses['num'].append(learning_rate)
        losses['avg_validation_loss'].append(avg_validation_error)

    return losses

losses = find_best_learning_rate()
best_learning_rate = best_param(losses)
print(best_learning_rate)
plot_validation_loss(losses,  len(param_list), 'learning_rate')


hidden_nodes: 84, learning_rate: 0.01, epochs: 1000, num_plot: 0
Progress: 99.9% ... Training loss: 0.106 ... Validation loss: 0.204hidden_nodes: 84, learning_rate: 0.04, epochs: 1000, num_plot: 1
Progress: 99.9% ... Training loss: 0.066 ... Validation loss: 0.184hidden_nodes: 84, learning_rate: 0.07, epochs: 1000, num_plot: 2
Progress: 99.9% ... Training loss: 0.054 ... Validation loss: 0.1660.04
[0.01, 0.04, 0.07]
[0.23058972823509005, 0.14856238508743017, 0.15613732788280296]

Step 3. Increase epochs


In [39]:
param_list = range(1000, 5000, 1000)

def find_best_epochs():
    losses = {'num': [], 'avg_validation_loss': []}

    for (index, param_value) in enumerate(param_list):
        avg_validation_error = train_with_hyperparameters(hidden_nodes = best_hidden_nodes, learning_rate = best_learning_rate, epochs = param_value, output_nodes = 1, num_plot = index)
        losses['num'].append(param_value)
        losses['avg_validation_loss'].append(avg_validation_error)

    return losses

losses = find_best_epochs()
best_epochs = best_param(losses)
print(best_epochs)
plot_validation_loss(losses,  len(param_list), 'epochs')


hidden_nodes: 84, learning_rate: 0.04, epochs: 1000, num_plot: 0
Progress: 99.9% ... Training loss: 0.066 ... Validation loss: 0.171hidden_nodes: 84, learning_rate: 0.04, epochs: 2000, num_plot: 1
Progress: 99.9% ... Training loss: 0.055 ... Validation loss: 0.148hidden_nodes: 84, learning_rate: 0.04, epochs: 3000, num_plot: 2
Progress: 99.9% ... Training loss: 0.063 ... Validation loss: 0.179hidden_nodes: 84, learning_rate: 0.04, epochs: 4000, num_plot: 3
Progress: 99.9% ... Training loss: 0.050 ... Validation loss: 0.2072000
[1000, 2000, 3000, 4000]
[0.15984166311488382, 0.13528683465465044, 0.14829599168438848, 0.19881746701712213]

In [41]:
params_result = 'best hidden_nodes = {}, learning_rate = {}, epochs = {}'.format(best_hidden_nodes, best_learning_rate, best_epochs)

print(params_result)


best hidden_nodes = 84, learning_rate = 0.04, epochs = 2000