We appreciate your patience while we actively develop and enhance our content for a better experience.
Sample Code
import tensorflow as tf def main(): print("This program demonstrates how to use TensorFlow to create a neural network to classify handwritten digits from the MNIST dataset.") # Load the MNIST dataset mnist = tf.keras.datasets.mnist (X_train, y_train), (X_test, y_test) = mnist.load_data() # Normalize the data X_train, X_test = X_train / 255.0, X_test / 255.0 # Create a simple neural network model model = tf.keras.models.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(10, activation='softmax') ]) # Compile the model model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) # Train the model model.fit(X_train, y_train, epochs=5) # Evaluate the model on the test dataset loss, accuracy = model.evaluate(X_test, y_test) print(f"Accuracy of the neural network on the test set: {accuracy * 100:.2f}%") if __name__ == "__main__": main()