1. Some materials are taken from machine learning course of Victor Kitov
1. (R)MSE ((Root) Mean Squared Error)
$$ L(\hat{y}, y) = \frac{1}{N}\sum\limits_{n=1}^N (y_n - \hat{y}_n)^2$$2. MAE (Mean Absolute Error)
$$ L(\hat{y}, y) = \frac{1}{N}\sum\limits_{n=1}^N |y_n - \hat{y}_n|$$MAE is robust to outliers
We can compare models with MAE and MSE but it is hard to tell if a model is good overall...
3. RSE (Relative Squared Error)
$$ L(\hat{y}, y) = \sqrt\frac{\sum\limits_{n=1}^N (y_n - \hat{y}_n)^2}{\sum\limits_{n=1}^N (y_n - \bar{y})^2}$$4. RAE (Relative Absolute Error)
$$ L(\hat{y}, y) = \frac{\sum\limits_{n=1}^N |y_n - \hat{y}_n|}{\sum\limits_{n=1}^N |y_n - \bar{y}|}$$5. MAPE (Mean Absolute Persentage Error)
$$ L(\hat{y}, y) = \frac{100}{N} \sum\limits_{n=1}^N\left|\frac{ y_n - \hat{y}_n}{y_n}\right|$$6. RMSLE (Root Mean Squared Logarithmic Error)
$$ L(\hat{y}, y) = \sqrt{\frac{1}{N}\sum\limits_{n=1}^N(\log(y_n + 1) - \log(\hat{y}_n + 1))^2}$$y = 10000
y_hat = np.linspace(0, 30000, 151)
# log error
error1 = np.sqrt((np.log(y+1) - np.log(y_hat + 1))**2)
# squared error
error2 = (y - y_hat)**2 /1000.
plt.plot(y_hat, error1, label='RMSLE'); plt.plot(y_hat, error2, label='MSE'); plt.xlabel('$\hat{y}$'); plt.ylabel('Error')
plt.title('true value y = %.1f' % y); plt.legend(); plt.ylim(0, 10)
(0, 10)
Confusion matrix $M=\{m_{ij}\}_{i,j=1}^{C}$ shows the number of $\omega_{i}$ class objects predicted as belonging to class $\omega_{j}$.
Diagonal elements correspond to correct classifications and off-diagonal elements - to incorrect classifications.
fig = interact(demo_fscore, beta=FloatSlider(min=0.1, max=5, step=0.2, value=1))
Decision rule based on discriminant functions:
Decision rule based on probabilities:
If $\mu \downarrow$ , the algorithm predicts $\omega_{1}$ more often and
Characterizes classification accuracy for different $\mu$.
Area under the ROC curve
Global quality characteristic for different $\mu$
AUC$\in[0,1]$
AUC property: it is equal to probability that for 2 random objects $x_{1}\in \text{"+"}$ and $x_{2}\in \text{"-"}$ it will hold that: $\widehat{p}(+|x_{1})>\widehat{p}(+|x_2)$
What about unbalanced case?
Let $TPR @ K\%$ be positive class rate in top $K \%$ segment of the dateset, sorted by score
$$ Model Lift @ K\% = \frac{TPR @ K\%}{r_{POS}} $$
"Averaging over samples"
For each class $c$ consider its confusion matrix
"Averaging over classes"
For each class $c$ consider its confusion matrix
"Averaging over classes but with their representation rate"
For each class $c$ consider its confusion matrix
C="Coronavirus"
F="Flue"
O="Ok"
y_true = [C,C,C,C,C,C, F,F,F,F,F,F,F,F,F,F, O,O,O,O,O,O,O,O,O]
y_pred = [C,C,C,C,O,F, C,C,C,C,C,C,O,O,F,F, C,C,C,O,O,O,O,O,O]
print(metrics.confusion_matrix(y_true, y_pred))
print(metrics.classification_report(y_true, y_pred, digits=3))
[[4 1 1] [6 2 2] [3 0 6]] precision recall f1-score support Coronavirus 0.308 0.667 0.421 6 Flue 0.667 0.200 0.308 10 Ok 0.667 0.667 0.667 9 accuracy 0.480 25 macro avg 0.547 0.511 0.465 25 weighted avg 0.581 0.480 0.464 25
# Each column represents a class,
# Each row - an object
y_true = np.array([[0,1,0],
[0,1,1],
[1,0,1],
[0,0,1],
[0,0,0]])
y_pred = np.array([[0,1,1],
[0,1,1],
[0,1,0],
[0,0,0],
[1,0,1]])
print(metrics.classification_report(y_true, y_pred, digits=3))
precision recall f1-score support 0 0.000 0.000 0.000 1 1 0.667 1.000 0.800 2 2 0.333 0.333 0.333 3 micro avg 0.429 0.500 0.462 6 macro avg 0.333 0.444 0.378 6 weighted avg 0.389 0.500 0.433 6 samples avg 0.300 0.400 0.333 6