docstr: Writes out resulting scores to text files: First checks for class-internal-df (typically current) fold,
  gets resulting scores, writes them to a text file and pickles data frame. Also checks if data-frame pickles of
  all folds of cross-validation exist in exp_dir. If true, loads all dataframes, aggregates test sets over folds,
  and calculates and writes out overall metrics.
docstr_tok: ["Writes","out","resulting","scores","to","text","files",":","First","checks","for","class-internal-df","(","typically","current",")","fold",",","gets","resulting","scores",",","writes","them","to","a","text","file","and","pickles","data","frame",".","Also","checks","if","data-frame","pickles","of","all","folds","of","cross-validation","exist","in","exp_dir",".","If","true",",","loads","all","dataframes",",","aggregates","test","sets","over","folds",",","and","calculates","and","writes","out","overall","metrics","."]
code: def score_test_df(self, internal_df=True):
      """
      Writes out resulting scores to text files: First checks for class-internal-df (typically current) fold,
      gets resulting scores, writes them to a text file and pickles data frame. Also checks if data-frame pickles of
      all folds of cross-validation exist in exp_dir. If true, loads all dataframes, aggregates test sets over folds,
      and calculates and writes out overall metrics.
      """
      if internal_df:
          self.test_df.to_pickle(
              os.path.join(
                  self.cf.exp_dir,
                  "{}_test_df.pickle".format(self.cf.fold),
              )
          )
          stats, _ = self.return_metrics()
  
          with open(
              os.path.join(self.cf.exp_dir, "results.txt"), "a"
          ) as handle:
              handle.write("\n****************************\n")
              handle.write(
                  "\nresults for fold {} \n".format(self.cf.fold)
              )
              handle.write("\n****************************\n")
              handle.write(
                  "\nfold df shape {}\n  \n".format(self.test_df.shape)
              )
              for s in stats:
                  handle.write(
                      "AUC {:0.4f}  AP {:0.4f} {} \n".format(
                          s["auc"], s["ap"], s["name"]
                      )
                  )
  
      fold_df_paths = [
          ii
          for ii in os.listdir(self.cf.exp_dir)
          if "test_df.pickle" in ii
      ]
      if len(fold_df_paths) == self.cf.n_cv_splits:
          with open(
              os.path.join(self.cf.exp_dir, "results.txt"), "a"
          ) as handle:
              self.cf.fold = "overall"
              dfs_list = [
                  pd.read_pickle(os.path.join(self.cf.exp_dir, ii))
                  for ii in fold_df_paths
              ]
              for ix, df in enumerate(dfs_list):
                  df["fold"] = ix
              self.test_df = pd.concat(dfs_list)
              stats, _ = self.return_metrics()
              handle.write("\n****************************\n")
              handle.write("\nOVERALL RESULTS \n")
              handle.write("\n****************************\n")
              handle.write(
                  "\ndf shape \n  \n".format(self.test_df.shape)
              )
              for s in stats:
                  handle.write(
                      "\nAUC {:0.4f} (mu {:0.4f})  AP {:0.4f} (mu {:0.4f})  {}\n ".format(
                          s["auc"],
                          s["mean_auc"],
                          s["ap"],
                          s["mean_ap"],
                          s["name"],
                      )
                  )
              results_table_path = os.path.join(
                  ("/").join(self.cf.exp_dir.split("/")[:-1]),
                  "results_table.txt",
              )
              with open(results_table_path, "a") as handle2:
                  for s in stats:
                      handle2.write(
                          "\nAUC {:0.4f} (mu {:0.4f})  AP {:0.4f} (mu {:0.4f})  {} {}".format(
                              s["auc"],
                              s["mean_auc"],
                              s["ap"],
                              s["mean_ap"],
                              s["name"],
                              self.cf.exp_dir.split("/")[-1],
                          )
                      )
                  handle2.write("\n")
  
file_path: medicaldetectiontoolkit/evaluator.py
imports: import os
  import numpy
  import pandas
  from sklearn.metrics import roc_auc_score, average_precision_score
  from sklearn.metrics import roc_curve, precision_recall_curve
  import utils.model_utils
  import plotting
  from multiprocessing import Pool
label_desc: Use image node_id 4 for calling the Evaluator obj's underlying member method code with example usage: obj.score_test_df(internal_df) without return types