Using KMeans Clustering to Evaluate and Alert for Deviations of Linac Photon Beam Parameters

Objective: To analyse the daily measured Dosimetric Quality Assurance (QA) parameters of linear accelerator (linac) using Unsupervised Machine Learning (ML) Algorithm thereby evaluating the current machine status and to highlight the probable cause of the ‘out-of-range’ measured parameter. Methods: Five parameters measured using PTW QuickCheckwebline device in a linac is subjected to KMeans clustering technique. The measured parameters comprise of Central Axis Dose (CAX), Beam Flatness, SymmetryLR, SymmetryGT and Beam Quality (BQF). Data from Varian with 55- and 107-day’s measurements and from Elekta with 75 days measurements from 2 beam matched linacs were used in this clustering technique. Results: This evaluation is used to review the current linac status and obtain 1) upper and lower limits of each parameter (CAX, Flatness, Symmetry, Beam Quality), 2) Frequency of the days when the linac parameters are closer to the target value and when they deviate from the target value. 3) The date when these parameters deviate from the estimated limits. 4) The probable reason for the deviation and 5) Finally if the machine requires maintenance. This methodology ensures that the machine is always closest to the target value, thus providing quality radiation treatment for the cancer patients. Moreover, the performance of the linac is studied meticulously and the need for maintenance is alerted before the linac beam shows marked deviation from the base value. Conclusion: KMeans clustering is a very simple and easy to use ML tool. With quick computation time and with lesser data it can arrive at the actual limits of the linac parameters and help to determine if the linac needs maintenance well in advance.


Introduction
Treating cancer patients with radiation is one of the prime modalities in Oncology department.External beam radiotherapy is achieved using C or O type Linear accelerators (Linac) that can produce photons and electrons.These linac should deliver the photon and electron beams daily within certain limits as recommended by Hanley J et al., (2009) [1] from the base line values measured during commissioning.This is to ensure that the measured base line values input into the Treatment Planning System (TPS), with which every patient is planned, is also delivered every day to get the desired result.Linac, deviating from the baseline values will not give optimal treatment.To prevent this, it is important to have the beam parameters as close as possible to the TPS commissioned model with some bounds.Minimising this boundary ensures quality and precision treatment to the patient.Therefore, the efficiency of every linac should be assessed individually and continue to maintain it.
As Binny et al., (2016) [2] correctly stated, every linac require verification to account for uncertainties in

RESEARCH ARTICLE
Using KMeans Clustering to Evaluate and Alert for Deviations of Linac Photon Beam Parameters linac's mechanical positions, focal spot position etc, in this study we can see how two beam matched units show varying parameters for the daily QA.D.Jiang et al., (2020) [3] could observe the drift in the absolute output for all energies but unable to conclude that the issue was with the monitor chamber until after 200 days of measurements and after intense analysis.A tool is hence required to not only measure the daily QA parameters but also to evaluate them and help to identify the issue if the measurement shows marked deviation.Many studies were made using Statistical Process Control like cumulative sum (CUSUM) chart, Exponentially Weighted Moving Average (EWMA) chart, Ishikawa diagrams and Shewhart charts [4][5][6].CUSUM charts and Shewhart charts respond very well for small shifts but are very slow in recognising large shifts.It also gives importance to the most recent data.Weighted Moving Average (WMA) charts work fine with normal data but fails with out-of-range data.Ishikawa diagrams does not show the development of a problem and the process needs to be repeated for every situation following the workflow each time.Li and Chan (2016) [7] have studied 5 years of daily QA measurements using data-driven Artificial Neural Network and have discussed that overfitting is the major issue requiring a very large number of data, but a large data affects the splitting up of data for training, testing and validation.Hence, a tool which can analyse short term data and a large set of data, alerting when there are out-of-range values with a reasoning will help to deliver precise treatment to patients as planned.
In this article the past records of the linac are analysed using clustering technique and the following are determined: 1) Upper and lower limits of each parameter (CAX, Flatness, Symmetry, Beam Quality), 2) Frequency of the days when the linac was closest to the target value and when it was deviating from the target 3) The date when these parameters are deviating from the estimated limits.4) The probable reason for the deviation and 5) Finally if the machine requires a maintenance.

