1. Explain the variance
can be used for multi-target parameters
sklearn.metrics.explained_variance_score()
from sklearn.metrics import explained_variance_score
import numpy as np
y_true = [1, 2, 2, 5]
y_pred = np.array([1, 2, 3, 5])
print(explained_variance_score(y_true, y_pred))#一元数据集
0.9166666666666666
x_true = [[1, 2], [3, 4]]
x_pred = [[0, 2], [2, 3]]
print(explained_variance_score(x_true, x_pred, multioutput='raw_values'))#multioutput给定权值
[1. 0.75]
print(explained_variance_score(x_true, x_pred, multioutput=[0.3, 0.7]))#多元数据集,给定权重0.3和0.7
0.825
2. Average absolute error The
expression is piecewise linear, and the discussion interval is obtained by deriving
from sklearn.metrics import mean_absolute_error
import numpy as np
y_true = [1, 2, 2, 5]
y_pred = np.array([1, 2, 3, 5])
print(mean_absolute_error(y_true, y_pred))
0.25
x_true = [[1, 2], [3, 4]]
x_pred = [[0, 2], [2, 3]]
print(mean_absolute_error(x_true, x_pred, multioutput='raw_values'))
[1. 0.5]
print(mean_absolute_error(x_true, x_pred, multioutput=[0.3, 0.7]))
0.6499999999999999
3. Mean square error
from sklearn.metrics import mean_squared_error
import numpy as np
y_true = [1, 2, 2, 5]
y_pred = np.array([1, 2, 3, 5])
print(mean_squared_error(y_true, y_pred))
0.25
x_true = [[1, 2], [3, 4]]
x_pred = [[0, 2], [2, 3]]
print(mean_squared_error(x_true, x_pred, multioutput='raw_values'))
[1. 0.5]
print(mean_squared_error(x_true, x_pred, multioutput=[0.3, 0.7]))
0.6499999999999999
4. The median absolute error
can prevent the influence of extremely large error points, but does not support multioutput parameters
from sklearn.metrics import median_absolute_error
import numpy as np
y_true = [10, 2, 2, 5]
y_pred = np.array([1, 2, 3, 5])
print(median_absolute_error(y_true, y_pred))
0.5
#此例不支持多元参数,同时显示精度太小,如果两数据集数据接近,可能结果为零。
5. Determinant coefficient
from sklearn.metrics import r2_score
import numpy as np
y_true = [10, 2, 2, 5]
y_pred = np.array([1, 2, 3, 5])
print(r2_score(y_true, y_pred))
-0.9181286549707601
x_true = [[1, 2], [3, 4]]
x_pred = [[0, 2], [2, 3]]
print(r2_score(x_true, x_pred))
0.25
print(r2_score(x_true, x_pred, multioutput=[0.3, 0.7]))
0.35