Question: Machine learning question, use jupyter lab, no AI plz: Import this: import sys from packaging import version import sklearn import matplotlib.pyplot as plt import numpy

Machine learning question, use jupyter lab, no AI plz:
Import this:
import sys
from packaging import version
import sklearn
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from sklearn.preprocessing import add_dummy_feature
from sklearn.datasets import make_blobs
from sklearn import metrics #Import scikit-learn metrics module for accuracy calculation
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
print("Sklearn package",sys.version_info)
print("Sklearn package",sklearn.__version__)
print("TensorFlow version:", tf.__version__)
assert sys.version_info >=(3,7)
assert version.parse(sklearn.__version__)>= version.parse("1.0.1")
plt.rc('font', size=12)
plt.rc('axes', labelsize=14, titlesize=14)
plt.rc('legend', fontsize=14)
plt.rc('xtick', labelsize=10)
plt.rc('ytick', labelsize=10)
----
Questions:
2.1. Load and prepare the MNIST dataset. The pixel values of the images range from 0 through 255. Scale these values to a range of 0 to 1 by dividing the values by 255.0.
2.2. This also converts the sample data from integers to floating-point numbers:
tf.random.set_seed(1)
mnist = tf.keras.datasets.mnist
(x_train, y_train),(x_test, y_test)= mnist.load_data()
print(x_train.shape,y_train.shape,x_test.shape,y_test.shape)
x_train, x_test = x_train /255.0, x_test /255.0
3. Q1
3.1. Using the keras Sequential Model:
3.1.1. Construct a neural network classification model that has two layers, input layer, and an output later.
3.1.2. The first hidden layer has 128 neurons and the second hidden layer has 64 neuron.
3.1.3. The output layer has 10 output units since we have 10 classes.
3.1.4. Both the hidden layers use the 'relu' activation function.
3.1.5. Using a learning rate of 0.001, epochs=10, batch_size=64 and 'adam' as the optimization algorithm
3.1.6. Print the accuracy of the model on the testing dataset, x_test
3.1.7. Accuracy will be around 97%
#Write your code here..
#Do NOT CHANGE THIS CODE
#Testing some images
predictions = model(x_test[:5]).numpy()
y_pred = np.argmax(predictions,axis=1)
print("Predicted Class Labels for some testing records")
print(y_pred)
print("True Class Labels for some testing records")
print(y_test[:5])

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!