Created
December 1, 2021 02:20
-
-
Save lynnssi/90e426ce76a46dab1b17802ae0a05f1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clf = LocalOutlierFactor(novelty=True) | |
clf = clf.fit(X_train) | |
test_scores = clf.decision_function(X_test) | |
# LOF in sklearn returns negative decision scores. Multiply by -1 to approximate the original score, otherwise the roc_auc_score function doesn't work. | |
# Documentation: "Inliers tend to have a LOF score close to 1 (negative_outlier_factor_ close to -1), while outliers tend to have a larger LOF score" | |
test_scores = -1*test_scores | |
roc = round(roc_auc_score(y_test, test_scores), ndigits=4) | |
prn = round(precision_n_scores(y_test, test_scores), ndigits=4) | |
print(f'{clf_name} ROC:{roc}, precision @ rank n:{prn}') | |
#>> LOF ROC:0.9656, precision @ rank n:0.8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment