<jupyter_start><jupyter_text><jupyter_code>import numpy as np
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.optimizers import SGD
import tensorflow as tf
import matplotlib.pyplot as plt
from numpy.random import seed
from tensorflow import set_random_seed

seed(1)
set_random_seed(2)

x =  np.random.uniform(low=0,high=360,size=10000)
y =  1+np.sin(np.deg2rad(x))

model = Sequential()
model.add(Dense(4, input_shape=(1,), kernel_initializer='uniform', activation='relu'))
model.add(Dense(60,kernel_initializer='uniform', activation='relu'))
## CHANGING THE ACTIVATION TO ANYTHING OTHER THAN linear CAUSES THE MODEL TO NOT CONVERGE; WHY?
model.add(Dense(1, kernel_initializer='uniform', activation='linear'))
model.compile(loss='mean_squared_error', optimizer='adam')

history = model.fit(x,y, epochs=100, batch_size=32, verbose=0)

plt.plot(history.history['loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.show()
# print model.summary()
loss_and_metrics = model.evaluate(x, y)
print loss_and_metrics

y1 = model.predict(x)

plt.scatter(x, y,label='test data')
plt.scatter(x, y1,label="predicted")
plt.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14004914004914004, 'fraction_numerical': 0.021294021294021293, 'mean_word_length': 7.855072463768116, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '461709', 'license': 'MIT', 'n_tokens_mistral': 464, 'n_tokens_neox': 437, 'n_words': 94, 'path': 'sine_function.ipynb', 'repo_name': 'movvas/pychallenges', 'size': '1221'}