Linac Daily QA
PTW Quickcheckwebline is a wireless device that records the radiation automatically and displays the parameters involved.There are 13 ionisation chambers in this device to capture the radiation and display the CAX, Flatness, Symmetry GT, SymmetryLR and BeamQuality for photons and electrons.

CAX
This gives the central axis dose measured at isocentre as absorbed dose to water.

Flatness
For a flattened photon beam the flatness defines how flat the profiles are and as per IEC 60976 it is the percentage dose ratio of the maximum to minimum value within the flattened region.

Symmetry
Symmetry is the percentage of maximum deviation of the left-side dose from the right-side dose within the flattened region.Symmetry from left to right of the source is termed as Symmetry LT and from Gun to Target is referred as Symmetry GT.Symmetry = (D (X) /D (-X) )*100 within flattened region (IEC 60976)

Beam quality
This remains fixed for every energy type representing the penetration and attenuation of the beam.The Half Value Layer (HVL), Nominal acceleration potential (NAP) and Tissue Phantom ratio of 20 cm depth to that of 10 cm depth (TPR 20/10 ) are some of the methods of evaluating the beam quality.
Nyaichyai et al., (2022) [8] verified the suitability of PTW Quickcheck device for routine quality assurance of the linac for output, energy, flatness and symmetry.Nicewonger et al., (2019) [9] found the PTW Quick check device to be a suitable tool for daily testing quantitatively and efficient solution qualitatively.D.Jiang et al., (2020) [3] observed that PTW Quick check device produced fitting linearity and reproducibility when compared with Farmer chamber.Dhoju et al., (2023) [10] concluded Beam monitorization following quality assurance protocol improves quality of the exposed beam during treatment procedure of patients.These works suggest that PTW QuickCheck webline is a reliable tool and the measurements can be effectively and efficiently utilised to automatically decide on the status of the linac Desired protocol (IEC, Varian, Elekta, AAPM TG45 etc.) to arrive at the linac parameters, can be chosen from the available list of various international protocols in the Quick Check Webline software.When the data for TPS is collected, the base data for the Quickcheck is also collected and normalised.Subsequent measurements are performed daily and compared with the base value.A standard value of 2% or 3% is given for the upper and lower limits from the target value as per the clinical protocol.If the linac's performance can be evaluated, then the limits can be set uniquely for every linac.

Datasets
Daily QA measurements from different make and model of linac was collected and subjected to this analysis successfully.In this paper Varian Truebeam with 55 & 107 datasets and two beam matched Elekta Synergy machines with 75 datasets are analysed.

KMeans Clustering technique
Machine Learning (ML) is a subset of Artificial Intelligence and has found immense usage in different areas of Radiotherapy like imaging, classification, and prediction [11][12][13].Unsupervised ML is a technique used for classification based on the data without any manual intervention [7].Clustering or grouping is one of the Unsupervised ML algorithms [14,15] and amongst the different methods KMeans clustering is chosen for this study using Python.[16][17][18].
KMeans involves grouping the data into clusters depending on how close they are to each other.Centroid in KMeans is the centre of a cluster such that it is the mean of all the points in that cluster.In KMeans, first a centroid is randomly set within the datapoints and then the Euclidean distance between this centroid and each of the available points is calculated.The mean distance from all the points is set as the centroid for that cluster.If a data shows very large distance, then it is considered as centroid of the next cluster.Through iterative process the centroids are determined, and the process stops when there is no change in the position of the centroid or when the number of given iterations is reached.The number of clusters need to be defined prior in KMeans.Centroids which are the centre of the clusters are formed until the defined number of clusters are achieved.Finally, we get the classification of all the data points into K clusters.The data points within a cluster should be closer to that centroid and away from the other centroids.

