Skip to content

Commit 61e722a

Browse files
tuliocasagrandelesteve
authored andcommitted
Improve readability of LOF example (scikit-learn#10322)
1 parent d8483df commit 61e722a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

examples/neighbors/plot_lof.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@
2626
np.random.seed(42)
2727

2828
# Generate train data
29-
X = 0.3 * np.random.randn(100, 2)
29+
X_inliers = 0.3 * np.random.randn(100, 2)
30+
X_inliers = np.r_[X_inliers + 2, X_inliers - 2]
31+
3032
# Generate some abnormal novel observations
3133
X_outliers = np.random.uniform(low=-4, high=4, size=(20, 2))
32-
X = np.r_[X + 2, X - 2, X_outliers]
34+
X = np.r_[X_inliers, X_outliers]
3335

3436
# fit the model
3537
clf = LocalOutlierFactor(n_neighbors=20)
3638
y_pred = clf.fit_predict(X)
37-
y_pred_outliers = y_pred[200:]
3839

3940
# plot the level sets of the decision function
4041
xx, yy = np.meshgrid(np.linspace(-5, 5, 50), np.linspace(-5, 5, 50))
@@ -44,9 +45,9 @@
4445
plt.title("Local Outlier Factor (LOF)")
4546
plt.contourf(xx, yy, Z, cmap=plt.cm.Blues_r)
4647

47-
a = plt.scatter(X[:200, 0], X[:200, 1], c='white',
48+
a = plt.scatter(X_inliers[:, 0], X_inliers[:, 1], c='white',
4849
edgecolor='k', s=20)
49-
b = plt.scatter(X[200:, 0], X[200:, 1], c='red',
50+
b = plt.scatter(X_outliers[:, 0], X_outliers[:, 1], c='red',
5051
edgecolor='k', s=20)
5152
plt.axis('tight')
5253
plt.xlim((-5, 5))

0 commit comments

Comments
 (0)