Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# GRADED FUNCTION: classify def classify ( test _ Q 1 , test _ Q 2 , y _ test, threshold, model, batch _ size

# GRADED FUNCTION: classify
def classify(test_Q1, test_Q2, y_test, threshold, model, batch_size=64, verbose=True):
"""Function to test the accuracy of the model.
Args:
test_Q1(numpy.ndarray): Array of Q1 questions. Each element of the array would be a string.
test_Q2(numpy.ndarray): Array of Q2 questions. Each element of the array would be a string.
y_test (numpy.ndarray): Array of actual target.
threshold (float): Desired threshold
model (tensorflow.Keras.Model): The Siamese model.
batch_size (int, optional): Size of the batches. Defaults to 64.
Returns:
float: Accuracy of the model
numpy.array: confusion matrix
"""
y_pred =[]
test_gen = tf.data.Dataset.from_tensor_slices(((test_Q1, test_Q2),None)).batch(batch_size=batch_size)
### START CODE HERE ###
pred = model.predict(test_gen)
_, n_feat = pred.shape
v1= None
v2= None
# Compute the cosine similarity. Using `tf.math.reduce_sum`.
# Don't forget to use the appropriate axis argument.
d = None
# Check if d>threshold to make predictions
y_pred = tf.cast((d > threshold), tf.float64)
# take the average of correct predictions to get the accuracy
accuracy = tf.math.reduce_mean(y_pred)
# compute the confusion matrix using `tf.math.confusion_matrix`
cm = tf.math.confusion_matrix(accuracy)
### END CODE HERE ###
return accuracy, cm

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

Students also viewed these Databases questions

Question

List and briefly define key requirements for wireless LANs.

Answered: 1 week ago