我目前使用最新版本的Keras 2.4.2和Tensorflow 2.2.0,使用Movielens-1M数据集(包含100万行)实现了一个简单的矩阵分解模型。然而,我注意到在训练过程中训练数据量会减少。
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
import keras
dataset = pd.read_csv('ratings.dat', skiprows=1,sep='::',names="userId,itemId,rating,timestamp".split(","))
dataset.userId = dataset.userId.astype('category').cat.codes.values
dataset.itemId = dataset.itemId.astype('category').cat.codes.values
train, test = train_test_split(dataset, test_size=0.2)
#model architecture can be found link below
x = [train.userId, train.itemId]
y = train.rating
print(x[0].shape, x[1].shape, y.shape)
history = model.fit(x, y, epochs=25,
verbose=1, validation_split=0.25)
点击 这里 查看模型结构。
如您所见,训练数据的数量应该是 600124(包括验证集)。但是,进度条显示的值要少得多(18754)。这是怎么回事?