class_docstr: This class is created to test the GLM algo with Multinomial family per request from Tomas as this
  is a new feature for the GLM alo.  In this case, the relationship
  between the response Y (K possible classes) and predictor vector X is assumed to be
  Prob(Y = c|X) = exp(Wc^T * X + E)/(sum k=0 to K-1 (ep(Wk^T *X+E)) where E is
  unknown Gaussian noise.  We generate random data sets using the exact formula.  To evaluate the H2O GLM Model,
  we run the sklearn logistic regression with the same data sets and compare the performance of the two.  If they
  are close enough within a certain tolerance, we declare the H2O model working.  When regularization and other
  parameters are enabled, we can evaluate H2O GLM model performance by comparing the logloss/accuracy
  from H2O model and to the H2O model generated without regularization.  As long as they do not deviate
  too much, we consider the H2O model performance satisfactory.
  
  In particular, I have written 7 tests in the hope to exercise
  as many parameters settings of the GLM algo with Multinomial distribution as possible.  Tomas
  has requested 2 tests to be added to test his new feature of missing_values_handling with
  predictors containing both categorical/real columns.  Here is a list of all tests:
  
  test1_glm_no_regularization(): sklearn logistic regression model is built.
      H2O GLM is built for Multinomial family with the same random data sets.  We observe
      the weights, confusion matrices from the two models.  We compare the logloss, prediction
      accuracy from the two models to determine if H2O GLM model shall pass the test.
  test2_glm_lambda_search(): test lambda search with alpha set to 0.5 per Tomas's
      suggestion.  Make sure loglss and prediction accuracy generated here is comparable in
      value to H2O GLM model with no regularization.
  test3_glm_grid_search_over_params(): test grid search over
      various alpha values while lambda is set to be the best value obtained
      from test 2.  Cross validation with k=5 and random assignment is enabled
      as well.  The best model performance hopefully will generate logloss and
      prediction accuracies close to H2O model with no regularization in test 1.
  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 replace a value with
      nan and create missing values.  Sklearn logistic regression model is built using the
      data set where we have imputed the missing values.  This Sklearn model will be used to
      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
      as before.  Next, we go into the predictor matrix and randomly
      decide to change a value to be nan and create missing values.  Again, we build a Sklearn
      logistic regression and compare our H2O model with it.
  test7_missing_enum_values_lambda_search(): Test parameter
      missing_values_handling="MeanImputation" with mixed predictors (categorical/real value columns).
      and setting lambda search to be True.  We use the same predictors from test6.  Next, we encode
      the categorical columns using true one hot encoding since Lambda-search will be enabled with
      alpha set to 0.5.  Since the encoding is different in this case from test6, we will build a brand
      new Sklearn logistic regression model and compare the best H2O model logloss/prediction accuracy with it.
class_docstr_tok: ["This","class","is","created","to","test","the","GLM","algo","with","Multinomial","family","per","request","from","Tomas","as","this","is","a","new","feature","for","the","GLM","alo",".","In","this","case",",","the","relationship","between","the","response","Y","(","K","possible","classes",")","and","predictor","vector","X","is","assumed","to","be","Prob","(","Y","=","c|X",")","=","exp","(","Wc^T","*","X","+","E",")","\/","(","sum","k=0","to","K-1","(","ep","(","Wk^T","*","X+E",")",")","where","E","is","unknown","Gaussian","noise",".","We","generate","random","data","sets","using","the","exact","formula",".","To","evaluate","the","H2O","GLM","Model",",","we","run","the","sklearn","logistic","regression","with","the","same","data","sets","and","compare","the","performance","of","the","two",".","If","they","are","close","enough","within","a","certain","tolerance",",","we","declare","the","H2O","model","working",".","When","regularization","and","other","parameters","are","enabled",",","we","can","evaluate","H2O","GLM","model","performance","by","comparing","the","logloss\/accuracy","from","H2O","model","and","to","the","H2O","model","generated","without","regularization",".","As","long","as","they","do","not","deviate","too","much",",","we","consider","the","H2O","model","performance","satisfactory",".","In","particular",",","I","have","written","7","tests","in","the","hope","to","exercise","as","many","parameters","settings","of","the","GLM","algo","with","Multinomial","distribution","as","possible",".","Tomas","has","requested","2","tests","to","be","added","to","test","his","new","feature","of","missing_values_handling","with","predictors","containing","both","categorical\/real","columns",".","Here","is","a","list","of","all","tests",":","test1_glm_no_regularization","(",")",":","sklearn","logistic","regression","model","is","built",".","H2O","GLM","is","built","for","Multinomial","family","with","the","same","random","data","sets",".","We","observe","the","weights",",","confusion","matrices","from","the","two","models",".","We","compare","the","logloss",",","prediction","accuracy","from","the","two","models","to","determine","if","H2O","GLM","model","shall","pass","the","test",".","test2_glm_lambda_search","(",")",":","test","lambda","search","with","alpha","set","to","0.5","per","Tomas's","suggestion",".","Make","sure","loglss","and","prediction","accuracy","generated","here","is","comparable","in","value","to","H2O","GLM","model","with","no","regularization",".","test3_glm_grid_search_over_params","(",")",":","test","grid","search","over","various","alpha","values","while","lambda","is","set","to","be","the","best","value","obtained","from","test","2",".","Cross","validation","with","k=5","and","random","assignment","is","enabled","as","well",".","The","best","model","performance","hopefully","will","generate","logloss","and","prediction","accuracies","close","to","H2O","model","with","no","regularization","in","test","1.","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","replace","a","value","with","nan","and","create","missing","values",".","Sklearn","logistic","regression","model","is","built","using","the","data","set","where","we","have","imputed","the","missing","values",".","This","Sklearn","model","will","be","used","to","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","as","before",".","Next",",","we","go","into","the","predictor","matrix","and","randomly","decide","to","change","a","value","to","be","nan","and","create","missing","values",".","Again",",","we","build","a","Sklearn","logistic","regression","and","compare","our","H2O","model","with","it",".","test7_missing_enum_values_lambda_search","(",")",":","Test","parameter","missing_values_handling=","''","MeanImputation","''","with","mixed","predictors","(","categorical\/real","value","columns",")",".","and","setting","lambda","search","to","be","True",".","We","use","the","same","predictors","from","test6",".","Next",",","we","encode","the","categorical","columns","using","true","one","hot","encoding","since","Lambda-search","will","be","enabled","with","alpha","set","to","0.5",".","Since","the","encoding","is","different","in","this","case","from","test6",",","we","will","build","a","brand","new","Sklearn","logistic","regression","model","and","compare","the","best","H2O","model","logloss\/prediction","accuracy","with","it","."]
code: def __init__(self):
      self.setup()
  
imports: import sys
  import os
  import random
  import math
  import numpy
  import time
  import h2o
  from builtins import range
  from tests import pyunit_utils
  from h2o.estimators.glm import H2OGeneralizedLinearEstimator
  from h2o.grid.grid_search import H2OGridSearch
  from scipy import stats
  from sklearn.linear_model import LogisticRegression
  from sklearn import metrics
label_desc: Use image node_id 1 to create a new TestGLMMultinomial object  with example: obj = TestGLMMultinomial()