Reasons for applying KMeans for the daily dosimetry parameters
To ensure that the datasets are eligible for clustering, DOI:10.31557/APJCP.2024.25.1.305 KMeans Clustering for linac QA results for multiple trials.

Applying KMeans to CAX values of Varian Truebeam
On subjecting 55 days CAX values of a Varian Truebeam to KMeans clustering we get the group of data as in Figure 1.The CAX dose is along the horizontal axis and the clusters, usually 0, 1, 2 etc is along the vertical axis.
Figure 1 shows five different clusters with 0.56 as Silhouette score which justifies the clustering.The five clusters are named as 0,1,2,3,4.As the target value is fixed as 100, cluster 1 is the best group (~100 to ~100.25) of data and it holds 13 out of 55 data.The next range of good cluster is 4, (~100.25 to ~100.5) and this holds 20 out of 55 data.The next range is cluster 3 (~99.75 to ~100) but with only 5 out of 55.Most of the output values are greater than 100 (from the plot), Implying that this energy of this Truebeam machine has the tendency to deliver slightly higher output (>100) The lower limit can be set as 99.5 and the upper limit as 101.5.Clusters 4 & 1 can be marked as the ones closest to the target and for 33 days (20+13) the linac was within these clusters.Cluster 3 and Cluster 0 can be considered as "out-of-range" data.Though this customer had given 3% as the acceptable CAX deviation, this linac shows <1.0% deviation on most of the days and the target is 100.5.
To show that using a smaller dataset or larger dataset give the same prediction, the above clustering was repeated with 107 datasets.In Figure 2 107 datasets of the same linac is clustered.The cluster number (0 to 4) may differ, but the grouping of the data almost remains same excepting for some outliers (102.5).Here cluster 4 represents the best group (~99.75 to ~100.25) with 23 out of 107 in this group.Also, it is noted that the output is more than 100 in most of the days (0+4+3 clusters) 64 out of 107 when compared to the lesser than 100 values which is 20 out of 107.This set of data also shows 100.5 as the target value and 1% can be the acceptable deviation.
The above two sets of process with 55-and 107-days measurements show that with minimal set of data it is Hopkin Statistic that tests the spatial randomness of the data is applied individually to the CAX, Flatness, Symmetry and BeamQuality parameters.It assesses the clustering tendency of a data set by measuring the probability that a given data set is generated by a uniform data distribution.This factor was 0.8 for CAX, 0.9 for Flatness and Symmetry and 0.95 for Beam Quality, implying that the daily QA parameters are perfect candidates for clustering.Of the different clustering techniques, KMeans works well for non-linear dataset which is true with each of the daily QA parameters (CAX, Flatness, Sym GT, Sym LR & BQF).The target value for each of these parameters is known for a commissioned linac.We can expect the clusters to be distributed above and below the target value with limited bounds.The datasets are 1Dimensional with only the dose value (for CAX) and so standardisation can be ignored.Additionally, the measurements can be directly input into the code to form clusters without any cleansing or preparation.This is of advantage as usually any data to be subjected to ML needs to be cleansed, prepared, and normalised.Another fact is a minimum of 30 number of data can also be analysed.This helps to understand how the linac behaved in those 30 days.

Parameters used for the clustering
KMeans requires initialisation method, number of clusters along with other parameters to form the clusters.KMeans++ was chosen for the initialisation method and 5 was chosen for the number of clusters.Out of the different initialisation methods that chooses the centroids, KMeans++ is found to be effective as it selects only one centroid initially and then moves on in selecting the other centroids.By using the 'Elbow' method, the number of clusters which will yield better result is chosen.For the number of data used in this article 5 clusters gave optimal results with KMeans_Inertia <1 and so 5 was chosen.
To maintain the reproducibility the random state parameter of KMeans is kept fixed (42 in this case).As this value remains the same, we can get the same consistent Figure 1.CAX Clusters with 55 Days Data possible to estimate the limits within which the linac functions and frequency of best days.The clusters when transferred to the respective dates of measurements can predict the performance of the linac.Applying these clusters to the regular measurements helps to decide on which category they fall and alerts if the values are out-of-limits as defined by the training dataset.This is explained in detail in the next section.
Thus, with the existing data a model can be trained for KMeans cluster to analyse the data and know the customised limits of every individual linac parameter.Using this trained model the subsequent measurements can be predicted to be either "within tolerance" or "out of tolerance".Here the tolerance limit is more specific to the that linac.
In the same context, models can be trained for Flatness, Symmetry GT, Symmetry LR and Beam Quality.

