import%20marimo%0A%0A__generated_with%20%3D%20%220.24.0%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20import%20plotly.graph_objects%20as%20go%0A%20%20%20%20from%20plotly.subplots%20import%20make_subplots%0A%20%20%20%20from%20scipy.spatial.distance%20import%20mahalanobis%0A%20%20%20%20from%20scipy.stats%20import%20chi2%2C%20multivariate_normal%0A%20%20%20%20from%20sklearn.covariance%20import%20EmpiricalCovariance%2C%20MinCovDet%0A%20%20%20%20from%20sklearn.metrics%20import%20balanced_accuracy_score%0A%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20EmpiricalCovariance%2C%0A%20%20%20%20%20%20%20%20MinCovDet%2C%0A%20%20%20%20%20%20%20%20balanced_accuracy_score%2C%0A%20%20%20%20%20%20%20%20chi2%2C%0A%20%20%20%20%20%20%20%20go%2C%0A%20%20%20%20%20%20%20%20mahalanobis%2C%0A%20%20%20%20%20%20%20%20make_subplots%2C%0A%20%20%20%20%20%20%20%20mo%2C%0A%20%20%20%20%20%20%20%20np%2C%0A%20%20%20%20%20%20%20%20pd%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%5B%E2%86%90%2033%20Huber%20Loss%5D(33_huber_loss.py)%20%7C%20%5BIndex%5D(..%2Findex.html)%20%7C%20%5B35%20Gini%20Impurity%20vs%20Entropy%20%E2%86%92%5D(35_gini_impurity_vs_entropy.py)%0A%0A%20%20%20%20%23%20Mahalanobis%20Distance%2C%20Covariance%20Metric%20Tensors%2C%20and%20Robust%20Outlier%20Detection%0A%0A%20%20%20%20%23%23%20%5Ba%5D%20Why%20do%20you%20need%20to%20know%20these%20concepts%3F%0A%0A%20%20%20%20In%20multivariable%20data%20science%2C%20machine%20learning%2C%20and%20anomaly%20detection%2C%20Euclidean%20distance%20often%20fails%20when%20features%20have%20disparate%20scales%20or%20non-zero%20correlations.%0A%0A%20%20%20%20%23%23%23%23%20The%20Pitfalls%20of%20Isotropic%20Distance%0A%20%20%20%20Standard%20Euclidean%20distance%20implicitly%20assumes%20that%20every%20coordinate%20axis%20possesses%20equal%20variance%20and%20that%20all%20pairs%20of%20features%20are%20mutually%20independent%20(an%20identity%20covariance%20matrix).%20In%20real-world%20data%2C%20coordinates%20are%20correlated%20and%20stretched%20along%20dominant%20principal%20directions.%20Two%20points%20located%20at%20identical%20Euclidean%20distances%20from%20the%20dataset%20centroid%20can%20have%20radically%20disparate%20likelihoods.%20A%20point%20shifted%20along%20the%20minor%20axis%20of%20variation%20represents%20a%20severe%2C%20statistically%20improbable%20deviation%2C%20whereas%20the%20same%20shift%20along%20the%20major%20axis%20represents%20routine%20random%20fluctuation.%0A%0A%20%20%20%20%23%23%23%23%20The%20Metric%20Tensor%20and%20Statistical%20Distance%0A%20%20%20%20Mahalanobis%20distance%20resolves%20this%20flaw%20by%20measuring%20statistical%20distance%20scaled%20by%20the%20covariance%20structure.%20It%20transforms%20coordinates%20into%20a%20standardized%20space%20where%20distances%20correspond%20directly%20to%20standard%20deviations%20from%20the%20centroid%20along%20any%20arbitrary%20direction.%0A%0A%20%20%20%20%23%23%23%23%20The%20Masking%20and%20Swamping%20Effects%0A%20%20%20%20Calculating%20Mahalanobis%20distance%20requires%20an%20estimate%20of%20the%20mean%20vector%20and%20covariance%20matrix.%20When%20a%20dataset%20contains%20severe%20outliers%2C%20conventional%20sample%20estimators%20suffer%20from%20catastrophic%20breakdown.%20Standard%20sample%20mean%20and%20covariance%20have%20a%20breakdown%20point%20of%200%25.%20Even%20a%20small%20fraction%20of%20contaminated%20observations%20can%20artificially%20inflate%20the%20sample%20covariance%2C%20stretching%20the%20estimated%20ellipsoids%20toward%20the%20outliers.%20This%20phenomenon%2C%20known%20as%20the%20masking%20effect%2C%20causes%20genuine%20anomalies%20to%20receive%20deceptively%20small%20Mahalanobis%20distances.%0A%0A%20%20%20%20To%20overcome%20this%20vulnerability%2C%20robust%20statistics%20employs%20high-breakdown%20estimators%20such%20as%20the%20Minimum%20Covariance%20Determinant%20(FastMCD).%20FastMCD%20isolates%20the%20uncontaminated%20core%20of%20the%20observations%2C%20yielding%20an%20uncorrupted%20metric%20tensor%20that%20reliably%20flags%20multivariate%20anomalies.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20%5Bb%5D%20Mathematical%20Foundations%20and%20Geometric%20Mechanics%0A%0A%20%20%20%20%23%23%23%201.%20Definition%20of%20Mahalanobis%20Distance%0A%0A%20%20%20%20Let%20%24x%20%5Cin%20%5Cmathbb%7BR%7D%5Ep%24%20be%20an%20observation%20vector%2C%20%24%5Cmu%20%5Cin%20%5Cmathbb%7BR%7D%5Ep%24%20the%20population%20centroid%2C%20and%20%24%5CSigma%20%5Cin%20%5Cmathbb%7BR%7D%5E%7Bp%20%5Ctimes%20p%7D%24%20a%20symmetric%20positive-definite%20covariance%20matrix.%20The%20Mahalanobis%20distance%20%24d_M(x%2C%20%5Cmu%3B%20%5CSigma)%24%20is%20defined%20as%3A%0A%0A%20%20%20%20%24%24d_M(x%2C%20%5Cmu%3B%20%5CSigma)%20%3D%20%5Csqrt%7B(x%20-%20%5Cmu)%5E%5Ctop%20%5CSigma%5E%7B-1%7D%20(x%20-%20%5Cmu)%7D%24%24%0A%0A%20%20%20%20When%20%24%5CSigma%20%3D%20%5Csigma%5E2%20I_p%24%2C%20the%20metric%20simplifies%20to%20standardized%20Euclidean%20distance%3A%0A%0A%20%20%20%20%24%24d_M(x%2C%20%5Cmu%3B%20%5Csigma%5E2%20I_p)%20%3D%20%5Cfrac%7B1%7D%7B%5Csigma%7D%20%5Csqrt%7B(x%20-%20%5Cmu)%5E%5Ctop%20(x%20-%20%5Cmu)%7D%20%3D%20%5Cfrac%7B%5C%7Cx%20-%20%5Cmu%5C%7C_2%7D%7B%5Csigma%7D%24%24%0A%0A%20%20%20%20%23%23%23%202.%20The%20Metric%20Tensor%20and%20Level%20Sets%0A%0A%20%20%20%20In%20Riemannian%20geometry%20and%20linear%20algebra%2C%20the%20inverse%20covariance%20matrix%20%24M%20%3D%20%5CSigma%5E%7B-1%7D%24%20acts%20as%20a%20Riemannian%20metric%20tensor%20on%20%24%5Cmathbb%7BR%7D%5Ep%24.%20The%20inner%20product%20induced%20by%20%24%5CSigma%5E%7B-1%7D%24%20is%3A%0A%0A%20%20%20%20%24%24%5Clangle%20u%2C%20v%20%5Crangle_%7B%5CSigma%5E%7B-1%7D%7D%20%3D%20u%5E%5Ctop%20%5CSigma%5E%7B-1%7D%20v%24%24%0A%0A%20%20%20%20The%20level%20sets%20of%20constant%20squared%20Mahalanobis%20distance%20%24d_M%5E2(x%2C%20%5Cmu)%20%3D%20c%5E2%24%20define%20%24(p-1)%24-dimensional%20ellipsoids%20centered%20at%20%24%5Cmu%24%3A%0A%0A%20%20%20%20%24%24%5Cmathcal%7BE%7D_c%20%3D%20%5Cleft%5C%7B%20x%20%5Cin%20%5Cmathbb%7BR%7D%5Ep%20%3A%20(x%20-%20%5Cmu)%5E%5Ctop%20%5CSigma%5E%7B-1%7D%20(x%20-%20%5Cmu)%20%3D%20c%5E2%20%5Cright%5C%7D%24%24%0A%0A%20%20%20%20Via%20the%20spectral%20decomposition%20%24%5CSigma%20%3D%20Q%20%5CLambda%20Q%5E%5Ctop%24%2C%20where%20%24Q%20%3D%20%5Bq_1%2C%20%5Cdots%2C%20q_p%5D%24%20is%20the%20orthogonal%20matrix%20of%20eigenvectors%20and%20%24%5CLambda%20%3D%20%5Ctext%7Bdiag%7D(%5Clambda_1%2C%20%5Cdots%2C%20%5Clambda_p)%24%20contains%20positive%20eigenvalues%3A%0A%0A%20%20%20%20%24%24%5CSigma%5E%7B-1%7D%20%3D%20Q%20%5CLambda%5E%7B-1%7D%20Q%5E%5Ctop%20%3D%20%5Csum_%7Bj%3D1%7D%5Ep%20%5Cfrac%7B1%7D%7B%5Clambda_j%7D%20q_j%20q_j%5E%5Ctop%24%24%0A%0A%20%20%20%20The%20principal%20semi-axes%20of%20the%20ellipsoid%20%24%5Cmathcal%7BE%7D_c%24%20align%20exactly%20with%20the%20eigenvectors%20%24q_j%24%2C%20with%20semi-axis%20lengths%20proportional%20to%20%24c%20%5Csqrt%7B%5Clambda_j%7D%24.%0A%0A%20%20%20%20%23%23%23%203.%20Equivalence%20to%20Whitening%20(Sphering)%0A%0A%20%20%20%20Mahalanobis%20distance%20can%20be%20computed%20as%20standard%20Euclidean%20distance%20following%20a%20linear%20whitening%20transformation.%20Define%20the%20whitening%20matrix%20%24W%20%3D%20%5CLambda%5E%7B-1%2F2%7D%20Q%5E%5Ctop%20%3D%20%5CSigma%5E%7B-1%2F2%7D%24.%20Let%3A%0A%0A%20%20%20%20%24%24z%20%3D%20W%20(x%20-%20%5Cmu)%20%3D%20%5CLambda%5E%7B-1%2F2%7D%20Q%5E%5Ctop%20(x%20-%20%5Cmu)%24%24%0A%0A%20%20%20%20The%20transformed%20random%20vector%20%24z%24%20has%20zero%20mean%20and%20an%20identity%20covariance%20matrix%3A%0A%0A%20%20%20%20%24%24%5Coperatorname%7BCov%7D(z)%20%3D%20W%20%5CSigma%20W%5E%5Ctop%20%3D%20(%5CSigma%5E%7B-1%2F2%7D)%20%5CSigma%20(%5CSigma%5E%7B-1%2F2%7D)%20%3D%20I_p%24%24%0A%0A%20%20%20%20Computing%20the%20Euclidean%20norm%20of%20%24z%24%20yields%3A%0A%0A%20%20%20%20%24%24%5C%7Cz%5C%7C_2%20%3D%20%5Csqrt%7Bz%5E%5Ctop%20z%7D%20%3D%20%5Csqrt%7B(x%20-%20%5Cmu)%5E%5Ctop%20W%5E%5Ctop%20W%20(x%20-%20%5Cmu)%7D%20%3D%20%5Csqrt%7B(x%20-%20%5Cmu)%5E%5Ctop%20%5CSigma%5E%7B-1%7D%20(x%20-%20%5Cmu)%7D%20%3D%20d_M(x%2C%20%5Cmu)%24%24%0A%0A%20%20%20%20Thus%2C%20Mahalanobis%20distance%20is%20the%20Euclidean%20distance%20measured%20after%20rotating%20into%20principal%20axes%20and%20scaling%20each%20axis%20to%20unit%20variance.%0A%0A%20%20%20%20%23%23%23%204.%20Chi-Square%20Distribution%20of%20Squared%20Distance%0A%0A%20%20%20%20If%20the%20random%20vector%20%24X%24%20follows%20a%20multivariate%20normal%20distribution%20%24X%20%5Csim%20%5Cmathcal%7BN%7D_p(%5Cmu%2C%20%5CSigma)%24%2C%20the%20whitened%20vector%20%24Z%20%3D%20%5CSigma%5E%7B-1%2F2%7D(X%20-%20%5Cmu)%24%20follows%20standard%20multivariate%20normal%20distribution%20%24Z%20%5Csim%20%5Cmathcal%7BN%7D_p(0%2C%20I_p)%24.%20The%20squared%20Mahalanobis%20distance%20represents%20the%20sum%20of%20%24p%24%20independent%20standard%20squared%20normals%3A%0A%0A%20%20%20%20%24%24d_M%5E2(X%2C%20%5Cmu)%20%3D%20%5Csum_%7Bj%3D1%7D%5Ep%20Z_j%5E2%20%5Csim%20%5Cchi%5E2_p%24%24%0A%0A%20%20%20%20This%20distribution%20provides%20an%20exact%20statistical%20hypothesis%20test%20for%20anomaly%20detection.%20For%20a%20significance%20level%20%24%5Calpha%20%5Cin%20(0%2C%201)%24%2C%20the%20critical%20decision%20boundary%20is%20the%20%24(1%20-%20%5Calpha)%24-quantile%20of%20the%20chi-square%20distribution%20with%20%24p%24%20degrees%20of%20freedom%3A%0A%0A%20%20%20%20%24%24%5Ctext%7BDecision%20Rule%3A%20Outlier%20if%20%7D%20d_M%5E2(x%2C%20%5Cmu)%20%3E%20%5Cchi%5E2_p(1%20-%20%5Calpha)%24%24%0A%0A%20%20%20%20%23%23%23%205.%20Minimum%20Covariance%20Determinant%20(FastMCD)%0A%0A%20%20%20%20Standard%20sample%20mean%20%24%5Cbar%7Bx%7D%20%3D%20%5Cfrac%7B1%7D%7Bn%7D%20%5Csum_%7Bi%3D1%7D%5En%20x_i%24%20and%20sample%20covariance%20%24S%20%3D%20%5Cfrac%7B1%7D%7Bn-1%7D%20%5Csum_%7Bi%3D1%7D%5En%20(x_i%20-%20%5Cbar%7Bx%7D)(x_i%20-%20%5Cbar%7Bx%7D)%5E%5Ctop%24%20are%20vulnerable%20to%20leverage%20points%20and%20contamination.%0A%0A%20%20%20%20The%20Minimum%20Covariance%20Determinant%20(MCD)%20estimator%2C%20pioneered%20by%20Rousseeuw%2C%20achieves%20a%2050%25%20breakdown%20point.%20For%20a%20sample%20of%20size%20%24n%24%2C%20MCD%20seeks%20an%20optimal%20subset%20%24H%20%5Csubset%20%5C%7B1%2C%20%5Cdots%2C%20n%5C%7D%24%20of%20size%20%24h%24%20(typically%20%24h%20%5Capprox%20%5Cfrac%7Bn%20%2B%20p%20%2B%201%7D%7B2%7D%24)%20that%20minimizes%20the%20generalized%20variance%3A%0A%0A%20%20%20%20%24%24%5Chat%7BH%7D%20%3D%20%5Carg%5Cmin_%7BH%20%5Csubset%20%5C%7B1%2C%20%5Cdots%2C%20n%5C%7D%2C%20%7CH%7C%3Dh%7D%20%5Cdet%5Cleft(%20%5Cfrac%7B1%7D%7Bh-1%7D%20%5Csum_%7Bi%20%5Cin%20H%7D%20(x_i%20-%20%5Cbar%7Bx%7D_H)(x_i%20-%20%5Cbar%7Bx%7D_H)%5E%5Ctop%20%5Cright)%24%24%0A%0A%20%20%20%20The%20FastMCD%20algorithm%20iteratively%20alternates%20between%20computing%20covariance%20on%20subset%20%24H_k%24%20and%20updating%20%24H_%7Bk%2B1%7D%24%20to%20the%20%24h%24%20observations%20with%20the%20smallest%20Mahalanobis%20distances%20under%20the%20current%20covariance.%20This%20C-step%20(concentration%20step)%20guarantees%20monotonic%20decrease%20of%20the%20determinant%20until%20convergence.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20%23%20Fix%20random%20seed%20for%20reproducible%20synthetic%20experiments%0A%20%20%20%20np.random.seed(42)%0A%0A%20%20%20%20%23%20Ground%20truth%20parameters%20for%202D%20Gaussian%0A%20%20%20%20true_mean%20%3D%20np.array(%5B2.0%2C%202.0%5D)%0A%20%20%20%20true_cov%20%3D%20np.array(%5B%5B2.5%2C%201.8%5D%2C%20%5B1.8%2C%202.0%5D%5D)%0A%0A%20%20%20%20%23%20Generate%20uncontaminated%20Gaussian%20core%0A%20%20%20%20n_clean%20%3D%20450%0A%20%20%20%20clean_points%20%3D%20np.random.multivariate_normal(true_mean%2C%20true_cov%2C%20size%3Dn_clean)%0A%0A%20%20%20%20%23%20Injected%20anomalies%3A%20extreme%20orthogonal%20leverage%20points%20and%20cluster%20anomalies%0A%20%20%20%20outlier_specs%20%3D%20%5B%0A%20%20%20%20%20%20%20%20(-2.5%2C%205.0)%2C%0A%20%20%20%20%20%20%20%20(-3.0%2C%204.0)%2C%0A%20%20%20%20%20%20%20%20(-1.5%2C%204.5)%2C%0A%20%20%20%20%20%20%20%20(6.0%2C%20-1.0)%2C%0A%20%20%20%20%20%20%20%20(5.5%2C%20-2.0)%2C%0A%20%20%20%20%20%20%20%20(6.5%2C%20-0.5)%2C%0A%20%20%20%20%20%20%20%20(7.0%2C%207.5)%2C%0A%20%20%20%20%20%20%20%20(8.0%2C%207.0)%2C%0A%20%20%20%20%20%20%20%20(-3.5%2C%20-1.0)%2C%0A%20%20%20%20%20%20%20%20(-2.0%2C%20-2.5)%2C%0A%20%20%20%20%5D%0A%20%20%20%20anomaly_points%20%3D%20np.array(outlier_specs)%0A%20%20%20%20n_anomalies%20%3D%20len(anomaly_points)%0A%0A%20%20%20%20%23%20Combined%20dataset%0A%20%20%20%20all_features%20%3D%20np.vstack(%5Bclean_points%2C%20anomaly_points%5D)%0A%20%20%20%20ground_truth_labels%20%3D%20np.zeros(len(all_features)%2C%20dtype%3Dint)%0A%20%20%20%20ground_truth_labels%5Bn_clean%3A%5D%20%3D%201%0A%20%20%20%20return%20all_features%2C%20clean_points%2C%20ground_truth_labels%2C%20true_cov%2C%20true_mean%0A%0A%0A%40app.cell%0Adef%20_(EmpiricalCovariance%2C%20MinCovDet%2C%20all_features%2C%20chi2%2C%20clean_points%2C%20np)%3A%0A%20%20%20%20%23%201.%20Fit%20Standard%20Empirical%20Covariance%20(vulnerable%20to%20masking)%0A%20%20%20%20emp_cov_model%20%3D%20EmpiricalCovariance().fit(all_features)%0A%20%20%20%20emp_mean%20%3D%20emp_cov_model.location_%0A%20%20%20%20emp_cov%20%3D%20emp_cov_model.covariance_%0A%20%20%20%20emp_d2%20%3D%20emp_cov_model.mahalanobis(all_features)%0A%0A%20%20%20%20%23%202.%20Fit%20Robust%20Minimum%20Covariance%20Determinant%20(FastMCD)%0A%20%20%20%20mcd_model%20%3D%20MinCovDet(random_state%3D42).fit(all_features)%0A%20%20%20%20mcd_mean%20%3D%20mcd_model.location_%0A%20%20%20%20mcd_cov%20%3D%20mcd_model.covariance_%0A%20%20%20%20mcd_d2%20%3D%20mcd_model.mahalanobis(all_features)%0A%0A%20%20%20%20%23%20Chi-square%20critical%20threshold%20for%20p%20%3D%202%20dimensions%20at%20alpha%20%3D%200.01%20(99%25%20confidence)%0A%20%20%20%20dof%20%3D%202%0A%20%20%20%20critical_d2%20%3D%20chi2.ppf(0.99%2C%20df%3Ddof)%0A%20%20%20%20critical_d%20%3D%20np.sqrt(critical_d2)%0A%0A%20%20%20%20%23%20Predictions%20based%20on%20chi-square%20threshold%0A%20%20%20%20emp_pred_anomalies%20%3D%20(emp_d2%20%3E%20critical_d2).astype(int)%0A%20%20%20%20mcd_pred_anomalies%20%3D%20(mcd_d2%20%3E%20critical_d2).astype(int)%0A%0A%20%20%20%20%23%20Ground%20truth%20clean%20distances%20for%20theoretical%20comparison%0A%20%20%20%20inv_mcd_cov%20%3D%20np.linalg.pinv(mcd_cov)%0A%20%20%20%20clean_diff%20%3D%20clean_points%20-%20mcd_mean%0A%20%20%20%20clean_d2%20%3D%20np.sum(clean_diff%20%40%20inv_mcd_cov%20*%20clean_diff%2C%20axis%3D1)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20clean_d2%2C%0A%20%20%20%20%20%20%20%20critical_d%2C%0A%20%20%20%20%20%20%20%20critical_d2%2C%0A%20%20%20%20%20%20%20%20emp_cov%2C%0A%20%20%20%20%20%20%20%20emp_d2%2C%0A%20%20%20%20%20%20%20%20emp_mean%2C%0A%20%20%20%20%20%20%20%20emp_pred_anomalies%2C%0A%20%20%20%20%20%20%20%20mcd_cov%2C%0A%20%20%20%20%20%20%20%20mcd_d2%2C%0A%20%20%20%20%20%20%20%20mcd_mean%2C%0A%20%20%20%20%20%20%20%20mcd_pred_anomalies%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20all_features%2C%0A%20%20%20%20chi2%2C%0A%20%20%20%20clean_d2%2C%0A%20%20%20%20critical_d%2C%0A%20%20%20%20emp_cov%2C%0A%20%20%20%20emp_mean%2C%0A%20%20%20%20go%2C%0A%20%20%20%20ground_truth_labels%2C%0A%20%20%20%20make_subplots%2C%0A%20%20%20%20mcd_cov%2C%0A%20%20%20%20mcd_d2%2C%0A%20%20%20%20mcd_mean%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20np%2C%0A%20%20%20%20true_cov%2C%0A%20%20%20%20true_mean%2C%0A)%3A%0A%20%20%20%20%23%20Helper%20to%20generate%202D%20ellipse%20coordinates%20for%20a%20given%20center%2C%20covariance%2C%20and%20distance%20level%0A%20%20%20%20def%20get_ellipse_coords(center%2C%20cov_mat%2C%20distance_radius%2C%20n_pts%3D120)%3A%0A%20%20%20%20%20%20%20%20angles%20%3D%20np.linspace(0%2C%202%20*%20np.pi%2C%20n_pts)%0A%20%20%20%20%20%20%20%20circle_pts%20%3D%20np.vstack(%5Bnp.cos(angles)%2C%20np.sin(angles)%5D)%0A%20%20%20%20%20%20%20%20%23%20Cholesky%20factor%20L%20such%20that%20L%20L%5ET%20%3D%20Cov%0A%20%20%20%20%20%20%20%20eigenvalues%2C%20eigenvectors%20%3D%20np.linalg.eigh(cov_mat)%0A%20%20%20%20%20%20%20%20%23%20Scale%20by%20sqrt(eigenvalue)%0A%20%20%20%20%20%20%20%20trans_matrix%20%3D%20eigenvectors%20%40%20np.diag(np.sqrt(np.maximum(eigenvalues%2C%201e-9)))%0A%20%20%20%20%20%20%20%20ellipse_pts%20%3D%20center%5B%3A%2C%20None%5D%20%2B%20distance_radius%20*%20(trans_matrix%20%40%20circle_pts)%0A%20%20%20%20%20%20%20%20return%20ellipse_pts%5B0%5D%2C%20ellipse_pts%5B1%5D%0A%0A%20%20%20%20fig%20%3D%20make_subplots(%0A%20%20%20%20%20%20%20%20rows%3D1%2C%0A%20%20%20%20%20%20%20%20cols%3D2%2C%0A%20%20%20%20%20%20%20%20subplot_titles%3D%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%3Cb%3ECovariance%20Ellipsoids%3A%20Standard%20vs%20Robust%20FastMCD%3C%2Fb%3E%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%3Cb%3EEmpirical%20d_M%5E2%20vs%20Theoretical%20Chi-Square%20(df%3D2)%20Distribution%3C%2Fb%3E%22%2C%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20horizontal_spacing%3D0.12%2C%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Left%20Subplot%3A%20Scatter%20of%20clean%20vs%20anomaly%20points%0A%20%20%20%20clean_idx%20%3D%20ground_truth_labels%20%3D%3D%200%0A%20%20%20%20anomaly_idx%20%3D%20ground_truth_labels%20%3D%3D%201%0A%0A%20%20%20%20fig.add_trace(%0A%20%20%20%20%20%20%20%20go.Scatter(%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dall_features%5Bclean_idx%2C%200%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3Dall_features%5Bclean_idx%2C%201%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mode%3D%22markers%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20marker%3Ddict(color%3D%22%232563EB%22%2C%20size%3D6%2C%20opacity%3D0.6)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3D%22Normal%20Points%20(Clean)%22%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20row%3D1%2C%0A%20%20%20%20%20%20%20%20col%3D1%2C%0A%20%20%20%20)%0A%0A%20%20%20%20fig.add_trace(%0A%20%20%20%20%20%20%20%20go.Scatter(%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dall_features%5Banomaly_idx%2C%200%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3Dall_features%5Banomaly_idx%2C%201%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mode%3D%22markers%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20marker%3Ddict(color%3D%22%23DC2626%22%2C%20size%3D10%2C%20symbol%3D%22x%22%2C%20line%3Ddict(width%3D2))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3D%22Ground%20Truth%20Anomalies%22%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20row%3D1%2C%0A%20%20%20%20%20%20%20%20col%3D1%2C%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Add%2099%25%20Chi-Square%20boundary%20ellipse%20for%20Ground%20Truth%0A%20%20%20%20gt_ex%2C%20gt_ey%20%3D%20get_ellipse_coords(true_mean%2C%20true_cov%2C%20critical_d)%0A%20%20%20%20fig.add_trace(%0A%20%20%20%20%20%20%20%20go.Scatter(%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dgt_ex%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3Dgt_ey%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mode%3D%22lines%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20line%3Ddict(color%3D%22%2310B981%22%2C%20width%3D2%2C%20dash%3D%22dash%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3D%22True%2099%25%20Ellipse%22%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20row%3D1%2C%0A%20%20%20%20%20%20%20%20col%3D1%2C%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Add%2099%25%20Chi-Square%20boundary%20ellipse%20for%20Standard%20Empirical%20Covariance%20(Masked)%0A%20%20%20%20emp_ex%2C%20emp_ey%20%3D%20get_ellipse_coords(emp_mean%2C%20emp_cov%2C%20critical_d)%0A%20%20%20%20fig.add_trace(%0A%20%20%20%20%20%20%20%20go.Scatter(%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Demp_ex%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3Demp_ey%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mode%3D%22lines%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20line%3Ddict(color%3D%22%23F59E0B%22%2C%20width%3D2.5%2C%20dash%3D%22dot%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3D%22Empirical%20Covariance%2099%25%20(Masked)%22%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20row%3D1%2C%0A%20%20%20%20%20%20%20%20col%3D1%2C%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Add%2099%25%20Chi-Square%20boundary%20ellipse%20for%20FastMCD%20(Robust)%0A%20%20%20%20mcd_ex%2C%20mcd_ey%20%3D%20get_ellipse_coords(mcd_mean%2C%20mcd_cov%2C%20critical_d)%0A%20%20%20%20fig.add_trace(%0A%20%20%20%20%20%20%20%20go.Scatter(%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dmcd_ex%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3Dmcd_ey%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mode%3D%22lines%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20line%3Ddict(color%3D%22%238B5CF6%22%2C%20width%3D2.5)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3D%22FastMCD%20Robust%2099%25%20Boundary%22%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20row%3D1%2C%0A%20%20%20%20%20%20%20%20col%3D1%2C%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Right%20Subplot%3A%20Empirical%20Chi-Square%20histogram%20vs%20Theoretical%20Chi-Square%20Density%0A%20%20%20%20x_theory%20%3D%20np.linspace(0.01%2C%2025.0%2C%20300)%0A%20%20%20%20pdf_theory%20%3D%20chi2.pdf(x_theory%2C%20df%3D2)%0A%0A%20%20%20%20fig.add_trace(%0A%20%20%20%20%20%20%20%20go.Histogram(%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dclean_d2%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20histnorm%3D%22probability%20density%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20nbinsx%3D35%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20marker_color%3D%22%2360A5FA%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20opacity%3D0.6%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3D%22Clean%20Samples%20d_M%5E2%22%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20row%3D1%2C%0A%20%20%20%20%20%20%20%20col%3D2%2C%0A%20%20%20%20)%0A%0A%20%20%20%20fig.add_trace(%0A%20%20%20%20%20%20%20%20go.Scatter(%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dx_theory%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3Dpdf_theory%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mode%3D%22lines%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20line%3Ddict(color%3D%22%231E3A8A%22%2C%20width%3D2.5)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3D%22Theoretical%20Chi-Square(df%3D2)%20PDF%22%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20row%3D1%2C%0A%20%20%20%20%20%20%20%20col%3D2%2C%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Mark%20the%2099%25%20critical%20threshold%20line%0A%20%20%20%20fig.add_vline(%0A%20%20%20%20%20%20%20%20x%3Dcritical_d**2%2C%0A%20%20%20%20%20%20%20%20line%3Ddict(color%3D%22%23DC2626%22%2C%20width%3D2%2C%20dash%3D%22dash%22)%2C%0A%20%20%20%20%20%20%20%20annotation_text%3Df%2299%25%20Cutoff%20(%7Bcritical_d**2%3A.2f%7D)%22%2C%0A%20%20%20%20%20%20%20%20annotation_position%3D%22top%20right%22%2C%0A%20%20%20%20%20%20%20%20row%3D1%2C%0A%20%20%20%20%20%20%20%20col%3D2%2C%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Plot%20anomaly%20distances%20on%20right%20subplot%20as%20scatter%20ticks%0A%20%20%20%20fig.add_trace(%0A%20%20%20%20%20%20%20%20go.Scatter(%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dmcd_d2%5Banomaly_idx%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3D%5B0.02%5D%20*%20len(all_features%5Banomaly_idx%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mode%3D%22markers%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20marker%3Ddict(color%3D%22%23DC2626%22%2C%20symbol%3D%22line-ns%22%2C%20size%3D16%2C%20line%3Ddict(width%3D2))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3D%22Anomalies%20d_M%5E2%20Scores%22%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20row%3D1%2C%0A%20%20%20%20%20%20%20%20col%3D2%2C%0A%20%20%20%20)%0A%0A%20%20%20%20fig.update_xaxes(title_text%3D%22Feature%201%20(X1)%22%2C%20row%3D1%2C%20col%3D1)%0A%20%20%20%20fig.update_yaxes(title_text%3D%22Feature%202%20(X2)%22%2C%20row%3D1%2C%20col%3D1)%0A%20%20%20%20fig.update_xaxes(title_text%3D%22Squared%20Mahalanobis%20Distance%20(d_M%5E2)%22%2C%20range%3D%5B0%2C%2030%5D%2C%20row%3D1%2C%20col%3D2)%0A%20%20%20%20fig.update_yaxes(title_text%3D%22Density%22%2C%20row%3D1%2C%20col%3D2)%0A%0A%20%20%20%20fig.update_layout(%0A%20%20%20%20%20%20%20%20template%3D%22plotly_white%22%2C%0A%20%20%20%20%20%20%20%20height%3D520%2C%0A%20%20%20%20%20%20%20%20margin%3Ddict(l%3D50%2C%20r%3D40%2C%20t%3D70%2C%20b%3D50)%2C%0A%20%20%20%20%20%20%20%20legend%3Ddict(orientation%3D%22h%22%2C%20yanchor%3D%22bottom%22%2C%20y%3D-0.28%2C%20xanchor%3D%22center%22%2C%20x%3D0.5)%2C%0A%20%20%20%20)%0A%0A%20%20%20%20viz%20%3D%20mo.ui.plotly(fig)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20all_features%2C%0A%20%20%20%20balanced_accuracy_score%2C%0A%20%20%20%20critical_d2%2C%0A%20%20%20%20emp_d2%2C%0A%20%20%20%20emp_pred_anomalies%2C%0A%20%20%20%20ground_truth_labels%2C%0A%20%20%20%20mahalanobis%2C%0A%20%20%20%20mcd_cov%2C%0A%20%20%20%20mcd_d2%2C%0A%20%20%20%20mcd_mean%2C%0A%20%20%20%20mcd_pred_anomalies%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20np%2C%0A%20%20%20%20pd%2C%0A)%3A%0A%20%20%20%20%23%20Example%201%3A%20Pure%20NumPy%20Vectorized%20Mahalanobis%20Distance%20vs%20Scipy%20Implementation%0A%20%20%20%20def%20vectorized_mahalanobis(x_mat%2C%20mean_vec%2C%20cov_mat)%3A%0A%20%20%20%20%20%20%20%20centered%20%3D%20x_mat%20-%20mean_vec%0A%20%20%20%20%20%20%20%20cov_inv%20%3D%20np.linalg.pinv(cov_mat)%0A%20%20%20%20%20%20%20%20sq_dist%20%3D%20np.sum(centered%20%40%20cov_inv%20*%20centered%2C%20axis%3D1)%0A%20%20%20%20%20%20%20%20return%20np.sqrt(np.maximum(sq_dist%2C%200.0))%0A%0A%20%20%20%20test_subset%20%3D%20all_features%5B%3A5%5D%0A%20%20%20%20numpy_distances%20%3D%20vectorized_mahalanobis(test_subset%2C%20mcd_mean%2C%20mcd_cov)%0A%20%20%20%20cov_inv_test%20%3D%20np.linalg.pinv(mcd_cov)%0A%20%20%20%20scipy_distances%20%3D%20np.array(%5Bmahalanobis(pt%2C%20mcd_mean%2C%20cov_inv_test)%20for%20pt%20in%20test_subset%5D)%0A%0A%20%20%20%20df_verification%20%3D%20pd.DataFrame(%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Point_Index%22%3A%20np.arange(5)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Feature_1%22%3A%20test_subset%5B%3A%2C%200%5D.round(4)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Feature_2%22%3A%20test_subset%5B%3A%2C%201%5D.round(4)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22NumPy_Vectorized_dM%22%3A%20numpy_distances.round(5)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22SciPy_Spatial_dM%22%3A%20scipy_distances.round(5)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Max_Absolute_Diff%22%3A%20np.abs(numpy_distances%20-%20scipy_distances).round(8)%2C%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Example%202%3A%20Outlier%20Detection%20Benchmark%3A%20Standard%20Empirical%20vs%20FastMCD%20Robust%20Estimator%0A%20%20%20%20emp_bal_acc%20%3D%20balanced_accuracy_score(ground_truth_labels%2C%20emp_pred_anomalies)%0A%20%20%20%20mcd_bal_acc%20%3D%20balanced_accuracy_score(ground_truth_labels%2C%20mcd_pred_anomalies)%0A%0A%20%20%20%20%23%20Detection%20statistics%0A%20%20%20%20n_true_anomalies%20%3D%20np.sum(ground_truth_labels%20%3D%3D%201)%0A%20%20%20%20emp_detected%20%3D%20np.sum((emp_pred_anomalies%20%3D%3D%201)%20%26%20(ground_truth_labels%20%3D%3D%201))%0A%20%20%20%20mcd_detected%20%3D%20np.sum((mcd_pred_anomalies%20%3D%3D%201)%20%26%20(ground_truth_labels%20%3D%3D%201))%0A%0A%20%20%20%20df_benchmark%20%3D%20pd.DataFrame(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Estimator%22%3A%20%22Empirical%20Covariance%20(Masked)%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Breakdown_Point%22%3A%20%220.0%25%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Chi2_Cutoff%22%3A%20f%22%7Bcritical_d2%3A.2f%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22True_Anomalies_Detected%22%3A%20f%22%7Bemp_detected%7D%20%2F%20%7Bn_true_anomalies%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Balanced_Accuracy%22%3A%20f%22%7Bemp_bal_acc%20*%20100%3A.2f%7D%25%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Robust_to_Masking%22%3A%20%22No%20(Covariance%20inflated%20by%20outliers)%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Estimator%22%3A%20%22FastMCD%20(Minimum%20Covariance%20Determinant)%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Breakdown_Point%22%3A%20%22~50.0%25%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Chi2_Cutoff%22%3A%20f%22%7Bcritical_d2%3A.2f%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22True_Anomalies_Detected%22%3A%20f%22%7Bmcd_detected%7D%20%2F%20%7Bn_true_anomalies%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Balanced_Accuracy%22%3A%20f%22%7Bmcd_bal_acc%20*%20100%3A.2f%7D%25%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Robust_to_Masking%22%3A%20%22Yes%20(Isolates%20uncontaminated%20sub-sample)%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Example%203%3A%20Comparison%20of%20Euclidean%20Distance%20vs%20Mahalanobis%20Distance%20for%20Key%20Boundary%20Samples%0A%20%20%20%20euclidean_dist%20%3D%20np.linalg.norm(all_features%20-%20mcd_mean%2C%20axis%3D1)%0A%20%20%20%20selected_indices%20%3D%20%5B0%2C%2015%2C%20100%2C%20-1%2C%20-5%2C%20-8%5D%0A%20%20%20%20selected_samples%20%3D%20all_features%5Bselected_indices%5D%0A%0A%20%20%20%20df_comparison%20%3D%20pd.DataFrame(%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Sample_Type%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Core%20Point%20A%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Core%20Point%20B%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Core%20Point%20C%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Orthogonal%20Outlier%201%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Orthogonal%20Outlier%202%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Cluster%20Outlier%203%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Feature_1%22%3A%20selected_samples%5B%3A%2C%200%5D.round(3)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Feature_2%22%3A%20selected_samples%5B%3A%2C%201%5D.round(3)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Euclidean_Dist%22%3A%20euclidean_dist%5Bselected_indices%5D.round(3)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Empirical_dM%22%3A%20np.sqrt(emp_d2%5Bselected_indices%5D).round(3)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22FastMCD_dM%22%3A%20np.sqrt(mcd_d2%5Bselected_indices%5D).round(3)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22True_Label%22%3A%20%5B%22Normal%22%2C%20%22Normal%22%2C%20%22Normal%22%2C%20%22Anomaly%22%2C%20%22Anomaly%22%2C%20%22Anomaly%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22FastMCD_Decision%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Anomaly%22%20if%20mcd_d2%5Bidx%5D%20%3E%20critical_d2%20else%20%22Normal%22%20for%20idx%20in%20selected_indices%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20)%0A%0A%20%20%20%20table_verif%20%3D%20mo.ui.table(df_verification)%0A%20%20%20%20table_bench%20%3D%20mo.ui.table(df_benchmark)%0A%20%20%20%20table_comp%20%3D%20mo.ui.table(df_comparison)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
844aa82f2d3b652b0c1ea46a68fd9f5b