class_docstr: This class is created to test the GLM algo with Gaussian family.  In this case, the relationship
  between the response Y and the predictor vector X is assumed to be Y = W^T * X + E where E is
  unknown Gaussian noise.  We generate random data set using the exact formula.  Since we know
  what the W is and there are theoretical solutions to calculating W, p-values, we know the solution
   to W/p-values/MSE for test and training data set for each randomly generated
  data set.  Hence, we are able to evaluate the H2O GLM Model generated using the same random data
  sets.  When regularization and other parameters are enabled, theoretical solutions are no longer
  available.  However, we can still evaluate H2O GLM model performance by comparing the MSE from H2O model
  and to the theoretical limits since they all are using the same data sets.  As long as they do not
  deviate too much, we consider the H2O model performance satisfactory.  In particular, I have
  written 8 tests in the hope to exercise as many parameters settings of the GLM algo with Gaussian
  distribution as possible.  Tomas has requested 2 tests to be added to test his new feature of
  missing_values_handling for predictors with both categorical/real columns.  Here is a list of
  all tests:
  
  test1_glm_and_theory(): theoretical values for weights, p-values and MSE are calculated.
      H2O GLM model is built Gaussian family with the same random data set.  We compare
      the weights, p-values, MSEs generated from H2O with theory.
  test2_glm_lambda_search(): test lambda search with alpha set to 0.5 per Tomas's
      suggestion.  Make sure MSEs generated here is comparable in value to H2O
      GLM model with no regularization.
  test3_glm_grid_search_over_params(): test grid search with over
      various alpha values while lambda is set to be the best value obtained
      from test 2.  The best model performance hopefully will generate MSEs
      close to H2O with no regularization in test 1.
  test4_glm_remove_collinear_columns(): test parameter remove_collinear_columns=True
      with lambda set to best lambda from test 2, alpha set to best alpha from Gridsearch
      and solver set to the one which generate the smallest test MSEs.  The same data set
      is used here except that we randomly choose predictor columns to repeat and scale.
      Make sure MSEs generated here is comparable in value to H2O GLM with no
      regularization.
  test5_missing_values(): Test parameter missing_values_handling="MeanImputation" with
      only real value predictors.  The same data sets as before is used.  However, we
      go into the predictor matrix and randomly decide to change a value to be
      nan and create missing values.  Since no regularization is enabled in this case,
      we are able to calculate a theoretical weight/p-values/MSEs where we can
      compare our H2O models with.
  test6_enum_missing_values(): Test parameter missing_values_handling="MeanImputation" with
      mixed predictors (categorical/real value columns).  We first generate a data set that
      contains a random number of columns of categorical and real value columns.  Next, we
      encode the categorical columns.  Then, we generate the random data set using the formula
      Y = W^T * X+ E as before.  Next, we go into the predictor matrix (before encoding) and randomly
      decide to change a value to be nan and create missing values.  Since no regularization
      is enabled in this case, we are able to calculate a theoretical weight/p-values/MSEs
      where we can compare our H2O models with.
  test7_missing_enum_values_lambda_search(): Test parameter
      missing_values_handling="MeanImputation" with mixed predictors (categorical/real value columns).
      We first generate a data set that contains a random number of columns of categorical and real
      value columns.  Next, we encode the categorical columns using true one hot encoding.  Then,
      we generate the random data set using the formula Y = W^T * X+ E as before.  Next, we go into
      the predictor matrix (before encoding) and randomly  decide to change a value to be nan and
      create missing values.  Lambda-search will be enabled with alpha set to 0.5.  Since the
      encoding is different in this case than in test6, we will compute a theoretical weights/MSEs
      and compare the best H2O model MSEs with theoretical calculations and hope that they are close.
