root_mean_squared_error#
- sklearn.metrics.root_mean_squared_error(y_true, y_pred, *, sample_weight=None, multioutput='uniform_average')[source]#
均方根误差回归损失。
在用户指南中阅读更多内容。
在 1.4 版本中新增。
- 参数:
- y_true形状为 (n_samples,) 或 (n_samples, n_outputs) 的类数组
真实(正确)目标值。
- y_pred形状为 (n_samples,) 或 (n_samples, n_outputs) 的类数组
估计的目标值。
- sample_weight形状为 (n_samples,) 的类数组, 默认值为 None
样本权重。
- multioutput{'raw_values', 'uniform_average'} 或 形状为 (n_outputs,) 的类数组, 默认值为 'uniform_average'
定义多个输出值的聚合方式。类数组值定义了用于平均误差的权重。
- ‘raw_values’
在多输出输入情况下返回完整的误差集。
- ‘uniform_average’
所有输出的误差以均匀权重平均。
- 返回:
- loss浮点数或浮点数 ndarray
一个非负浮点值(最佳值为 0.0),或一个浮点值数组,每个独立目标一个值。
示例
>>> from sklearn.metrics import root_mean_squared_error >>> y_true = [3, -0.5, 2, 7] >>> y_pred = [2.5, 0.0, 2, 8] >>> root_mean_squared_error(y_true, y_pred) 0.612... >>> y_true = [[0.5, 1],[-1, 1],[7, -6]] >>> y_pred = [[0, 2],[-1, 2],[8, -5]] >>> root_mean_squared_error(y_true, y_pred) 0.822...