<s> r"""<STR_LIT>""" <EOL> print ( __doc__ ) <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> from sklearn . covariance import EmpiricalCovariance , MinCovDet <EOL> n_samples = <NUM_LIT> <EOL> n_outliers = <NUM_LIT> <EOL> n_features = <NUM_LIT:2> <EOL> gen_cov = np . eye ( n_features ) <EOL> gen_cov [ <NUM_LIT:0> , <NUM_LIT:0> ] = <NUM_LIT> <EOL> X = np . dot ( np . random . randn ( n_samples , n_features ) , gen_cov ) <EOL> outliers_cov = np . eye ( n_features ) <EOL> outliers_cov [ np . arange ( <NUM_LIT:1> , n_features ) , np . arange ( <NUM_LIT:1> , n_features ) ] = <NUM_LIT> <EOL> X [ - n_outliers : ] = np . dot ( np . random . randn ( n_outliers , n_features ) , outliers_cov ) <EOL> robust_cov = MinCovDet ( ) . fit ( X ) <EOL> emp_cov = EmpiricalCovariance ( ) . fit ( X ) <EOL> fig = plt . figure ( ) <EOL> plt . subplots_adjust ( hspace = - <NUM_LIT> , wspace = <NUM_LIT> , top = <NUM_LIT> , bottom = <NUM_LIT> ) <EOL> subfig1 = plt . subplot ( <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> inlier_plot = subfig1 . scatter ( X [ : , <NUM_LIT:0> ] , X [ : , <NUM_LIT:1> ] , <EOL> color = '<STR_LIT>' , label = '<STR_LIT>' ) <EOL> outlier_plot = subfig1 . scatter ( X [ : , <NUM_LIT:0> ] [ - n_outliers : ] , X [ : , <NUM_LIT:1> ] [ - n_outliers : ] , <EOL> color = '<STR_LIT>' , label = '<STR_LIT>' ) <EOL> subfig1 . set_xlim ( subfig1 . get_xlim ( ) [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> subfig1 . set_title ( "<STR_LIT>" ) <EOL> xx , yy = np . meshgrid ( np . linspace ( plt . xlim ( ) [ <NUM_LIT:0> ] , plt . xlim ( ) [ <NUM_LIT:1> ] , <NUM_LIT:100> ) , <EOL> np . linspace ( plt . ylim ( ) [ <NUM_LIT:0> ] , plt . ylim ( ) [ <NUM_LIT:1> ] , <NUM_LIT:100> ) ) <EOL> zz = np . c_ [ xx . ravel ( ) , yy . ravel ( ) ] <EOL> mahal_emp_cov = emp_cov . mahalanobis ( zz ) <EOL> mahal_emp_cov = mahal_emp_cov . reshape ( xx . shape ) <EOL> emp_cov_contour = subfig1 . contour ( xx , yy , np . sqrt ( mahal_emp_cov ) , <EOL> cmap = plt . cm . PuBu_r , <EOL> linestyles = '<STR_LIT>' ) <EOL> mahal_robust_cov = robust_cov . mahalanobis ( zz ) <EOL> mahal_robust_cov = mahal_robust_cov . reshape ( xx . shape ) <EOL> robust_contour = subfig1 . contour ( xx , yy , np . sqrt ( mahal_robust_cov ) , <EOL> cmap = plt . cm . YlOrBr_r , linestyles = '<STR_LIT>' ) <EOL> subfig1 . legend ( [ emp_cov_contour . collections [ <NUM_LIT:1> ] , robust_contour . collections [ <NUM_LIT:1> ] , <EOL> inlier_plot , outlier_plot ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> loc = "<STR_LIT>" , borderaxespad = <NUM_LIT:0> ) <EOL> plt . xticks ( ( ) ) <EOL> plt . yticks ( ( ) ) <EOL> emp_mahal = emp_cov . mahalanobis ( X - np . mean ( X , <NUM_LIT:0> ) ) ** ( <NUM_LIT> ) <EOL> subfig2 = plt . subplot ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> subfig2 . boxplot ( [ emp_mahal [ : - n_outliers ] , emp_mahal [ - n_outliers : ] ] , widths = <NUM_LIT> ) <EOL> subfig2 . plot ( <NUM_LIT> * np . ones ( n_samples - n_outliers ) , <EOL> emp_mahal [ : - n_outliers ] , '<STR_LIT>' , markeredgewidth = <NUM_LIT:1> ) <EOL> subfig2 . plot ( <NUM_LIT> * np . ones ( n_outliers ) , <EOL> emp_mahal [ - n_outliers : ] , '<STR_LIT>' , markeredgewidth = <NUM_LIT:1> ) <EOL> subfig2 . axes . set_xticklabels ( ( '<STR_LIT>' , '<STR_LIT>' ) , size = <NUM_LIT:15> ) <EOL> subfig2 . set_ylabel ( r"<STR_LIT>" , size = <NUM_LIT:16> ) <EOL> subfig2 . set_title ( "<STR_LIT>" ) <EOL> plt . yticks ( ( ) ) <EOL> robust_mahal = robust_cov . mahalanobis ( X - robust_cov . location_ ) ** ( <NUM_LIT> ) <EOL> subfig3 = plt . subplot ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:4> ) <EOL> subfig3 . boxplot ( [ robust_mahal [ : - n_outliers ] , robust_mahal [ - n_outliers : ] ] , <EOL> widths = <NUM_LIT> ) <EOL> subfig3 . plot ( <NUM_LIT> * np . ones ( n_samples - n_outliers ) , <EOL> robust_mahal [ : - n_outliers ] , '<STR_LIT>' , markeredgewidth = <NUM_LIT:1> ) <EOL> subfig3 . plot ( <NUM_LIT> * np . ones ( n_outliers ) , <EOL> robust_mahal [ - n_outliers : ] , '<STR_LIT>' , markeredgewidth = <NUM_LIT:1> ) <EOL> subfig3 . axes . set_xticklabels ( ( '<STR_LIT>' , '<STR_LIT>' ) , size = <NUM_LIT:15> ) <EOL> subfig3 . set_ylabel ( r"<STR_LIT>" , size = <NUM_LIT:16> ) <EOL> subfig3 . set_title ( "<STR_LIT>" ) <EOL> plt . yticks ( ( ) ) <EOL> plt . show ( ) </s>
