0. This document

This is an Rmarkdown (.Rmd) document, and you may be reading the HTML version (after its compilation). Please get the .Rmd version in our website, in order to:

In case of errors, look for help or contact your instructor.

PROBLEM 1: a neural network for regression

Creating simulated data

The following lines create a dataset in an independent variable called x and a dependent variable called y.

set.seed(123)
x = rnorm(n=100, mean=0, sd=0.5)
y = 4.1 - 1.3*x - 1.5*x^2 + rnorm(n=100, mean=0, sd=0.3)
m = data.frame(x=x, y=y)

Here I don’t ask you to pay attention to how the data has been generated.

1.1. Fit the data to a neural network of a single neuron in the input layer (variable x), 5 neurons in the hidden layer, and variable y in the output layer. Write the list of weights defining the fitted network.

# Here just launch the fitting and make many
# attemps in order to get close to the real minimum

The fitted network has weights: …

1.2. Plot original data, and add in red colour the predictions the net would do over the sampled data.

# Code for plotting data (x,y)
# Code for adding points in red color to plot

1.3. Repeat exercices 1.1 and 1.2 for a network with 3 neurons in the hidden layer.

# Here your code with final plot

1.3. Explain “in a few words” how to perform “cross-validation” in order to choose the best of those two types of network (5 neurons vs 3 neurons).

Here your explanation.