code: def error_rate_for_model(test_model, train_set, test_set):
      """Report error rate on test_doc sentiments, using supplied model and train_docs"""
  
      train_targets = [doc.sentiment for doc in train_set]
      train_regressors = [
          test_model.dv[doc.tags[0]] for doc in train_set
      ]
      train_regressors = sm.add_constant(train_regressors)
      predictor = logistic_predictor_from_data(
          train_targets, train_regressors
      )
  
      test_regressors = [test_model.dv[doc.tags[0]] for doc in test_set]
      test_regressors = sm.add_constant(test_regressors)
  
      # Predict & evaluate
      test_predictions = predictor.predict(test_regressors)
      corrects = sum(
          np.rint(test_predictions)
          == [doc.sentiment for doc in test_set]
      )
      errors = len(test_predictions) - corrects
      error_rate = float(errors) / len(test_predictions)
      return (error_rate, errors, len(test_predictions), predictor)
  
imports: import logging
  import collections
  import io
  import re
  import tarfile
  import os.path
  import smart_open
  import gensim.utils
  import multiprocessing
  from collections import OrderedDict
  import gensim.models.doc2vec
  from gensim.models.doc2vec import Doc2Vec
  from gensim.test.test_doc2vec import ConcatenatedDoc2Vec
  import numpy
  import statsmodels.api
  from random import sample
  from collections import defaultdict
  from random import shuffle
  import random
  import random
  from gensim.test.utils import datapath
label_desc: Use image node_id 5 for calling a global function with example usage: error_rate_for_model(test_model, train_set, test_set) and returns: error_rate,  errors,  len,  predictor