class_docstr_tok: ["This","class","is","created","to","test","the","GLM","algo","with","Gaussian","family",".","In","this","case",",","the","relationship","between","the","response","Y","and","the","predictor","vector","X","is","assumed","to","be","Y","=","W^T","*","X","+","E","where","E","is","unknown","Gaussian","noise",".","We","generate","random","data","set","using","the","exact","formula",".","Since","we","know","what","the","W","is","and","there","are","theoretical","solutions","to","calculating","W",",","p-values",",","we","know","the","solution","to","W\/p-values\/MSE","for","test","and","training","data","set","for","each","randomly","generated","data","set",".","Hence",",","we","are","able","to","evaluate","the","H2O","GLM","Model","generated","using","the","same","random","data","sets",".","When","regularization","and","other","parameters","are","enabled",",","theoretical","solutions","are","no","longer","available",".","However",",","we","can","still","evaluate","H2O","GLM","model","performance","by","comparing","the","MSE","from","H2O","model","and","to","the","theoretical","limits","since","they","all","are","using","the","same","data","sets",".","As","long","as","they","do","not","deviate","too","much",",","we","consider","the","H2O","model","performance","satisfactory",".","In","particular",",","I","have","written","8","tests","in","the","hope","to","exercise","as","many","parameters","settings","of","the","GLM","algo","with","Gaussian","distribution","as","possible",".","Tomas","has","requested","2","tests","to","be","added","to","test","his","new","feature","of","missing_values_handling","for","predictors","with","both","categorical\/real","columns",".","Here","is","a","list","of","all","tests",":","test1_glm_and_theory","(",")",":","theoretical","values","for","weights",",","p-values","and","MSE","are","calculated",".","H2O","GLM","model","is","built","Gaussian","family","with","the","same","random","data","set",".","We","compare","the","weights",",","p-values",",","MSEs","generated","from","H2O","with","theory",".","test2_glm_lambda_search","(",")",":","test","lambda","search","with","alpha","set","to","0.5","per","Tomas's","suggestion",".","Make","sure","MSEs","generated","here","is","comparable","in","value","to","H2O","GLM","model","with","no","regularization",".","test3_glm_grid_search_over_params","(",")",":","test","grid","search","with","over","various","alpha","values","while","lambda","is","set","to","be","the","best","value","obtained","from","test","2",".","The","best","model","performance","hopefully","will","generate","MSEs","close","to","H2O","with","no","regularization","in","test","1.","test4_glm_remove_collinear_columns","(",")",":","test","parameter","remove_collinear_columns=True","with","lambda","set","to","best","lambda","from","test","2",",","alpha","set","to","best","alpha","from","Gridsearch","and","solver","set","to","the","one","which","generate","the","smallest","test","MSEs",".","The","same","data","set","is","used","here","except","that","we","randomly","choose","predictor","columns","to","repeat","and","scale",".","Make","sure","MSEs","generated","here","is","comparable","in","value","to","H2O","GLM","with","no","regularization",".","test5_missing_values","(",")",":","Test","parameter","missing_values_handling=","''","MeanImputation","''","with","only","real","value","predictors",".","The","same","data","sets","as","before","is","used",".","However",",","we","go","into","the","predictor","matrix","and","randomly","decide","to","change","a","value","to","be","nan","and","create","missing","values",".","Since","no","regularization","is","enabled","in","this","case",",","we","are","able","to","calculate","a","theoretical","weight\/p-values\/MSEs","where","we","can","compare","our","H2O","models","with",".","test6_enum_missing_values","(",")",":","Test","parameter","missing_values_handling=","''","MeanImputation","''","with","mixed","predictors","(","categorical\/real","value","columns",")",".","We","first","generate","a","data","set","that","contains","a","random","number","of","columns","of","categorical","and","real","value","columns",".","Next",",","we","encode","the","categorical","columns",".","Then",",","we","generate","the","random","data","set","using","the","formula","Y","=","W^T","*","X+","E","as","before",".","Next",",","we","go","into","the","predictor","matrix","(","before","encoding",")","and","randomly","decide","to","change","a","value","to","be","nan","and","create","missing","values",".","Since","no","regularization","is","enabled","in","this","case",",","we","are","able","to","calculate","a","theoretical","weight\/p-values\/MSEs","where","we","can","compare","our","H2O","models","with",".","test7_missing_enum_values_lambda_search","(",")",":","Test","parameter","missing_values_handling=","''","MeanImputation","''","with","mixed","predictors","(","categorical\/real","value","columns",")",".","We","first","generate","a","data","set","that","contains","a","random","number","of","columns","of","categorical","and","real","value","columns",".","Next",",","we","encode","the","categorical","columns","using","true","one","hot","encoding",".","Then",",","we","generate","the","random","data","set","using","the","formula","Y","=","W^T","*","X+","E","as","before",".","Next",",","we","go","into","the","predictor","matrix","(","before","encoding",")","and","randomly","decide","to","change","a","value","to","be","nan","and","create","missing","values",".","Lambda-search","will","be","enabled","with","alpha","set","to","0.5",".","Since","the","encoding","is","different","in","this","case","than","in","test6",",","we","will","compute","a","theoretical","weights\/MSEs","and","compare","the","best","H2O","model","MSEs","with","theoretical","calculations","and","hope","that","they","are","close","."]
docstr: Test parameter missing_values_handling="MeanImputation" with
  only real value predictors.  The same data sets as before are used.  However, we
  go into the predictor matrix and randomly decide to change a value to be
  nan and create missing values.  Since no regularization is enabled in this case,
  we are able to calculate a theoretical weight/p-values/MSEs where we can
  compare our H2O models with.
