Issue
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')
data.head(20)
data.isnull().sum()
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',
fontsize=16);
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.LSTM(60),
tf.keras.layers.Dense(30, activation="relu"),
tf.keras.layers.Dense(10, activation="relu"),
tf.keras.layers.Dense(1),
])
optimizer = tf.keras.optimizers.SGD(lr=1.0000e-04, momentum=0.9)
model.compile(loss=tf.keras.losses.Huber(),
optimizer=optimizer,
metrics=["mae"])
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.
Solution
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. Use
data = pd.read_csv('/content/daily-minimum-temperatures-in-me.csv')
data = data._convert(numeric=True)
data.head(20)
This will convert all data in your code to numeric, hopefully it will work.
Answered By - Garuda
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.