Artificial Intelligence Applications in Engineering (MUH-920), week 8 of 14: interactive lab

Threshold and cost lab: From scores to decisions

Prof. Dr. Utku Kose, Süleyman Demirel University

Part A trains a logistic regression by gradient descent with every term of the gradient shown, and Part B searches the best split of a tree with Gini impurity or entropy [1, 2]. Part C asks for metrics computed from confusion matrices of engineering scenarios. Part D builds a ROC curve, its area and the cost of each threshold from individual scores [3]. Part E generates classifier scores for failures and normal cases with adjustable separation and imbalance. A threshold slider updates the confusion matrix, precision, recall, F1 and the expected cost, and the ROC and precision-recall curves show the current operating point [3, 4]. Part F creates synthetic minority examples with SMOTE and computes class weights [5], and Part G computes Shapley values and permutation importance [6].

Part A: Logistic regression by gradient descent

Two classes of machines are generated from standardised torque and wear. Each press computes the score, the probability and the gradient contribution of every example, averages the gradient and updates the coefficients; the first three examples are shown in full. The straight boundary at p = 0.5 turns and moves as the log-loss falls [1].

Part B: Impurity and the best split

Twenty machines with their torque and a failure label are the default data. The table evaluates every threshold between neighbouring values with the Gini impurity or the entropy of both children and marks the largest decrease; the chart plots the decrease over the threshold [2, 7].

Part C: Metrics from confusion matrices

Part D: ROC curve, AUC and costs by hand

The ten scored cases of the worked example are the default. The table lowers the threshold case by case and lists the true and false positive rates, the precision and the cost of each threshold; the area under the ROC curve is computed with trapezoids and, as a check, by counting correctly ordered pairs [3, 4].

Part E: Choose a threshold

Score distributions
ROC curve
Precision-recall curve

Part F: SMOTE and class weights

A few failures among many normal runs are plotted over torque and tool wear. Each synthetic failure is placed on the segment between a failure and one of its nearest failure neighbours, with the random factor shown, and the class weights are recomputed as the data grow [5].

Part G: Shapley values and permutation importance

The predictions for all eight subsets of three features define the game of the worked example, and every value can be changed. The Shapley value of each feature is computed from its four weighted marginal contributions, and the check confirms that the values add up to the change from the baseline. The second panel computes permutation importance from shuffled scores [6].

Shapley values of three features

Permutation importance

References

[1] Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning: Data Mining, Inference, and Prediction (2nd ed.). Springer. https://doi.org/10.1007/978-0-387-84858-7

[2] Breiman, L., Friedman, J. H., Olshen, R. A., & Stone, C. J. (1984). Classification and Regression Trees. Wadsworth.

[3] Fawcett, T. (2006). An introduction to ROC analysis. Pattern Recognition Letters, 27(8), 861-874. https://doi.org/10.1016/j.patrec.2005.10.010

[4] Saito, T., & Rehmsmeier, M. (2015). The precision-recall plot is more informative than the ROC plot when evaluating binary classifiers on imbalanced datasets. PLOS ONE, 10(3), e0118432. https://doi.org/10.1371/journal.pone.0118432

[5] Chawla, N. V., Bowyer, K. W., Hall, L. O., & Kegelmeyer, W. P. (2002). SMOTE: Synthetic minority over-sampling technique. Journal of Artificial Intelligence Research, 16, 321-357. https://doi.org/10.1613/jair.953

[6] Lundberg, S. M., & Lee, S.-I. (2017). A unified approach to interpreting model predictions. In Advances in Neural Information Processing Systems 30 (pp. 4765-4774). https://arxiv.org/abs/1705.07874

[7] Quinlan, J. R. (1986). Induction of decision trees. Machine Learning, 1(1), 81-106. https://doi.org/10.1007/BF00116251