Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Custom Models, Layers, and Loss Functions with TensorFlow/Week 2 - Custom Loss Functions/C1W2_Assignment.ipynb
Views: 13373
W2 Assignment: Creating a Custom Loss Function
This short exercise will require you to write a simple linear regression neural network that is trained on two arrays: (inputs) and (labels), where the relationship between each corresponding element is .
You will need to implement a custom loss function that returns the root mean square error (RMSE) of . Let's begin!
Define the custom loss function (TODO)
Define the custom loss function below called my_rmse()
that returns the RMSE between the target (y_true
) and prediction (y_pred
).
You will return , where =
error: the difference between the true label and predicted label.
sqr_error: the square of the error.
mean_sqr_error: the mean of the square of the error
sqrt_mean_sqr_error: the square root of hte mean of the square of the error (the root mean squared error).
Please use
K.mean
,K.square
, andK.sqrt
The steps are broken down into separate lines of code for clarity. Feel free to combine them, and just remember to return the root mean squared error.
All public tests passed
Define a model using the custom loss function (TODO)
Similar to the ungraded labs, you will define a simple model and pass the function you just coded as the loss.
When compiling the model, you'll choose the
sgd
optimizer and set theloss
parameter to the custom loss function that you just defined.For grading purposes, please leave the other parameter values as is.
All public tests passed