sklearn.metrics计算MAPE
时间: 2023-07-04 16:27:36 浏览: 228
Agile.Metrics.for.Predictability.An.Introduction.098643633
在scikit-learn中,没有直接计算MAPE(Mean Absolute Percentage Error,平均绝对百分比误差)的函数,但可以通过以下代码计算MAPE:
```python
from sklearn.metrics import mean_absolute_error
import numpy as np
def mean_absolute_percentage_error(y_true, y_pred):
return np.mean(np.abs((y_true - y_pred) / y_true)) * 100
y_true = [3, -0.5, 2, 7]
y_pred = [2.5, 0.0, 2, 8]
mae = mean_absolute_error(y_true, y_pred)
mape = mean_absolute_percentage_error(np.array(y_true), np.array(y_pred))
print("MAE:", mae)
print("MAPE:", mape)
```
其中,MAE为均方误差,MAPE为平均绝对百分比误差。
阅读全文