プリンキピア

第21章推薦システム

21.4.3. Reimplementing the Evaluator21.4.3 評価関数を実装し直す

Since the input and output have been changed, we need to reimplement the evaluation function, while we still use RMSE as the accuracy measure.
英語のヒント
入力と出力が変わったので、評価関数を実装し直す必要がある。精度の尺度には引き続きRMSEを使う。
def evaluator(network, inter_matrix, test_data, devices):
    scores = []
    for values in inter_matrix:
        feat = gluon.utils.split_and_load(values, devices, even_split=False)
        scores.extend([network(i).asnumpy() for i in feat])
    recons = np.array([item for sublist in scores for item in sublist])
    # Calculate the test RMSE
    rmse = np.sqrt(np.sum(np.square(test_data - np.sign(test_data) * recons))
                   / np.sum(np.sign(test_data)))
    return float(rmse)