text: def accuracy(actual, preds):
      '''
      INPUT
      preds - predictions as a numpy array or pandas series
      actual - actual values as a numpy array or pandas series
      
      OUTPUT:
      returns the accuracy as a float
      '''
      return np.sum(preds == actual)/len(actual)
  def precision(actual, preds):
      '''
      INPUT
      (assumes positive = 1 and negative = 0)
      preds - predictions as a numpy array or pandas series 
      actual - actual values as a numpy array or pandas series
      
      OUTPUT:
      returns the precision as a float
      '''
      tp = len(np.intersect1d(np.where(preds==1), np.where(actual==1)))
      pred_pos = (preds==1).sum()
      return tp/(pred_pos)
  def recall(actual, preds):
      '''
      INPUT
      preds - predictions as a numpy array or pandas series
      actual - actual values as a numpy array or pandas series
      
      OUTPUT:
      returns the recall as a float
      '''
      tp = len(np.intersect1d(np.where(preds==1), np.where(actual==1)))
      act_pos = (actual==1).sum()
      return tp/act_pos
  
  def f1(preds, actual):
      '''
      INPUT
      preds - predictions as a numpy array or pandas series
      actual - actual values as a numpy array or pandas series
      
      OUTPUT:
      returns the f1score as a float
      '''
      tp = len(np.intersect1d(np.where(preds==1), np.where(actual==1)))
      pred_pos = (preds==1).sum()
      prec = tp/(pred_pos)
      act_pos = (actual==1).sum()
      recall = tp/act_pos
      return 2*(prec*recall)/(prec+recall)
  
  def build_roc_auc(model, X_train, X_test, y_train, y_test):
      '''
      INPUT:
      stuff 
      OUTPUT:
      auc - returns auc as a float
      prints the roc curve
      '''
      import numpy as np
      import matplotlib.pyplot as plt
      from itertools import cycle
      from sklearn.metrics import roc_curve, auc, roc_auc_score
      from scipy import interp
      
      y_preds = model.fit(X_train, y_train).predict_proba(X_test)
      # Compute ROC curve and ROC area for each class
      fpr = dict()
      tpr = dict()
      roc_auc = dict()
      for i in range(len(y_test)):
          fpr[i], tpr[i], _ = roc_curve(y_test, y_preds[:, 1])
          roc_auc[i] = auc(fpr[i], tpr[i])
  
      # Compute micro-average ROC curve and ROC area
      fpr["micro"], tpr["micro"], _ = roc_curve(y_test.ravel(), y_preds[:, 1].ravel())
      roc_auc["micro"] = auc(fpr["micro"], tpr["micro"])
      
      plt.plot(fpr[2], tpr[2], color='darkorange',
               lw=2, label='ROC curve (area = %0.2f)' % roc_auc[2])
      plt.plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--')
      plt.xlim([0.0, 1.0])
      plt.ylim([0.0, 1.05])
      plt.xlabel('False Positive Rate')
      plt.ylabel('True Positive Rate')
      plt.title('Receiver operating characteristic example')
      plt.show()
      
      return roc_auc_score(y_test, np.round(y_preds[:, 1]))
  