Question: # GRADED FUNCTION: classify def classify ( test _ Q 1 , test _ Q 2 , y _ test, threshold, model, batch _ size
# GRADED FUNCTION: classify
def classifytestQ testQ ytest, threshold, model, batchsize verboseTrue:
Function to test the accuracy of the model.
Args:
testQnumpyndarray: Array of Q questions. Each element of the array would be a string.
testQnumpyndarray: Array of Q questions. Each element of the array would be a string.
ytest numpyndarray: Array of actual target.
threshold float: Desired threshold
model tensorflowKeras.Model: The Siamese model.
batchsize int optional: Size of the batches. Defaults to
Returns:
float: Accuracy of the model
numpy.array: confusion matrix
ypred
testgen tfdata.Dataset.fromtensorslicestestQ testQNonebatchbatchsizebatchsize
### START CODE HERE ###
pred model.predicttestgen
nfeat pred.shape
v None
v None
# Compute the cosine similarity. Using tfmath.reducesum
# Don't forget to use the appropriate axis argument.
d None
# Check if dthreshold to make predictions
ypred tfcastd threshold tffloat
# take the average of correct predictions to get the accuracy
accuracy tfmath.reducemeanypred
# compute the confusion matrix using tfmath.confusionmatrix
cm tfmath.confusionmatrixaccuracy
### END CODE HERE ###
return accuracy, cm
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
