// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.cloud.automl.v1beta1;

import "google/api/annotations.proto";

option go_package = "google.golang.org/genproto/googleapis/cloud/automl/v1beta1;automl";
option java_outer_classname = "ClassificationProto";
option java_package = "com.google.cloud.automl.v1beta1";
option php_namespace = "Google\\Cloud\\AutoMl\\V1beta1";


// Contains annotation details specific to classification.
message ClassificationAnnotation {
  // Output only. A confidence estimate between 0.0 and 1.0. A higher value
  // means greater confidence that the annotation is positive. If a user
  // approves an annotation as negative or positive, the score value remains
  // unchanged. If a user creates an annotation, the score is 0 for negative or
  // 1 for positive.
  float score = 1;
}

// Model evaluation metrics for classification problems.
// Visible only to v1beta1
message ClassificationEvaluationMetrics {
  // Metrics for a single confidence threshold.
  message ConfidenceMetricsEntry {
    // Output only. The confidence threshold value used to compute the metrics.
    float confidence_threshold = 1;

    // Output only. Recall under the given confidence threshold.
    float recall = 2;

    // Output only. Precision under the given confidence threshold.
    float precision = 3;

    // Output only. The harmonic mean of recall and precision.
    float f1_score = 4;

    // Output only. The recall when only considering the label that has the
    // highest prediction score and not below the confidence threshold for each
    // example.
    float recall_at1 = 5;

    // Output only. The precision when only considering the label that has the
    // highest predictionscore and not below the confidence threshold for each
    // example.
    float precision_at1 = 6;

    // Output only. The harmonic mean of [recall_at1][google.cloud.automl.v1beta1.ClassificationEvaluationMetrics.ConfidenceMetricsEntry.recall_at1] and [precision_at1][google.cloud.automl.v1beta1.ClassificationEvaluationMetrics.ConfidenceMetricsEntry.precision_at1].
    float f1_score_at1 = 7;
  }

  // Confusion matrix of the model running the classification.
  message ConfusionMatrix {
    // Output only. A row in the confusion matrix.
    message Row {
      // Output only. Value of the specific cell in the confusion matrix.
      // The number of values each row is equal to the size of
      // annotatin_spec_id.
      repeated int32 example_count = 1;
    }

    // Output only. IDs of the annotation specs used in the confusion matrix.
    repeated string annotation_spec_id = 1;

    // Output only. Rows in the confusion matrix. The number of rows is equal to
    // the size of `annotation_spec_id`.
    // `row[i].value[j]` is the number of examples that have ground truth of the
    // `annotation_spec_id[i]` and are predicted as `annotation_spec_id[j]` by
    // the model being evaluated.
    repeated Row row = 2;
  }

  // Output only. The Area under precision recall curve metric.
  float au_prc = 1;

  // Output only. The Area under precision recall curve metric based on priors.
  float base_au_prc = 2;

  // Output only. Metrics that have confidence thresholds.
  // Precision-recall curve can be derived from it.
  repeated ConfidenceMetricsEntry confidence_metrics_entry = 3;

  // Output only. Confusion matrix of the evaluation.
  // Only set for MULTICLASS classification problems where number
  // of labels is no more than 10.
  // Only set for model level evaluation, not for evaluation per label.
  ConfusionMatrix confusion_matrix = 4;

  // Output only. The annotation spec ids used for this evaluation.
  repeated string annotation_spec_id = 5;
}

// Type of the classification problem.
enum ClassificationType {
  // Should not be used, an un-set enum has this value by default.
  CLASSIFICATION_TYPE_UNSPECIFIED = 0;

  // At most one label is allowed per example.
  MULTICLASS = 1;

  // Multiple labels are allowed for one example.
  MULTILABEL = 2;
}
