Reputation: 7048
According to the Keras documentation:
fit(x=None, y=None, batch_size=None, epochs=1, ...)
The arguments for fit function are numpy arrays:
Arguments
x: Numpy array of training data (if the model has a single input), or list of Numpy arrays (if the model has multiple inputs). If input layers in the model are named, you can also pass a dictionary mapping input names to Numpy arrays. x can be None (default) if feeding from framework-native tensors (e.g. TensorFlow data tensors).
y: Numpy array of target (label) data (if the model has a single output), or list of Numpy arrays (if the model has multiple outputs). If output layers in the model are named, you can also pass a dictionary mapping output names to Numpy arrays. y can be None (default) if feeding from framework-native tensors (e.g. TensorFlow data tensors).
But I can pass x
and y
as dataframe and series.
print(type(x_train))
print(type(y_train))
Output:
<class 'pandas.core.frame.DataFrame'> <class 'pandas.core.series.Series'>
model.fit(x_train, y_train, ..)
This works fine. Why is that?
Upvotes: 1
Views: 1682
Reputation: 33460
Actually, this case has been covered in Keras source code by standardizing the input data in these lines:
# Case 2: Symbolic tensors or Numpy array-like.
x, y, sample_weights = self._standardize_user_data(
x, y,
sample_weight=sample_weight,
class_weight=class_weight,
batch_size=batch_size)
The _standardize_user_data
method calls standardize_input_data
function which converts DataFrame to Numpy array using using .values
attribute of DataFrame in this line:
data = data.values if data.__class__.__name__ == 'DataFrame' else data
As for Series
, this is done a bit more implicitly in standardize_single_array
function in this line:
elif x.ndim == 1:
x = np.expand_dims(x, 1)
Upvotes: 2