def accuracy(self):
    """Get accuracy numbers for each target and overall.

    Returns:
      A DataFrame with two columns: 'class' and 'accuracy'. It also contains the overall
      accuracy with class being '_all'.

    Raises:
      Exception if the CSV headers do not include 'target' or 'predicted', or BigQuery
      does not return 'target' or 'predicted' column.
    """

    if self._input_csv_files:
      df = self._get_data_from_csv_files()
      if 'target' not in df or 'predicted' not in df:
        raise ValueError('Cannot find "target" or "predicted" column')

      labels = sorted(set(df['target']) | set(df['predicted']))
      accuracy_results = []

      for label in labels:
        correct_count = len(df[(df['target'] == df['predicted']) & (df['target'] == label)])
        total_count = len(df[(df['target'] == label)])
        accuracy_results.append({
            'target': label,
            'accuracy': float(correct_count) / total_count if total_count > 0 else 0,
            'count': total_count
        })

      total_correct_count = len(df[(df['target'] == df['predicted'])])
      if len(df) > 0:
        total_accuracy = float(total_correct_count) / len(df)
        accuracy_results.append({'target': '_all', 'accuracy': total_accuracy, 'count': len(df)})
      return pd.DataFrame(accuracy_results)
    elif self._bigquery:
      query = bq.Query("""
SELECT
  target,
  SUM(CASE WHEN target=predicted THEN 1 ELSE 0 END)/COUNT(*) as accuracy,
  COUNT(*) as count
FROM
  %s
GROUP BY
  target""" % self._bigquery)
      query_all = bq.Query("""
SELECT
  "_all" as target,
  SUM(CASE WHEN target=predicted THEN 1 ELSE 0 END)/COUNT(*) as accuracy,
  COUNT(*) as count
FROM
  %s""" % self._bigquery)

      df = self._get_data_from_bigquery([query, query_all])
      return df
Get accuracy numbers for each target and overall.

    Returns:
      A DataFrame with two columns: 'class' and 'accuracy'. It also contains the overall
      accuracy with class being '_all'.

    Raises:
      Exception if the CSV headers do not include 'target' or 'predicted', or BigQuery
      does not return 'target' or 'predicted' column.