Detailed study of Beam Matched Elekta Linacs Training dataset
Elekta Infinity and Elekta Synergy are two beam matched units whose data were used for this study.Randomly 75 days measurements (from 03FEB2020 to 15MAY2020) were used as training datasets and the clusters obtained were mapped to the date of measurements scoring only the group that is out-of-tolerance or the group with lesser number of candidates.This is then compared to the date when the re-normalisation was done on the device.Renormalisation is usually done when there is continuous gross deviation of the measured parameters from the set tolerance limit (indicating a change in the linac's behaviour) or when the linac is independently tuned.The datasets of this study had 2% limits from target value (100) for the CAX and Symmetry, 3% for the FLATNESS and 1% for the BeamQuality for which the target is 6.
The clusters of all the parameters are shown in Figure 3 for the Infinity.The outliers can be discarded if present, but this dataset does not have any outliers, so all the data are included for assessment.From the clusters the upper and the lower limits for each parameter can be arrived as discussed under "Applying KMeans to CAX values of Varian Truebeam".The frequency of clusters closest to the target and the ones away from the target can also observed from the legend of each parameter.
To corelate these with the dates of measurement, Table 1 is generated using MS Excel.The clusters generated from python are written into the spreadsheet and the actual measurements are given along with the clusters for the respective dates.Only those clusters that showed marked deviation from the target value or clusters with a smaller number of data are marked in the Table .For example, in Figure 3, CAX_Infinity plot has a legend of 3 & 4 with a smaller number of clusters and can be considered as out-of-limits.Hence the numbers 3 or 4 is used for corresponding date in Table 1.
Between 16 th and 20 th March, while the actual measurements do not show deviation (2%,3% and 1% respectively from the target value), the clustering indicates that on these days the values are away from the target value.Customer had re-normalised the values in the Quickcheck device on 21 st march after when, the clusters fall closest to the target value.
Similarly, clusters for Synergy can be seen in Figure 4 and the corresponding Table 2 gives the analysis with date of measurement.In Table 2 we can observe the similar behaviour for the other beam matched linac Synergy but at different date (before 1 st March).In this case there is a continuous indication that "SYMGT" is not within the expected clusters.While the actual measured value does not indicate this.Further for this linac the normalisation done on 1 st March after which the clusters fall closer to the target value.

Accuracy of the Clusters
The Silhouette factor for each parameter of the linac are listed in Table 3.This is a good indication that the formed clusters closely represent the linac.This factor  where separation is the distance between a data point and the nearest cluster that the data point is not a part of, and cohesion is the average distance between a data point and all other data points in the same cluster.
The Silhouette coefficient ranges from -1 to +1, where a high value indicates that the object is well matched to its own cluster and poorly matched to neighbouring clusters.If most objects have a high value, then the clustering configuration is appropriate.If many points have a low or negative value, then clustering configuration may have too many or too few clusters.

Model for errors
On occasions when the daily check device shows an error for a particular parameter, it is difficult to pinpoint to the apt reason.To train the model that can predict the probable errors, measurements were done with purposely made handpicked few errors and the data were used to create a model.In the case of CAX dose error, the following are some of the errors encountered: Lesser Monitor units (MU) delivered than the baseline, Greater MU delivered than the baseline, Linac output variation, Field size is different, Energy is different, Set up error.This model has 7 clusters, one or each error.A measurement stated as "out-of-tolerance" in the analysis model can be subjected to this "foreseeing model" which can pinpoint to the error that has caused the deviation in the data (Figure 5A, 5B).In case of beam quality, three erratic situations were reproduced as in Figure 6A, 6B.Similarly, the probable errors for Flatness and symmetry can also be generated.Also, one error can cause two or three parameters to deviate from baseline.For example, when a larger field size, in comparison to baseline data, is used both Flatness and BQF can fail.Thus, the errors generated can also be unique to every linac.This database can be built by adding the forced errors and actual errors which will help in the long run for that linac.The different type of errors classified as setup errors, method and measurement errors, machine errors and environmental errors [6] can be incorporated with clusters to get the model for errors.

Test dataset
The clusters obtained with the 75 training datasets gives a good picture of the existing linac condition.The same model can be applied to another set of data and check the linac behaviour.The log registry of the linac was analysed to check the dates when the linac was subjected to maintenance.As there were many entries of engineer visit, those visits related to the tuning of the beam like dose rate error, beam timer error, beam mu ch2, Preventive maintenance were taken as reference.Few days before and after these visits were analysed to check if the clustering can help to identify the issue.Following Table 4, Table 5 show these details where days marked in bold with bigger font represent the days of beam tuning along with the original measured value and cluster group.The measured values that do not fall within the cluster limits are marked as OLH for out-of-limit on the upper limit and OLL for out-of-limit on the lower limit.The cells highlighted in green indicate the days when the parameter was closest to the target value.In most cases we can observe that after the machine underwent a maintenance, the days following it showed results that are closer to the target value or do not fall out-of-range.

Results
The clusters of the trained datasets help to visualise the behaviour of the linac.The clusters arrived using the training datasets helps to set linac specific upper and lower limit for each parameter.The frequency of days when the linac was close to the target can be obtained that helps to understand the stability of the machine.Tabulation of the cluster groups with the date of measurement enables to assess the status of the beam and check if any tuning of the parameters or renormalisation of the Quick check device is required.If there is gross deviation the reason can be determined from the Model to reason errors.Comparing the dates of maintenance with the cluster group shows that after the beam maintenance the clusters fall closer to the target group as indicated by the green colour cells.Conversely, a maintenance visit can be planned if any one cluster is continuously out-of-limit or more than two clusters are not under tolerance.As the limits used here are very tight (about 0.5 %), the beam is always under check and prevents it from grossly deviating (say beyond 2%).This ensures that even very high dose treatments like SRS can be accomplished with excellent results.

Discussion
KMeans clustering can be considered as an expressive tool to evaluate the daily dosimetry parameters.Knowing the range within which the linac usually behaves helps to have a good control over the patient specific quality assurance.If the linac deviates continuously from the usual range, then immediate action can be taken before

Figure 3 .
Figure 3. Clusters of Measured Parameters of Infinity-Training Dataset

Figure 4 .
Figure 4. Clusters of Measured Parameters of Synergy-Training Dataset

Figure 5 .
Figure 5. A, Clusters based on CAX errors; B, List of CAX Errors

Table 1 .
Table Showing the Out-of-Tolerance Clusters and the Actual Measurements for Infinity Machine

Table 2 .
Table Showing the Out-of-Tolerance Cluster Group and the Actual Measurements for Synergy Machine

Table 3 .
Silhouette Factors Showing the Accuracy of the Clustering the beam characteristics fall well below the norms.By accumulating the errors, a model can also be easily trained with which the reason for the failure can be got instantaneously which in turn helps to keep a check on the linac.Above all the KMeans clustering is a very simple and easy to use tool with quick computation time and with lesser data.As more advanced treatment technique like Stereotactic radiosurgery, stereotactic radiotherapy etc involves very large dose, the important beam parameter's

Table 4 .
Comparison of Clusters and Maintenance Visit for Infinity Machine

Table 5 .
Comparison of Clusters and Maintenance visit for Synergy Machine