docstr_tok: ["Test","parameter","missing_values_handling=","''","MeanImputation","''","with","only","real","value","predictors",".","The","same","data","sets","as","before","are","used",".","However",",","we","go","into","the","predictor","matrix","and","randomly","decide","to","change","a","value","to","be","nan","and","create","missing","values",".","Since","no","regularization","is","enabled","in","this","case",",","we","are","able","to","calculate","a","theoretical","weight\/p-values\/MSEs","where","we","can","compare","our","H2O","models","with","."]
code: def test5_missing_values(self):
      """
      Test parameter missing_values_handling="MeanImputation" with
      only real value predictors.  The same data sets as before are used.  However, we
      go into the predictor matrix and randomly decide to change a value to be
      nan and create missing values.  Since no regularization is enabled in this case,
      we are able to calculate a theoretical weight/p-values/MSEs where we can
      compare our H2O models with.
      """
      print(
          "*******************************************************************************************"
      )
      print(
          "Test5: test the GLM with imputation of missing values with column averages."
      )
  
      # get theoretical weights, p-values and mse
      try:
          (
              weight_theory,
              p_values_theory,
              mse_train_theory,
              mse_test_theory,
          ) = self.theoretical_glm(
              self.training_data_file_nans,
              self.test_data_file_nans,
              False,
              False,
          )
      except:
          print("Bad dataset, lin-alg package problem.")
          sys.exit(0)
  
      # import training set and test set
      training_data = h2o.import_file(
          pyunit_utils.locate(self.training_data_file_nans)
      )
      test_data = h2o.import_file(
          pyunit_utils.locate(self.test_data_file_nans)
      )
  
      # train H2O models with missing_values_handling="MeanImputation"
      model_h2o = H2OGeneralizedLinearEstimator(
          family=self.family,
          Lambda=0,
          compute_p_values=True,
          missing_values_handling="MeanImputation",
          standardize=False,
      )
      model_h2o.train(
          x=self.x_indices, y=self.y_index, training_frame=training_data
      )
  
      # calculate H2O model performance with test data set
      h2o_model_test_metrics = model_h2o.model_performance(
          test_data=test_data
      )
  
      num_test_failed = self.test_failed
      (
          _,
          _,
          _,
          _,
          _,
          _,
          self.test_failed,
      ) = pyunit_utils.extract_comparison_attributes_and_print(
          model_h2o,
          h2o_model_test_metrics,
          "\nTest5 Done!",
          True,
          True,
          True,
          weight_theory,
          p_values_theory,
          mse_train_theory,
          mse_test_theory,
          "Comparing intercept and weights ....",
          "H2O missing values intercept and weights: ",
          "Theoretical intercept and weights: ",
          "Intercept and weights are not equal!",
          "Intercept and weights are close enough!",
          "Comparing p-values ....",
          "H2O missing values p-values: ",
          "Theoretical p-values: ",
          "P-values are not equal!",
          "P-values are close enough!",
          "Comparing training MSEs ....",
          "H2O missing values training MSE: ",
          "Theoretical training MSE: ",
          "Training MSEs are not equal!",
          "Training MSEs are close enough!",
          "Comparing test MSEs ....",
          "H2O missing values test MSE: ",
          "Theoretical test MSE: ",
          "Test MSEs are not equal!",
          "Test MSEs are close enough!",
          self.test_failed,
          self.ignored_eps,
          self.allowed_diff,
          self.noise_var,
          False,
      )
  
      # print out test results and update test_failed_array status to reflect if this test has failed
      self.test_failed_array[
          self.test_num
      ] += pyunit_utils.show_test_results(
          "test5_missing_values", num_test_failed, self.test_failed
      )
      self.test_num += 1
  
imports: import sys
  import random
  import os
  import numpy
  import scipy
  import math
  from scipy import stats
  from builtins import range
  import time
  import h2o
  from tests import pyunit_utils
  from h2o.estimators.glm import H2OGeneralizedLinearEstimator
  from h2o.grid.grid_search import H2OGridSearch
label_desc: Use image node_id 8 for calling the TestGLMGaussian obj's underlying member method code with example usage: obj.test5_missing_values() without return types