<commit_before>package water.api;

import hex.AUC2;
import hex.ModelMetricsBinomial;
import water.util.TwoDimTable;

public class ModelMetricsBinomialV3<I extends ModelMetricsBinomial, S extends ModelMetricsBinomialV3<I, S>> extends ModelMetricsBase<I,S> {
  @API(help="The standard deviation of the training response.", direction=API.Direction.OUTPUT)
    public double sigma; // Belongs in a mythical ModelMetricsSupervisedV3

  @API(help="The logarithmic loss for this scoring run.", direction=API.Direction.OUTPUT)
    public double logloss;

  @API(help="The AUC for this scoring run.", direction=API.Direction.OUTPUT)
    public double AUC;

  @API(help="The Gini score for this run.", direction=API.Direction.OUTPUT)
    public double Gini;

  @API(help = "The Metrics for various thresholds.", direction = API.Direction.OUTPUT)
    public TwoDimTableBase thresholds_and_metric_scores;

  @API(help = "The Metrics for various criteria.", direction = API.Direction.OUTPUT)
    public TwoDimTableBase max_criteria_and_metric_scores;

  @Override
    public ModelMetricsBinomialV3 fillFromImpl(ModelMetricsBinomial modelMetrics) {
    super.fillFromImpl(modelMetrics);
    this.sigma = modelMetrics._sigma;
    this.logloss = modelMetrics._logloss;

    AUC2 auc = modelMetrics._auc;
    if (null != auc) {
      this.AUC  = auc._auc;
      this.Gini = auc._gini;
      
      // Fill TwoDimTable
      String[] thresholds = new String[auc._nBins];
      for( int i=0; i<auc._nBins; i++ )
        thresholds[i] = Double.toString(auc._ths[i]);
      AUC2.ThresholdCriterion crits[] = AUC2.ThresholdCriterion.VALUES;
      String[] colHeaders = new String[crits.length];
      String[] types      = new String[crits.length];
      String[] formats    = new String[crits.length];
      for( int i=0; i<crits.length; i++ ) {
        colHeaders[i] = crits[i].toString();
        types     [i] = crits[i]._isInt ? "long" : "double";
        formats   [i] = crits[i]._isInt ? "%d"   : "%f"    ;
      }
      TwoDimTable thresholdsByMetrics = new TwoDimTable("Thresholds x Metric Scores", null, thresholds, colHeaders, types, formats, "Thresholds" );
      this.thresholds_and_metric_scores = new TwoDimTableV1().fillFromImpl(thresholdsByMetrics);
      
      // Fill TwoDimTable
      TwoDimTable maxMetrics = new TwoDimTable("Maximum Metric", null, colHeaders,
                                               new String[]{"Threshold","Metric","idx"},
                                               new String[]{"double",   "double","long"},
                                               new String[]{"%f",       "%f",    "%d"},
                                               "Metric" );
      for( int i=0; i<crits.length; i++ ) {
        int idx = crits[i].max_criterion_idx(auc);
        maxMetrics.set(i,0,idx==-1 ? Double.NaN : auc._ths[idx]);
        maxMetrics.set(i,1,idx==-1 ? Double.NaN : crits[i].exec(auc,idx));
        maxMetrics.set(i,2,idx);
      }
      
      this.max_criteria_and_metric_scores = new TwoDimTableV1().fillFromImpl(maxMetrics);
    }
    return this;
  }
}
<commit_msg>Too aggressive is cutting stuff<commit_after>package water.api;

import hex.AUC2;
import hex.ModelMetricsBinomial;
import water.util.TwoDimTable;

public class ModelMetricsBinomialV3<I extends ModelMetricsBinomial, S extends ModelMetricsBinomialV3<I, S>> extends ModelMetricsBase<I,S> {
  @API(help="The standard deviation of the training response.", direction=API.Direction.OUTPUT)
    public double sigma; // Belongs in a mythical ModelMetricsSupervisedV3

  @API(help="The logarithmic loss for this scoring run.", direction=API.Direction.OUTPUT)
    public double logloss;

  @API(help="The AUC for this scoring run.", direction=API.Direction.OUTPUT)
    public double AUC;

  @API(help="The Gini score for this run.", direction=API.Direction.OUTPUT)
    public double Gini;

  @API(help = "The Metrics for various thresholds.", direction = API.Direction.OUTPUT)
    public TwoDimTableBase thresholds_and_metric_scores;

  @API(help = "The Metrics for various criteria.", direction = API.Direction.OUTPUT)
    public TwoDimTableBase max_criteria_and_metric_scores;

  @Override
    public ModelMetricsBinomialV3 fillFromImpl(ModelMetricsBinomial modelMetrics) {
    super.fillFromImpl(modelMetrics);
    this.sigma = modelMetrics._sigma;
    this.logloss = modelMetrics._logloss;

    AUC2 auc = modelMetrics._auc;
    if (null != auc) {
      this.AUC  = auc._auc;
      this.Gini = auc._gini;
      
      // Fill TwoDimTable
      String[] thresholds = new String[auc._nBins];
      for( int i=0; i<auc._nBins; i++ )
        thresholds[i] = Double.toString(auc._ths[i]);
      AUC2.ThresholdCriterion crits[] = AUC2.ThresholdCriterion.VALUES;
      String[] colHeaders = new String[crits.length];
      String[] types      = new String[crits.length];
      String[] formats    = new String[crits.length];
      for( int i=0; i<crits.length; i++ ) {
        colHeaders[i] = crits[i].toString();
        types     [i] = crits[i]._isInt ? "long" : "double";
        formats   [i] = crits[i]._isInt ? "%d"   : "%f"    ;
      }
      TwoDimTable thresholdsByMetrics = new TwoDimTable("Thresholds x Metric Scores", null, thresholds, colHeaders, types, formats, "Thresholds" );
      for( int i=0; i<auc._nBins; i++ ) {
        for (int j = 0; j < crits.length; j++) {
          double d = crits[j].exec(auc, i); // Note: casts to Object are NOT redundant
          thresholdsByMetrics.set(i, j, crits[j]._isInt ? (Object) ((long) d) : d);
        }
      }
      this.thresholds_and_metric_scores = new TwoDimTableV1().fillFromImpl(thresholdsByMetrics);
      
      // Fill TwoDimTable
      TwoDimTable maxMetrics = new TwoDimTable("Maximum Metric", null, colHeaders,
                                               new String[]{"Threshold","Metric","idx"},
                                               new String[]{"double",   "double","long"},
                                               new String[]{"%f",       "%f",    "%d"},
                                               "Metric" );
      for( int i=0; i<crits.length; i++ ) {
        int idx = crits[i].max_criterion_idx(auc);
        maxMetrics.set(i,0,idx==-1 ? Double.NaN : auc._ths[idx]);
        maxMetrics.set(i,1,idx==-1 ? Double.NaN : crits[i].exec(auc,idx));
        maxMetrics.set(i,2,idx);
      }
      
      this.max_criteria_and_metric_scores = new TwoDimTableV1().fillFromImpl(maxMetrics);
    }
    return this;
  }
}

{'fraction_non_alphanumeric': 0.12396185788988004, 'fraction_numerical': 0.00584435558289757, 'mean_word_length': 2.7352096496266514, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6959018', 'n_tokens_mistral': 2036, 'n_tokens_neox': 1946, 'n_words': 450}