boyu-ai/Hands-on-ML

第7章 7.2节train_rmse计算代码错误

Opened this issue · 1 comments

在纸质版图书第85页,这里计算训练集的损失函数为
train_rmse = np.sqrt(train_rmse / len(user_train))
我认为在每一批次中已经计算过当前批次的平均值,并进行累加
train_rmse += np.mean(errs ** 2)
所以这里应该修改为除以批次的数量
train_rmse = np.sqrt(train_rmse / batch_num)
微信图片_20240710112512
并且86页的运行结果图也应该修改,我的运行结果如下
output
微信图片_20240710112510

此外,我对训练集的RMSE进行重新计算

y_train_pred = model.pred(user_train, item_train)
train_rmse = np.sqrt(np.mean((y_train - y_train_pred) ** 2))
print(f'训练集RMSE:{train_rmse:.4f}')

运行结果为:
训练集RMSE:0.9608

所以我认为此处应当是出现了错误。

伯禹在线版图书中也发现了此问题:https://hml.boyuai.com/books/chapter7