code: def get_confusion_matrix(extended_test, labels):
      # Init a matrix
      sf_confusion_matrix = {
          "label": [],
          "predicted_label": [],
          "prob_default": [],
      }
      for target_l in labels:
          for predicted_l in labels:
              sf_confusion_matrix["label"].append(target_l)
              sf_confusion_matrix["predicted_label"].append(predicted_l)
              sf_confusion_matrix["prob_default"].append(0)
  
      sf_confusion_matrix = _tc.SFrame(sf_confusion_matrix)
      sf_confusion_matrix = sf_confusion_matrix.join(
          extended_test.groupby(
              ["label", "predicted_label"],
              {"count": _tc.aggregate.COUNT},
          ),
          how="left",
          on=["label", "predicted_label"],
      )
      sf_confusion_matrix = sf_confusion_matrix.fillna("count", 0)
  
      label_column = _tc.SFrame({"label": extended_test["label"]})
      predictions = extended_test["probs"]
      for i in range(0, len(labels)):
          new_test_data = label_column.add_columns(
              [
                  predictions.apply(lambda probs: probs[i]),
                  predictions.apply(lambda probs: labels[i]),
              ],
              ["prob", "predicted_label"],
          )
          if i == 0:
              test_longer_form = new_test_data
          else:
              test_longer_form = test_longer_form.append(new_test_data)
  
      if len(extended_test) == 0:
          sf_confusion_matrix = sf_confusion_matrix.rename(
              {"prob_default": "prob", "label": "target_label"}
          )
      else:
          sf_confusion_matrix = sf_confusion_matrix.join(
              test_longer_form.groupby(
                  ["label", "predicted_label"],
                  {"prob": _tc.aggregate.SUM("prob")},
              ),
              how="left",
              on=["label", "predicted_label"],
          )
          sf_confusion_matrix = sf_confusion_matrix.rename(
              {"label": "target_label"}
          ).fillna("prob", 0)
  
      def wo_divide_by_zero(a, b):
          if b == 0:
              return None
          else:
              return a * 1.0 / b
  
      sf_confusion_matrix["norm_prob"] = sf_confusion_matrix.join(
          sf_confusion_matrix.groupby(
              "target_label", {"sum_prob": _tc.aggregate.SUM("prob")}
          ),
          how="left",
      ).apply(lambda x: wo_divide_by_zero(x["prob"], x["sum_prob"]))
      return sf_confusion_matrix.fillna("norm_prob", 0)
  
file_path: turicreate/src/python/turicreate/toolkits/_evaluate_utils.py
imports: from six.moves import reduce
  import math
  import turicreate
label_desc: Use image node_id 4 for calling a global function with example usage: get_confusion_matrix(extended_test, labels) and returns: sf_confusion_matrix, None, unknown