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