<jupyter_start><jupyter_text>Essais régression avec données simples générées __Réseau simple avec une seule couche cachée et une fonction d'activation *Relu*.__<jupyter_code># Génère les données
import numpy as np
from random import random
from sklearn.model_selection import train_test_split

import numpy.random as npr
x= npr.uniform(-1,1,300)
y=x*x 

X_train, X_test, y_train, y_test = train_test_split(x , y, test_size=0.2)

# Build the model
from tensorflow.keras.layers import Input, Dense, Activation
from tensorflow.keras.models import Model
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.losses import mean_squared_error
from keras.utils.vis_utils import plot_model

inp = Input((1,))
h = Dense(10)(inp)
h1 = Activation ("relu")(h)
out = Dense(1)(h1)
model = Model(inputs=inp, outputs=out)
model.compile(Adam(),mean_squared_error)
print(model.summary())
plot_model(model,show_shapes=True)
H = model.fit(X_train,y_train,epochs=100,batch_size=30,validation_split=0.2)
# Show results
import matplotlib.pyplot as plt

plt.plot(H.history['loss'])
plt.plot(H.history['val_loss'])
plt.title('Model loss')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Train', 'Validation'])
plt.show()

test_loss = model.evaluate(X_test,y_test)
print('Le loss sur le jeu de test est :' ,test_loss)

# observed vs predicted for training
pred_train=model.predict(X_train)
plt.scatter(X_train,y_train)
plt.scatter(X_train,pred_train)
plt.legend(['Parabole-train', 'Prediction'])
plt.text(-0.2,0.8,'MSE=')
plt.text(0,0.8,np.round(np.mean((pred_train-y_train)**2),4))
plt.show()

# observed vs predicted for test
pred=model.predict(X_test)
plt.scatter(X_test,y_test)
plt.scatter(X_test,pred)
plt.legend(['Parabole-test', 'Prediction'])
plt.text(-0.2,0.8,'MSE=')
plt.text(0,0.8,np.round(np.mean((pred-y_test)**2),4))<jupyter_output><empty_output><jupyter_text>Réseau avec plusieurs couches cachées<jupyter_code>inp = Input((1,))
h = Dense(6)(inp)
h1 = Activation ("relu")(h)
h2 = Dense(4) (h1)
h3 = Activation ("sigmoid")(h2)
h4 = Dense(4) (h3)
h5 = Activation ("relu")(h4)
out = Dense(1)(h5)

model = Model(inputs=inp, outputs=out)
model.compile(Adam(),mean_squared_error)

H = model.fit(X_train,y_train,epochs=150,batch_size=30,validation_split=0.2)

# Show results
plt.plot(H.history['loss'])
plt.plot(H.history['val_loss'])
plt.title('Model loss')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.legend(['Train', 'Validation'])
plt.show()

test_loss = model.evaluate(X_test,y_test)
print('Le loss sur le jeu de test est :' ,test_loss)

pred=model.predict(X_test)

plt.scatter(X_train,y_train)
plt.scatter(X_test,pred)
plt.legend(['Hyperbole', 'Prediction'])
plt.text(-0.2,0.8,'MSE=')
plt.text(0,0.8,np.round(np.mean((pred-y_test)**2),4))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16492241068206423, 'fraction_numerical': 0.024900757849151932, 'mean_word_length': 7.477064220183486, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '607737', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1116, 'n_words': 199, 'path': '01-01-Essai.y=x2-TODO.ipynb', 'repo_name': 'will-afs/IDL', 'size': '2771'}