This section is still under construction and will be completed in the near future. Please do not go beyond this point for now.
In this session, we will explore the dataset in Chapter 13 further.
When comparing our findings in Section 13.1.6.1 and Section 13.1.6.2 with the failure description in Section 13.1.7, we can see that we did a pretty good job in identifying failure reasons. However, it seems that the description of TWF in Section 13.1.7 is contradicting our observations.
Exercise 14.1 (Tool wear failure)
Identify where the description of TWF in Section 13.1.7 does not align with our findings.
Also, we could have done better for OSF.
Exercise 14.2 (Overstrain failure)
According to Section 13.1.7, the failure type overstrain failure (OSF) occurs when the machine is subjected to excessive torque when a worn-out tool is used. Also the product variant is associated to the failure rate: When the product of torque and tool wear exceeds 11.000 minNm for the L product variant (12.000 for M, 13.000 for H), the process fails due to overstrain.
- Are you able to verify this relationship by visualizations?
In Section 13.1.6.2, the decision tree of depth 3 was not able to model OSF, since a decision tree can only split along one feature at a time (horizontal or vertical cuts). A product such as torque times tool wear can only be approximated by a staircase of such cuts. This is where domain knowledge comes into play: a well-chosen feature can turn a hard problem into a trivial one.
- Visualize the limitation: train decision trees of depth 1, 2, 4, and 8 on
Torque [Nm] and Tool wear [min] only, with OSF as target. Plot the resulting decision boundaries using sklearn.inspection.DecisionBoundaryDisplay and compare them to the hyperbola \(\text{torque} \cdot \text{tool wear} = 11{,}000\).
- Engineer the feature
strain \(= \text{torque} \cdot \text{tool wear}\) and retrain the tree from Section 13.1.6.2 with strain as an additional feature. How does the structure of the tree change?
- The threshold depends on the product variant
Type. Also make this a feature.
- What is the smallest tree depth that separates
OSF (almost) perfectly, and which threshold does the tree learn?
After this exercise you should be able to:
- Explain why decision trees struggle with interactions and rotated decision boundaries.
- Use domain knowledge to engineer features that simplify a model.
Exercise 14.3 (Engineered features and model performance)
Repeat the comparison for HDF and PWF: train trees of increasing depth with and without the engineered features temp_diff and power. Report the F1 score instead of the accuracy and explain why accuracy is a misleading metric for this dataset.
After this exercise you should be able to:
- Choose an appropriate metric for heavily imbalanced classification tasks.
In Section 13.1.6, we used pair plots, boxplots, and decision trees to investigate the relationship between different features and the machine failure types. Another approach could be to use parallel coordinates plots from plotly, which we already used for the interactive plots in Chapter 13.
Exercise 14.4 (Parallel coordinates plots)
Use parallel coordinates plots to visualize the relationships between multiple features and the machine failure types:
- Display every available continuous variable along with one selected failure type.
- Also add
Type as a categorical variable to the plot.
- Make the failure type categorical.
- Color the lines according to the selected failure type.
- Allow for choosing the failure type interactively using a Dropdown widget (see Jupyter widgets) with the available failure types.
- The parallel coordinate plot allows for dragging columns (just click and drag the title of a column) and reordering them. It also allows for selecting and highlighting specific lines, making it easier to focus on particular data points. Use these two features to get insights into the relationships between different features and the selected failure type. Can you identify the patterns which we have exploited in our previous analyses?