Search code examples
pythonjupyter-notebookneural-networksentiment-analysis

UnimplementedError in python for ANN implementation


I have try to implement ANN implementation on Python. But iam getting below error message. How can I solve this issue?

X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=0)


from sklearn.preprocessing import StandardScaler
sc = StandardScaler(with_mean=False)
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)


import tensorflow as tf

ann = tf.keras.models.Sequential()

#adding first hidden layer
ann.add(tf.keras.layers.Dense(units=6,activation="relu"))

#adding second hidden layer
ann.add(tf.keras.layers.Dense(units=6,activation="relu"))

ann.add(tf.keras.layers.Dense(units=1,activation="sigmoid"))
ann.compile(optimizer="adam",loss="binary_crossentropy",metrics=['accuracy'])
ann.fit(X_train,Y_train,batch_size=32,epochs = 100)

Iam getting this error message when I try to implement the ANN implementation on python.

WARNING:tensorflow:Keras is training/fitting/evaluating on array-like data. Keras may not be optimized for this format, so if your input data format is supported by TensorFlow I/O (https://github.com/tensorflow/io) we recommend using that to load a Dataset instead.
    Epoch 1/100
    ---------------------------------------------------------------------------
    UnimplementedError                        Traceback (most recent call last)
    Cell In[37], line 2
          1 #fitting ANN
    ----> 2 ann.fit(X_train,Y_train,batch_size=32,epochs = 100)

Solution

  • Input data for model.fit could be

    A Numpy array (or array-like), or a list of arrays (in case the model has multiple inputs).
    A TensorFlow tensor, or a list of tensors (in case the model has multiple inputs).
    A dict mapping input names to the corresponding array/tensors, if the model has named inputs.
    A tf.data dataset. Should return a tuple of either (inputs, targets) or (inputs, targets, sample_weights).
    A generator or keras.utils.Sequence returning (inputs, targets) or (inputs, targets, sample_weights).
    A tf.keras.utils.experimental.DatasetCreator, which wraps a callable that takes a single argument of type tf.distribute.InputContext, and returns a tf.data.Dataset. DatasetCreator should be used when users prefer to specify the per-replica batching and sharding logic for the Dataset. See tf.keras.utils.experimental.DatasetCreator doc for more information. A more detailed description of unpacking behavior for iterator types (Dataset, generator, Sequence) is given below. If these include sample_weights as a third component, note that sample weighting applies to the weighted_metrics argument but not the metrics argument in compile(). If using tf.distribute.experimental.ParameterServerStrategy, only DatasetCreator type is supported for x.
    

    source

    Looks like a problem with datatypes of x,y you are passing to ann.fit method.