Repository: keras-team/autokeras

Issue:
IO API, multi-modal classification, predict method problem
### Bug Description
IO API, multi-modal classification, predict method problem


### Bug Reproduction

https://github.com/datamllab/automl-in-action-notebooks/blob/master/3.4.2-Functional-API-Multi-Input.ipynb


### Setup Details
Include the details about the versions of:
 - OS type and version:
 - Python: 
 - autokeras: 1.0.2
 - keras-tuner:
 - scikit-learn:
 - numpy:
 - pandas:
 - tensorflow: 2.1.0

### Additional context
<!---
If applicable, add any other context about the problem.
-->



Discussion:

Resolving patch:
diff --git a/autokeras/keras_layers.py b/autokeras/keras_layers.py
--- a/autokeras/keras_layers.py
+++ b/autokeras/keras_layers.py
@@ -49,7 +49,12 @@ def call(self, inputs):
         output_nodes = []
         for input_node, encoding_layer in zip(split_inputs, self.encoding_layers):
             if encoding_layer is None:
-                output_nodes.append(tf.strings.to_number(input_node, tf.float32))
+                number = tf.strings.to_number(input_node, tf.float32)
+                # Replace NaN with 0.
+                imputed = tf.where(tf.math.is_nan(number),
+                                   tf.zeros_like(number),
+                                   number)
+                output_nodes.append(imputed)
             else:
                 output_nodes.append(tf.cast(encoding_layer(input_node), tf.float32))
         return tf.keras.layers.Concatenate()(output_nodes)


Test patch:
diff --git a/tests/autokeras/keras_layers_test.py b/tests/autokeras/keras_layers_test.py
--- a/tests/autokeras/keras_layers_test.py
+++ b/tests/autokeras/keras_layers_test.py
@@ -5,8 +5,8 @@
 
 
 def test_feature_encoder_layer(tmp_path):
-    data = np.array([['a', 'ab', 2.1], ['b', 'bc', 1.0], ['a', 'bc', 3.5]])
-    data2 = np.array([['a', 'ab', 2.1], ['x', 'bc', 1.0], ['a', 'bc', 3.5]])
+    data = np.array([['a', 'ab', 2.1], ['b', 'bc', 1.0], ['a', 'bc', 'nan']])
+    data2 = np.array([['a', 'ab', 2.1], ['x', 'bc', 1.0], ['a', 'bc', 'nan']])
 
     input_node = tf.keras.Input(shape=(3,), dtype=tf.string)
     layer = layer_module.MultiColumnCategoricalEncoding([
@@ -35,4 +35,5 @@ def test_feature_encoder_layer(tmp_path):
     assert result[0][0] != result[1][0]
     assert result[0][1] != result[1][1]
     assert result[0][1] != result[2][1]
+    assert result[2][2] == 0
     assert output.dtype == np.dtype('float32')
diff --git a/tests/integration_tests/task_api_test.py b/tests/integration_tests/task_api_test.py
--- a/tests/integration_tests/task_api_test.py
+++ b/tests/integration_tests/task_api_test.py
@@ -47,14 +47,14 @@ def test_text_regressor(tmp_path):
 def test_structured_data_from_numpy_regressor(tmp_path):
     num_data = 500
     num_train = 400
-    data = utils.generate_data(num_data, shape=(10,))
+    data = utils.generate_structured_data(num_data)
     x_train, x_test = data[:num_train], data[num_train:]
     y = utils.generate_data(num_instances=num_data, shape=(1,))
     y_train, y_test = y[:num_train], y[num_train:]
     clf = ak.StructuredDataRegressor(directory=tmp_path,
                                      max_trials=2,
                                      seed=utils.SEED)
-    clf.fit(x_train, y_train, epochs=20, validation_data=(x_train, y_train))
+    clf.fit(x_train, y_train, epochs=11, validation_data=(x_train, y_train))
     clf.export_model()
     assert clf.predict(x_test).shape == (len(y_test), 1)