准确度模块

surprise.accuracy 模块提供了计算一组预测的准确性指标的工具。

可用的准确度指标:

rmse

计算RMSE(均方根误差)。

mse

计算MSE(均方误差)。

mae

计算MAE(平均绝对误差)。

fcp

计算FCP(一致对的比例)。

surprise.accuracy.fcp(predictions, verbose=True)[source]

计算FCP(一致对的比例)。

如Koren和Sill在论文Collaborative Filtering on Ordinal User Feedback的第5.2节所述计算。

Parameters:
  • predictions (list of Prediction) – 一个预测列表,由 test() 方法返回。

  • verbose – 如果为True,将打印计算值。默认为True

Returns:

一致对的比例。

Raises:

ValueError – 当 predictions 为空时。

surprise.accuracy.mae(predictions, verbose=True)[source]

计算MAE(平均绝对误差)。

\[\text{MAE} = \frac{1}{|\hat{R}|} \sum_{\hat{r}_{ui} \in \hat{R}}|r_{ui} - \hat{r}_{ui}|\]
Parameters:
  • predictions (list of Prediction) – 一个预测列表,由 test() 方法返回。

  • verbose – 如果为True,将打印计算值。默认为True

Returns:

预测的平均绝对误差。

Raises:

ValueError – 当 predictions 为空时。

surprise.accuracy.mse(predictions, verbose=True)[source]

计算MSE(均方误差)。

\[\text{MSE} = \frac{1}{|\hat{R}|} \sum_{\hat{r}_{ui} \in \hat{R}}(r_{ui} - \hat{r}_{ui})^2.\]
Parameters:
  • predictions (list of Prediction) – 由 test() 方法返回的预测列表。

  • verbose – 如果为True,将打印计算值。默认为True

Returns:

预测的均方误差。

Raises:

ValueError – 当 predictions 为空时。

surprise.accuracy.rmse(predictions, verbose=True)[source]

计算RMSE(均方根误差)。

\[\text{RMSE} = \sqrt{\frac{1}{|\hat{R}|} \sum_{\hat{r}_{ui} \in \hat{R}}(r_{ui} - \hat{r}_{ui})^2}.\]
Parameters:
  • predictions (list of Prediction) – 一个预测列表,由 test() 方法返回。

  • verbose – 如果为True,将打印计算值。默认为True

Returns:

预测的均方根误差。

Raises:

ValueError – 当 predictions 为空时。