I've been asked to solve a problem for a project. I'm working on Python or R. I need to approximate a function with multiplayer perceptron (neural network).

The function is: $y= 2\text{cos}(x)+4$ on the interval $[0,10]$.

After reading a lot about perceptron and neural network for the approximation of functions, I found a code that helped me a lot and my program is based on this code.
Here is the code (with comments) I use to approximate my function followed by questions and examples :