第21章推薦システム
21.3.3. Evaluation Measures21.3.3 評価の尺度
We then implement the RMSE (root-mean-square error) measure, which is commonly used to measure the differences between rating scores predicted by the model and the actually observed ratings (ground truth) (Gunawardana and Shani, 2015). RMSE is defined as:
英語のヒント
次に、RMSE(二乗平均平方根誤差)の尺度を実装する。これは、モデルが予測した評価の点数と実際に観測された評価(正解)の違いを測るのによく使われる(Gunawardana and Shani, 2015)。RMSEは次のように定義される。
(21.3.4)
where is the set consisting of pairs of users and items that you want to evaluate on. is the size of this set. We can use the RMSE function provided by
mx.metric.英語のヒント
ここでは、評価したい利用者とアイテムの組からなる集合である。はこの集合の大きさである。
mx.metricが用意しているRMSEの関数を使える。def evaluator(net, test_iter, devices):
rmse = mx.metric.RMSE() # Get the RMSE
rmse_list = []
for idx, (users, items, ratings) in enumerate(test_iter):
u = gluon.utils.split_and_load(users, devices, even_split=False)
i = gluon.utils.split_and_load(items, devices, even_split=False)
r_ui = gluon.utils.split_and_load(ratings, devices, even_split=False)
r_hat = [net(u, i) for u, i in zip(u, i)]
rmse.update(labels=r_ui, preds=r_hat)
rmse_list.append(rmse.get()[1])
return float(np.mean(np.array(rmse_list)))