def test_unseen_categorical_feature():
  """
  Tests if the model can correctly handle unfamiliar values
  for categorical features. The model should not create new onehot 
  features for values in the test set and should instead treat
  these values as 'not any known value for that column'. 
  """
  headers = ["predictor 1", "predictor 2", "predictor3", "response"]
  response = "response"
  random_features = ['H', 5.5, 'I']
  train_set = [[random_features[i%3],'B',1,'C'] for i in range(1,50)] + [['A','A',-1,'D'] for i in range(1,50)]
  train_set_copy = copy.copy(train_set)
  new_features = ['J',9]
  test_set = [[new_features[i%2],'B',1,'C'] for i in range(1,49)] + [['A','A',-1,'D'] for i in range(1,50)]
  all_data = train_set + test_set

  factory = ModelFactory(all_data, headers, response, name_prefix="test")
  model = factory.build(train_set)
  print("factory builds ModelVisitor? -- ", isinstance(model, ModelVisitor))

  predictions = model.test(test_set)
  print("handling unseen categorical values correctly? -- ", all([pred[0] == pred[1] for pred in predictions]))
def test_unseen_categorical_feature ( ) : headers = [ "predictor 1" , "predictor 2" , "predictor3" , "response" ] response = "response" random_features = [ 'H' , 5.5 , 'I' ] train_set = [ [ random_features [ i % 3 ] , 'B' , 1 , 'C' ] for i in range ( 1 , 50 ) ] + [ [ 'A' , 'A' , - 1 , 'D' ] for i in range ( 1 , 50 ) ] train_set_copy = copy . copy ( train_set ) new_features = [ 'J' , 9 ] test_set = [ [ new_features [ i % 2 ] , 'B' , 1 , 'C' ] for i in range ( 1 , 49 ) ] + [ [ 'A' , 'A' , - 1 , 'D' ] for i in range ( 1 , 50 ) ] all_data = train_set + test_set factory = ModelFactory ( all_data , headers , response , name_prefix = "test" ) model = factory . build ( train_set ) print ( "factory builds ModelVisitor? -- " , isinstance ( model , ModelVisitor ) ) predictions = model . test ( test_set ) print ( "handling unseen categorical values correctly? -- " , all ( [ pred [ 0 ] == pred [ 1 ] for pred in predictions ] ) )
Tests if the model can correctly handle unfamiliar values
  for categorical features. The model should not create new onehot 
  features for values in the test set and should instead treat
  these values as 'not any known value for that column'.