TypeError: Exception encountered when calling layer "lstm_6" (type LSTM)


Can someone help me with this? I’m new in Machine Learning, and I was trying to do a time series Machine Learning but when I try to train the data with model.fit() this happen

TypeError: Exception encountered when calling layer "lstm_6" (type LSTM)
Value passed to parameter 'a' has DataType string not in list of allowed values: bfloat16, float16, float32, float64, int32, int64, complex64, complex128

I’m doing this in Colab and here is my code

import numpy as np
import pandas as pd
from keras.layers import Dense, LSTM
import matplotlib.pyplot as plt
import tensorflow as tf

data = pd.read_csv('/content/daily-minimum-temperatures-in-me.csv')


dates = data['Date'].values
temp  = data['Daily minimum temperatures'].values

plt.figure(figsize=(15,5), dpi=100)
plt.plot(dates, temp)
plt.title('Temperature average',

def windowed_dataset(series, window_size, batch_size, shuffle_buffer):
    series = tf.expand_dims(series, axis=-1)
    ds = tf.data.Dataset.from_tensor_slices(series)
    ds = ds.window(window_size + 1, shift=1, drop_remainder=True)
    ds = ds.flat_map(lambda w: w.batch(window_size + 1))
    ds = ds.shuffle(shuffle_buffer)
    ds = ds.map(lambda w: (w[:-1], w[-1:]))
    return ds.batch(batch_size).prefetch(1)

train_set = windowed_dataset(temp, window_size=60, batch_size=100, shuffle_buffer=1000)
model = tf.keras.models.Sequential([
  tf.keras.layers.LSTM(60, return_sequences=True),
  tf.keras.layers.Dense(30, activation="relu"),
  tf.keras.layers.Dense(10, activation="relu"),

optimizer = tf.keras.optimizers.SGD(lr=1.0000e-04, momentum=0.9)
history = model.fit(train_set,epochs=100)

If you need to know the dataset, here is the link

I appreciate the help to anyone answers. Thank you.


Whenever you are working try to use print statement very frequently.
Like print(type(temp)) gives your answer.

You are reading all your data in string format so your temp data is still in string format.

data = pd.read_csv('/content/daily-minimum-temperatures-in-me.csv')
data = data._convert(numeric=True)

This will convert all data in your code to numeric, hopefully it will work.

Answered By – Garuda

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published