Skip to content

Instantly share code, notes, and snippets.

@lynnssi
Created December 1, 2021 02:07
Show Gist options
  • Save lynnssi/fee9347ab2cbb7cd0330cadbda28b42a to your computer and use it in GitHub Desktop.
Save lynnssi/fee9347ab2cbb7cd0330cadbda28b42a to your computer and use it in GitHub Desktop.
from sklearn.neighbors import LocalOutlierFactor
# fit the model for outlier detection (default)
clf = LocalOutlierFactor(novelty=False)
y_pred = clf.fit_predict(X_train)
# Convert y_pred to the same convention as pyod.
# In sklearn, -1 is an outlier. In pyod, 1 is an outlier.
y_pred = y_pred == -1
n_errors = (y_pred != y_train).sum()
print("Error rate:", n_errors/len(y_pred))
>> Error rate: 0.09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment