如何在sklearn中得到isolationforest的top predictions
How to get the top predictions of isolationforest in sklearn
我正在使用 IsolationForest
来检测我的数据集的异常数据点。
clf = IsolationForest(max_samples='auto',
random_state=42,
behaviour="new",
contamination=.01)
clf.fit(X)
y_pred_train = clf.predict(X)
outliers = []
for item in np.where(y_pred_train == -1)[0]:
outliers.append(df_nodes[item])
我想要预测的异常值作为排名列表。也就是说,我想知道什么是最有可能的离群值以及下一个离群值等等(可能使用某种预测概率进行排序)。我试图在 sklearn
中找到一种方法来做到这一点。但是,我仍然找不到办法。请告诉我一个合适的方法。
如果需要,我很乐意提供更多详细信息。
不使用 predict
,而是使用 decision_function
。
来自docs:
Methods
decision_function(self, X) Average anomaly score of X of the base classifiers.
然后,您可以根据他们的异常分数对他们进行排名。这个值越低,观察越不正常。
我正在使用 IsolationForest
来检测我的数据集的异常数据点。
clf = IsolationForest(max_samples='auto',
random_state=42,
behaviour="new",
contamination=.01)
clf.fit(X)
y_pred_train = clf.predict(X)
outliers = []
for item in np.where(y_pred_train == -1)[0]:
outliers.append(df_nodes[item])
我想要预测的异常值作为排名列表。也就是说,我想知道什么是最有可能的离群值以及下一个离群值等等(可能使用某种预测概率进行排序)。我试图在 sklearn
中找到一种方法来做到这一点。但是,我仍然找不到办法。请告诉我一个合适的方法。
如果需要,我很乐意提供更多详细信息。
不使用 predict
,而是使用 decision_function
。
来自docs:
Methods decision_function(self, X) Average anomaly score of X of the base classifiers.
然后,您可以根据他们的异常分数对他们进行排名。这个值越低,观察越不正常。