# Classifying X-Ray Tube Malfunctions: AI-Powered CT Predictive Maintenance System
## 4 Data
### Data Cleaning  
#### 4.2.1 Identifying Anomalies and Handling Them  
It is important to assess the regularity of the data-gathering process to guarantee the correctness and dependability of the CT scanner data. Graphs plotting scan counts over time reveal two significant anomalies within our data. Firstly, while every single scan is labelled with both id and date, sometimes, these do not quite fit into the big picture with other data points. Usually, this means that while id is somehow continuous, the date would be shifted by several days compared to neighbouring data points if sorted by id. Anomalies found suggest that specific measurements were recorded at the wrong time, possibly due to incorrect computer date and time settings. These data were excluded, as it is impossible to accurately determine the corresponding number of scans and the time when the data were recorded. Additionally, there are observable gaps in the data, which point to times when the CT machine was not in use or when data collection failed. Most of the time, it would be the latter, as in the case of a CT scanner being used, it is being used daily, at worst, with a 2-day pause during the weekend. Hence, to mitigate this problem, it is important to select an interval where the data were routinely gathered in order to achieve relevant results. Our usage observations are also supported by the existing literature. For example, the 2015 report about CT equipment in NHS [22] states that the average CT scanned 32 patients daily and was in normal (not emergency on-call) operation for 48.8 h per week. Another NHS report from 2019 [23] also notes increasing 7-day usage of CTs. In Canada, as reported by CMII 2022-2023 survey [24], daily usage of an average CT was reported as 14.2 h, with 91.1 h being the weekly average, and 75.7% of surveyed sites reported 7 days/week operation. For working CT devices, data from the beginning of the graph were chosen. The selection was made this way as it is hard to estimate the reason for the gap, and a consistent interval ensures there was no hidden malfunction. This phenomenon can be seen in Figure 2. The initial long interval spanning from the start of the measuring until September 2019 is extracted and used as data for working CT.  
For malfunctioning devices, data closer to the failure point was used. It is logical that the transition from functional to slowly malfunctioning devices, or a device already malfunctioning and failing slowly, should happen in this window; hence, it is important to capture this moment. This approach's application is visible in Figure 3, where the top right interval is selected. As we opted to use classifiers, where consistent input dimensions are usually required, it was also necessary to agree on the input vector size. After some consideration, it was agreed to keep all the vectors bigger than 20,000 samples and truncate them to fit the smallest vector bigger than 20,000--20,190 data points. On average, this vector represents data from 69 days. We have selected this number of samples because we were able to retain most of the original dataset, given that we have already been operating with a low number of data samples, and excluding more could compromise the model's sensitivity. Additionally, 69 days should provide sufficient data to smooth out any noise that may occur due to variations in scanning procedures and protocols. We do not have any information about the day of the first reported malfunction or when the staff perceived the CT to degrade. We do not have information on when the X-ray tube perceived as functional has  
Figure 2: Number of scans over time for the working tube. (**a**) Before handling anomalies. (**b**) After handling anomalies. been replaced. Therefore, we cannot comment on the inflection point, where the functional X-ray tube starts to degrade towards the faulty one. Making this vector long could cause label noise, as it could include these transitional states.