Answered step by step
Verified Expert Solution
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started