## 1 Introduction
Events like the Great Financial Crisis and the COVID-19 pandemic demonstrate how interconnected markets amplify shocks, making risk management at both portfolio and systemic levels difficult. Persistent volatility spillovers exacerbate contagion across assets, underscoring the need for tools to comprehend market dynamics during turmoil, develop early warning systems during regime shifts, and detect the formation of price bubbles [13; 14]. Financial crashes and stock price collapses jeopardize the stability of the entire economic system. They reveal persistent patterns shaped by the type of shock and uncertainty involved. A typical response is flight-to-quality behavior, where investors shift from riskier assets to safer options, such as cash or money market instruments. Under extreme conditions, this behavior disrupts markets, triggering liquidity shortages, fire sales, and heightened volatility, which erodes overall market stability [15; 16]. Extreme events and shocks in stock markets result in substantial economic losses, reduced investor confidence, and household consumption, ultimately leading to economic depression. Consequently, despite the unpredictable nature of stock markets, there remains a pressing need for investors, regulators, and practitioners to develop methods and empirical models to anticipate and monitor disruptive events, regime changes, and the formation of price bubbles. A complementary approach to understanding bubbles emerges from the field of complex systems. This theory posits that bubbles and crashes are rooted in imitation and herding as the most visible manifestation of human behavior in our social systems. In particular, as a complex system comprising several heterogeneous agents with repetitive interactions in financial markets, this behavior tends to self-organize its internal structure, leading to surprising emergent properties that are out of equilibrium. Under such conditions, financial markets, prone to cooperative herding and imitation, exhibit repetitive nonlinear interactions that could destabilize the financial system. Therefore, in a market with multiple agents influenced by exogenous information and events, as well as endogenous interactions, self-organized and self-reinforcing extreme behaviors could emerge, generating market changes such as bubbles and crashes [17; 18; 19]. In line with the above, we propose a warning system for the early detection of stock market bubbles. Our approach combines unsupervised learning with Restricted Boltzmann Machines and supervised learning with Balanced Random Forest and Feedforward Neural Networks. Machine learning methods are emerging as practical models for analyzing extreme events, regime changes, and bubble formation in financial markets. Other works also focused on detecting or warning of financial crises. For instance, [20] developed a financial condition indicator using Artificial Neural Networks (ANNs) based on daily data. Their approach combined multiple ANN-based experts through a genetic algorithm, offering an integrated solution for financial crisis warnings. Although these authors use predictor features based on returns and volatilities, their proposal does not provide objective performance measures to compare with other detection alternatives. Our approach focuses on the early detection of financial bubbles--phases of instability that precede crises--rather than directly predicting financial crash events. This distinction is important: in contrast to conventional binary classification problems, the field lacks standardized definitions for financial bubbles and widely accepted evaluation benchmarks, making it challenging to assess models using uniform criteria. While studies forecasting discrete financial shocks (e.g., using logistic regression, decision trees, XGBoost) typically predict crash events at a defined future point, our model aims to detect the evolving structural features of bubbles through volatility-return patterns.