Mean-variance optimization, introduced by Markowitz, is a foundational theory and methodology in finance and optimization, significantly influencing investment management practices. This study enhances mean-variance optimization by integrating machine learning-based anomaly detection, specifically using GANs (generative adversarial networks), to identify anomaly levels in the stock market. We demonstrate the utility of GANs in detecting market anomalies and incorporating this information into portfolio optimization using robust methods such as shrinkage estimators and the Gerber statistic. Empirical analysis confirms that portfolios optimized with anomaly scores outperform those using conventional portfolio optimization. This study highlights the potential of advanced data-driven techniques to improve risk management and portfolio performance.