ction and Motivation
Stellar flares are bursts of energy released by stars, believed to be caused by magnetic line reconnection [1,2]. It is characterized by a sudden spike in the star’s brightness, followed by a slow exponential decay [1,2]. But why care about detecting them? The reason is that they play an important role in our understanding of the universe. They help us gain insight into topics such as stellar magnetic fields, rotation, mass-loss rates, and atmospheric evolution of these stars’ orbiting planets [1,2]. However, as you probably expected, it’s not as easy as it sounds. Firstly, stellar flares don’t usually occur at consistent time intervals, which makes them hard to predict [1]. Secondly, low-energy flares often remain undetected as data-preprocessing steps tend to eliminate their signatures [1]. Thirdly, these datasets are unsupervised, meaning that the flares are not pre-labelled, making it quite challenging to evaluate flare detection models.
Recent studies have proposed a few different ways to approach these challenges. One study combined a hidden Markov model (HMM) with a celerite model to account for quasi-periodic oscillations (i.e., oscillations that follow a regular pattern, but don’t have a fixed period), improving the detection of low-energy flares compared to traditional methods [1]. Another study used Recurrent Neural Networks (RNNs) to detect flares [2]. However, both approaches are highly computationally intensive, taking even hours to analyze data for a single star [1,2]. Moreover, I felt that these studies did not explore the potential of building prediction models to capture future flares. Such a model would be very useful, as scientists would know when to expect these flares and perhaps allocate resources to map these flares more effectively for in-depth research into their characteristics. In summary, my goal for this project was to develop a method that detects stellar flares with high accuracy and build a predictive model capable of capturing future flares. Achieving this will provide astronomers with a powerful tool to deepen our understanding of stellar systems and our universe as a whole.
The Data
For this project, I analyzed time-series data for star TIC 0131799991, observed at a two-minute cadence by NASA’s Transiting Exoplanet Survey Satellite (TESS). While the original dataset has several features, I focused on just two for this study: time and PDCSAP (Pre-search Data Conditioning Simple Aperture Photometry) flux. PDCSAP flux represents the brightness of the star corrected for long-term trends. Flux measurements are missing during periods when the satellite was turned off, resulting in a total of 13,372 valid flux observations in this dataset.
The data can be downloaded directly from the TESS website by following this tutorial. Alternatively, a copy is available on my GitHub repository for this project.
Results
Figure 1A shows the flux measurements of this star over time. Flares are characterized by sharp increases in flux; however, it’s clear that they don’t occur at perfectly consistent intervals. My first goal was to impute the missing values in this time series. To understand the underlying patterns better, I plotted the autocorrelation function (ACF) for the first 500 lags using the initial portion of the data, shown in Figure 1B. We observe that the ACF oscillates with a consistent frequency, with the distance between consecutive peaks being about 150 time units. Using this periodicity, I applied STL decomposition to separate the time series into trend and seasonal components. I then extrapolated these components to estimate the flux values for the missing portion of the data, as shown in Figure 1C. This method is quite successful, as we see that the imputed values preserve the overall structure of the data.
To build the flare detection model, I created a few additional features. One such feature was the flux rolling mean. To determine the optimal window size, I tested out multiple lags and visualized their effects over the first 2000 time points. A lag of 10 was highly erratic and noisy, while a lag of 200 resulted in an overly smoothed series, failing to detect the flare event around time point 1500. Between lags of 50 and 100, 100 provided the best balance between smoothing the data yet capturing the flare signature at time 1500. Choosing such a window size is essential, as it ensures that the rolling mean recognizes the periodic structure of the data while remaining sensitive enough to capture flare peaks. Additional features constructed were flux rolling standard deviation, flux difference, and flux ratio.
For my flare detection model, I used DBSCAN (Density-Based Spatial Clustering of Applications with Noise). DBSCAN is an unsupervised clustering algorithm that identifies clusters based on data density and flags outliers as noise. For this project, I defined a point to be a flare if it was classified as noise by DBSCAN and exceeded the 95th percentile of flux values, since flare events are considered rare. I tested out different parameter values and chose the set that was sensitive enough to detect both strong and weak flares, while minimizing false positives (shown in Figure 2).

A while ago, I mentioned one of the primary issues with the data being its unsupervised nature. So how do we know whether DBSCAN actually detects flares? This is where simulations come in handy since the ground truth is known, and we can evaluate our model accordingly. Table 1 summarizes the evaluation metrics of the two simulations I performed. For the first one, I used a randomized baseline and injected Pareto-distributed flares in this series. The DBSCAN algorithm achieved a sensitivity of 0.9 with no false positives! This strong performance is likely due to the high signal-to-noise ratio in the data, as the baseline was sampled from a Normal distribution (mean = 1, sd = 0.02).
For a more realistic approach, my second simulation used a baseline, as well as flare intensities, aligned with the actual stellar data. In this case, the sensitivity remained at 0.9, with a slightly lower precision of 0.75. Upon closer examination, the three false positives detected occurred shortly after the actual flare events, just slightly beyond the defined flare duration. This however is not a cause of major concern since the primary flare events were successfully captured. This aspect can be improved by consulting domain experts regarding flare morphology and perhaps creating tolerance windows. In summary, the results suggest that the DBSCAN parameters are optimized and may generalize well to other stars with similar periodicity and flare patterns.

