<jupyter_start><jupyter_text>Machine Learng Ex - 01<jupyter_code>import tensorflow as tf
from tensorflow.keras import datasets, layers, models<jupyter_output><empty_output><jupyter_text>Load the Data Set<jupyter_code>mnist = datasets.mnist<jupyter_output><empty_output><jupyter_text>Preprocessing  Sequence Padding  One-Hot Encoding  Train Test Sets<jupyter_code>(x_train, y_train), (x_test, y_test) = mnist.load_data()<jupyter_output><empty_output><jupyter_text>Normalization<jupyter_code>x_train, x_test = x_train / 255.0, x_test / 255.0<jupyter_output><empty_output><jupyter_text>Model Architecture  Sequential Model  Multilayer Perceptron (MLP) - ANN  Binary Classification  Multi-Class Classification<jupyter_code># Construct a neural network model
model = models.Sequential()
model.add(layers.Flatten(input_shape=(28, 28)))
model.add(layers.Dense(512, activation=tf.nn.relu))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(10, activation=tf.nn.softmax))<jupyter_output><empty_output><jupyter_text>Regression  Convolutional Neural Network (CNN)  Recurrent Neural Network (RNN)  Compile Model  MLP: Binary Classification  MLP: Multi-Class Classification<jupyter_code>model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])<jupyter_output><empty_output><jupyter_text>MLP: Regression  Recurrent Neural Network  Model Training  Set the batch size<jupyter_code># Input shape and batch size
batch_size = 32
print(x_train.shape[0])
print(x_train.shape[0]//batch_size + 1)<jupyter_output><empty_output><jupyter_text>Fit the data<jupyter_code># Train and evaluate the model
model.fit(x_train, y_train, epochs=5)<jupyter_output>Epoch 1/5
1875/1875 [==============================] - 9s 5ms/step - loss: 0.2230 - accuracy: 0.9337
Epoch 2/5
1875/1875 [==============================] - 8s 4ms/step - loss: 0.0986 - accuracy: 0.9700
Epoch 3/5
1875/1875 [==============================] - 9s 5ms/step - loss: 0.0696 - accuracy: 0.9779
Epoch 4/5
1875/1875 [==============================] - 9s 5ms/step - loss: 0.0542 - accuracy: 0.9830
Epoch 5/5
1875/1875 [==============================] - 9s 5ms/step - loss: 0.0441 - accuracy: 0.9855
313/313 [==============================] - 1s 2ms/step - loss: 0.0650 - accuracy: 0.9809<jupyter_text>Evaluate Your Model’s Performance<jupyter_code>model.evaluate(x_test, y_test)<jupyter_output><empty_output><jupyter_text>Prediction<jupyter_code>>>> model3.predict(x_test4, batch_size=32)
>>> model3.predict_classes(x_test4,batch_size=32)<jupyter_output><empty_output><jupyter_text>Save/Reload Models<jupyter_code>>>> from keras.models import load_model
>>> model3.save('model_file.h5')
>>> my_model = load_model('my_model.h5')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1812250815512867, 'fraction_numerical': 0.06016672707502718, 'mean_word_length': 7.117647058823529, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 59, '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': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '460118', 'license': 'MIT', 'n_tokens_mistral': 1116, 'n_tokens_neox': 977, 'n_words': 172, 'path': '1. Introduction to TensorFlow/AZ/ANN/Regression/learn.ipynb', 'repo_name': 'AmirRazaMBA/TensorFlow-Certification', 'size': '2759'}