|
43 | 43 |
|
44 | 44 | print(__doc__)
|
45 | 45 |
|
46 |
| -rng = np.random.RandomState(42) |
| 46 | +SEED = 42 |
| 47 | + |
| 48 | +rng = np.random.RandomState(SEED) |
47 | 49 |
|
48 | 50 | # Example settings
|
49 | 51 | n_samples = 200
|
50 | 52 | outliers_fraction = 0.25
|
51 |
| -clusters_separation = [0, 1, 2] |
| 53 | +clusters_separation = (0, 1, 2) |
52 | 54 |
|
53 | 55 | # define two outlier detection tools to be compared
|
54 | 56 | classifiers = {
|
|
63 | 65 | contamination=outliers_fraction)}
|
64 | 66 |
|
65 | 67 | # Compare given classifiers under given settings
|
66 |
| -xx, yy = np.meshgrid(np.linspace(-7, 7, 100), np.linspace(-7, 7, 100)) |
67 |
| -n_inliers = int((1. - outliers_fraction) * n_samples) |
| 68 | +xx, yy = np.meshgrid(np.linspace(-7, 7, n_samples // 2), |
| 69 | + np.linspace(-7, 7, n_samples // 2)) |
68 | 70 | n_outliers = int(outliers_fraction * n_samples)
|
| 71 | +n_inliers = n_samples - n_outliers |
69 | 72 | ground_truth = np.ones(n_samples, dtype=int)
|
70 | 73 | ground_truth[-n_outliers:] = -1
|
71 | 74 |
|
72 | 75 | # Fit the problem with varying cluster separation
|
73 |
| -for i, offset in enumerate(clusters_separation): |
74 |
| - np.random.seed(42) |
| 76 | +for _, offset in enumerate(clusters_separation): |
| 77 | + np.random.seed(SEED) |
75 | 78 | # Data generation
|
76 | 79 | X1 = 0.3 * np.random.randn(n_inliers // 2, 2) - offset
|
77 | 80 | X2 = 0.3 * np.random.randn(n_inliers // 2, 2) + offset
|
78 |
| - X = np.r_[X1, X2] |
| 81 | + X = np.concatenate([X1, X2], axis=0) |
79 | 82 | # Add outliers
|
80 |
| - X = np.r_[X, np.random.uniform(low=-6, high=6, size=(n_outliers, 2))] |
| 83 | + X = np.concatenate([X, np.random.uniform(low=-6, high=6, |
| 84 | + size=(n_outliers, 2))], axis=0) |
81 | 85 |
|
82 | 86 | # Fit the model
|
83 | 87 | plt.figure(figsize=(9, 7))
|
|
0 commit comments