Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

Recognize the features of practical performance appraisal forms

Answered: 1 week ago