I want to code a simple machine learning on JupyterLab but got error as Title
I have collect the data as x are lamda, eps, c (the shape of data is 102010 rows × 3 columns) and y is sen (the shape of data is 102010 rows × 1 columns) which i want my machine learning model to predict. This is my simple model code.
import tensorflow as tf
from sklearn.model_selection import train_test_split
import pandas as pd
# Split the data into features (X) and target (y)
X_data = df_total_x_data.values.reshape(-1, 1) # Reshape if needed
y_data = df_sen_final.values
x_train, x_test, y_train, y_test = train_test_split(x_data, y_data, test_size=0.2, random_state=42)
model = tf.keras.Sequential([tf.keras.layers.Dense(1, input_shape=(1,))])
model.compile(optimizer='adam', loss='mean_squared_error')
model.fit(x_train, y_train, epochs=10, validation_data=(x_test, y_test))
how can i fix this error?
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[60], line 17
15 model = tf.keras.Sequential([tf.keras.layers.Dense(1, input_shape=(1,))])
16 model.compile(optimizer='adam', loss='mean_squared_error')
---> 17 model.fit(x_train, y_train, epochs=10, validation_data=(x_test, y_test))
File /usr/local/lib/python3.10/dist-packages/keras/src/utils/traceback_utils.py:122, in filter_traceback.<locals>.error_handler(*args, **kwargs)
119 filtered_tb = _process_traceback_frames(e.__traceback__)
120 # To get the full stack trace, call:
121 # `keras.config.disable_traceback_filtering()`
--> 122 raise e.with_traceback(filtered_tb) from None
123 finally:
124 del filtered_tb
File /usr/local/lib/python3.10/dist-packages/tensorflow/python/data/ops/dataset_ops.py:503, in DatasetV2.__iter__(self)
501 return iterator_ops.OwnedIterator(self)
502 else:
--> 503 raise RuntimeError("`tf.data.Dataset` only supports Python-style "
504 "iteration in eager mode or within tf.function.")
RuntimeError: `tf.data.Dataset` only supports Python-style iteration in eager mode or within tf.function.