With a detection algorithm in place, my next step was to build a model that could predict flares. Since traditional ML algorithms assume independent observations, I included lagged features in the feature list to capture the time-dependent nature of the data. The binary flare variable (‘flare’ vs ‘not flare’) from DBSCAN served as the response. To respect the temporal structure of the data, I trained the model on the first 80% of the data and evaluated it on the last 20%. Table 2 summarizes the evaluation metrics on the test data from the XGBoost classification model. The model performs exceptionally well on non-flare points, while the sensitivity and precision are lower for flare points.

Upon visual inspection of the test set (Figure 3A), we see that the predicted flare points appear very close to the actual flare events. This suggests that the model can predict the correct events; however, since XGBoost evaluates predictions at an individual time point level, even small misalignments lead to reduced reported accuracy. This aspect can be improved by consultation with domain experts, perhaps by defining tolerance windows such that predictions within such a window are considered a correct detection. Overall, the XGBoost model shows good potential as a tool to forecast future flares, given that performance is assessed at an event level rather than exact pointwise matches.
To compare the above model with a more traditional time series-based model, I also trained an LSTM. Unlike XGBoost where a point is either labelled ‘flare’ or ‘non-flare’, the LSTM model predicts flux values directly. Thus, to define a flare point in this case, I set the threshold to be the minimum flux value among all points labeled as flares by DBSCAN in this star’s data. Figure 3B visually summarizes the LSTM test set results. On comparing the XGBoost and LSTM models, it is evident that XGBoost successfully captured several smaller flares that the LSTM model did not. This is a good sign, considering LSTM models are considered the go-to for time series predictions. One might argue that the smaller flares detected by XGBoost that LSTM missed are false positives; however, it is unlikely, since we observed during the simulation stage that all false positives detected occurred at the end of actual flare events. Thus, we can reasonably assume that the flares captured by DBSCAN in this case are valid detections. Another advantage of the XGBoost model is the training time. While the LSTM model took nearly thirty minutes to train, the XGBoost took less than ten seconds, further highlighting its potential as a computationally friendly predictive model.

Conclusion and Future Work
In summary, this project used DBSCAN to detect stellar flares in time-series flux data from star TIC 0131799991, recorded by TESS. The selected parameters provided a strong balance between detecting both strong and weak flares, while also minimizing false positives. Simulations demonstrated that these parameters are well-suited for this star and might generalize well to others with similar flare patterns and characteristics. Future work could look into testing whether these parameters generalize well to other stars, particularly ones with more irregular flare patterns or high noise. Additionally, we could also compare DBSCAN’s performance with existing methods on the same dataset to check relative model performance.
With a good flare detection model in place, I then built a flare prediction model employing XGBoost, with the flare labels generated by DBSCAN serving as the response. The XGBoost model did a good job, but tended to detect points close to (but not exactly) the actual flare events. Since XGBoost evaluates model performance on a pointwise level, these minor misalignments impacted the reported accuracy. We can reduce these false negatives via discussion with domain experts, who can perhaps help define tolerance windows that would account for such temporal proximity. Compared to LSTM, the XGBoost model was able to detect smaller flares and take far less training time, proving to be a computationally friendly tool as well.
This study combines unsupervised clustering with supervised learning to present a robust, generalizable and computationally efficient pipeline for stellar flare detection and prediction, one that can be adapted to different families of stars. It uses a novel approach for detection, and explores the possibility of prediction – a direction that has been largely unexplored in literature. Looking ahead, improving the model’s flare labeling accuracy and validating the approach across different stellar environments will be key for the wider adoption of this approach for flare detection and prediction. Ultimately, this work lays the foundation to support deeper insights into stellar behavior and our understanding of the universe.
References
[1] Esquivel, J. A., Shen, Y., Leos-Barajas, V., Eadie, G., Speagle, J. S., Craiu, R. V., Medina, A., and Davenport, J. R. A. (2025). Detecting Stellar Flares in Photometric Data Using Hidden Markov Models. The Astrophysical Journal, 979(2), 141. https://doi.org/10.3847/1538-4357/ad95f6
[2] Vida, K., Bódi, A., Szklenár, T., and Seli, B. (2021). Finding flares in Kepler and TESS data with recurrent deep neural networks. Astronomy & Astrophysics, 652(107). https://doi.org/10.1051/0004-6361/202141068
GitHub repo for this project can be found here.