def computeAccuracy(model, size, top):
accuracy = []<EOL>filename = os.path.join(os.path.dirname(__file__), "<STR_LIT>")<EOL>with zipfile.ZipFile(filename) as archive:<EOL><INDENT>with archive.open("<STR_LIT>") as datafile:<EOL><INDENT>for _ in range(<NUM_LIT:7>):<EOL><INDENT>next(datafile)<EOL><DEDENT>for _ in range(LEARNING_RECORDS):<EOL><INDENT>next(datafile)<EOL><DEDENT>for _ in range(size):<EOL><INDENT>pages = readUserSession(datafile)<EOL>model.resetSequenceStates()<EOL>for i in range(len(pages) - <NUM_LIT:1>):<EOL><INDENT>result = model.run({"<STR_LIT>": pages[i]})<EOL>inferences = result.inferences["<STR_LIT>"][<NUM_LIT:1>]<EOL>predicted = sorted(list(inferences.items()), key=itemgetter(<NUM_LIT:1>), reverse=True)[:top]<EOL>accuracy.append(<NUM_LIT:1> if pages[i + <NUM_LIT:1>] in list(zip(*predicted))[<NUM_LIT:0>] else <NUM_LIT:0>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return np.mean(accuracy)<EOL>
Compute prediction accuracy by checking if the next page in the sequence is
within the top N predictions calculated by the model
Args:
  model: HTM model
  size: Sample size
  top: top N predictions to use

Returns: Probability the next page in the sequence is within the top N
         predicted pages