<commit_before>package hex.glm;

import hex.*;
import hex.ModelMetrics.MetricBuilder;
import hex.ModelMetricsBinomial.MetricBuilderBinomial;
import hex.ModelMetricsRegression.MetricBuilderRegression;
import hex.glm.GLMModel.GLMParameters;
import hex.glm.GLMModel.GLMParameters.Family;
import water.DKV;
import water.Iced;
import water.Key;
import water.fvec.Frame;
import water.util.ArrayUtils;

/**
 * Class for GLMValidation.
 *
 * @author tomasnykodym
 *
 */
public class GLMValidation extends MetricBuilderBinomial<GLMValidation> {
  final double [] _ymu;
  double residual_deviance;
  double null_deviance;
  long nobs;
  double aic;// internal AIC used only for poisson family!
  private double _aic2;// internal AIC used only for poisson family!
  final GLMModel.GLMParameters _glm;
  final private int _rank;
  final double _threshold;
  AUC2 _auc2;
  MetricBuilder _metricBuilder;
  boolean _intercept = true;
  public GLMValidation(String[] domain, double ymu, GLMParameters glm, int rank, double threshold){
    super(domain);
    _rank = rank;
    _ymu = new double[]{ymu};
    _glm = glm;
    _threshold = threshold;
    _metricBuilder = _glm._family == Family.binomial
      ?new MetricBuilderBinomial(domain)
      :new MetricBuilderRegression();
  }

  public double explainedDev(){
    return 1.0 - residualDeviance()/nullDeviance();
  }


  @Override public double[] perRow(double ds[], float[] yact, Model m) {
    _metricBuilder.perRow(ds,yact,m);
    if(!ArrayUtils.hasNaNsOrInfs(ds)) {
      if (_glm._family == Family.binomial)
        add2(yact[0], ds[2]);<commit_msg>Fix in GLM scoring - check actual for NaNs as well (was only checking prediction, so NaN in actuals would turn all metrics to NaNs).<commit_after>package hex.glm;

import hex.*;
import hex.ModelMetrics.MetricBuilder;
import hex.ModelMetricsBinomial.MetricBuilderBinomial;
import hex.ModelMetricsRegression.MetricBuilderRegression;
import hex.glm.GLMModel.GLMParameters;
import hex.glm.GLMModel.GLMParameters.Family;
import water.DKV;
import water.Iced;
import water.Key;
import water.fvec.Frame;
import water.util.ArrayUtils;

/**
 * Class for GLMValidation.
 *
 * @author tomasnykodym
 *
 */
public class GLMValidation extends MetricBuilderBinomial<GLMValidation> {
  final double [] _ymu;
  double residual_deviance;
  double null_deviance;
  long nobs;
  double aic;// internal AIC used only for poisson family!
  private double _aic2;// internal AIC used only for poisson family!
  final GLMModel.GLMParameters _glm;
  final private int _rank;
  final double _threshold;
  AUC2 _auc2;
  MetricBuilder _metricBuilder;
  boolean _intercept = true;
  public GLMValidation(String[] domain, double ymu, GLMParameters glm, int rank, double threshold){
    super(domain);
    _rank = rank;
    _ymu = new double[]{ymu};
    _glm = glm;
    _threshold = threshold;
    _metricBuilder = _glm._family == Family.binomial
      ?new MetricBuilderBinomial(domain)
      :new MetricBuilderRegression();
  }

  public double explainedDev(){
    return 1.0 - residualDeviance()/nullDeviance();
  }


  @Override public double[] perRow(double ds[], float[] yact, Model m) {
    _metricBuilder.perRow(ds,yact,m);
    if(!ArrayUtils.hasNaNsOrInfs(ds) && !ArrayUtils.hasNaNsOrInfs(yact)) {
      if (_glm._family == Family.binomial)
        add2(yact[0], ds[2]);
{'fraction_non_alphanumeric': 0.10035949670461354, 'fraction_numerical': 0.004793289394847214, 'mean_word_length': 4.402912621359223, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3220318', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1070, 'n_words': 281}