## 1 Introduction
We contribute to the literature on machine learning in finance with a practical and user-oriented approach. Using daily data from the S&P500 index, we analyze returns and their volatility to identify periods of market instability and points near regime changes in market trends. We capture the complex relationships between stock returns and their volatility to train a Restricted Boltzmann Machine (RBM), which encodes this information in a high-dimensional space through its unsupervised learning process. In this way, these RBM representations provide essential inputs for a supervised learning process that evaluates the likelihood of entering a state of instability or nearing a turning point in the stock market. An advantage of this approach is that it is scalable to other financial indexes in different markets without the need to train the model from zero, allowing for the integration of data from bubbles and financial crises in a sole global market with indicators across various financial markets, making it a valuable model for general financial bubble warnings. Additionally, we trained our model to assess the proximity of a possible phase change and the market conditions that characterize the instability and high volatility triggered during a crisis period. In this way, we have two mutually exclusive event signals that assist the analyst in assessing the market condition. Our approach presents many advantages. Integrating unsupervised learning via RBMs into the model provides greater flexibility in analyzing market conditions. RBMs demonstrate remarkable versatility across various scientific fields, especially in finance, where they hold significant potential due to recent methodological advancements. Research on RBM learning phases evaluates the accuracy-efficiency tradeoff, enhancing their application in forecasting financial time-series data while balancing computational demands [21]. RBMsand several classifiers can predict short-term stock market trends [22]. They have also been utilized to extract discriminative low-dimensional features from raw data, with dimensions reaching up to 324, for stock price forecasting [23]. A new generalization of the RBM, the p-RBM, can retain the memory of p-states and predict stock market direction [24]. The above highlights RBMs' adaptability in addressing complex financial modeling challenges, from microstructure analysis to identifying systemic risk. Finally, our model's training period represents an advance in the empirical literature, as it considers a variety of financial shocks and crashes associated with multiple origins. We tested our model not only with one or two crises; instead, we trained it in a stepwise fashion over time using four well-known crashes in the U.S. market, starting from the Black Monday crash of 1987 to the COVID-19 outbreak in 2020 (see Appendix A for a summary of these and other episodes). Based on composite features from the S&P500 index returns and volatilities and using successive samples from financial crises and turmoil between 1987 and 2022, our results demonstrate that the model can effectively detect bubble formations and stock instability. Additionally, it identifies periods of abrupt stock market crashes. The model trains a hybrid neural network, Balanced Random Forest (BRF), to signal the formation of potential financial bubbles and proximity to critical tipping points. Furthermore, our method can recognize conditions indicative of potential overvaluation or price bubbles. The results show an AUC (area under the curve) rate exceeding 70% and false-positive rates of less than 20%. Notably, this work represents the first application of Gaussian-Gaussian Restricted Boltzmann Machines (GGRBMs) for financial market modeling, providing a flexible framework to analyze diverse market scenarios. Their use is novel for anomaly detection in capital markets and remains largely unexplored.