<jupyter_start><jupyter_text>Récap en Tensorflow<jupyter_code>%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import tensorflow as tf
from tensorflow import keras
plt.style.use('ggplot')
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train.shape
x_test.shape
plt.imshow(x_train[0])
model = keras.Sequential([
    keras.layers.Flatten(input_shape=(x_train.shape[1], x_train.shape[2])),
    keras.layers.Dense(100, activation='relu'),
    keras.layers.Dense(10, activation='sigmoid')
])

model.compile(
    optimizer='adam',
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy']
)

model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test,y_test)
prediction1 = model.predict(x_test)
np.argmax(prediction1[5])
plt.imshow(x_test[5])
y_label = [np.argmax(y) for y in prediction1]
cm = tf.math.confusion_matrix(labels=y_test, predictions=y_label)
plt.figure(figsize=(16, 8))
sns.heatmap(cm, annot=True, fmt='d')
plt.ylabel('Vraie')
plt.xlabel('Valeurs prédites')
x_train_2 = x_train/255
x_test_2 = x_test/255
model_2 = keras.Sequential([
    keras.layers.Flatten(input_shape=(x_train_2.shape[1], x_train_2.shape[2])),
    keras.layers.Dense(100, activation='relu'),
    keras.layers.Dense(10, activation='sigmoid')
])

model_2.compile(
    optimizer='adam',
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy']
)

model_2.fit(x_train_2, y_train, epochs=5)
model_2.evaluate(x_test_2, y_test)
prediction_2 = model_2.predict(x_test_2)
np.argmax(prediction_2[0])
plt.imshow(x_test[0])
y_label_2 = [np.argmax(y) for y in prediction_2]
cm_2 = tf.math.confusion_matrix(labels=y_test, predictions=y_label_2)
plt.figure(figsize=(16, 8))
sns.heatmap(cm_2, annot=True, fmt='d')
plt.ylabel('Vraie')
plt.xlabel('Valeurs prédites')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15059588299024917, 'fraction_numerical': 0.029794149512459372, 'mean_word_length': 6.8931623931623935, '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': '200359', 'license': 'MIT', 'n_tokens_mistral': 794, 'n_tokens_neox': 761, 'n_words': 112, 'path': 'python/recap_knn.ipynb', 'repo_name': 'camara94/tensorflow-keras-python', 'size': '1846'}