如何在sklearn中的isolationforest中使用文档向量

How to use document vectors in isolationforest in sklearn

为了理解 isolation forest 的真正作用,我使用如下 8 个功能做了一个示例项目。

from sklearn.ensemble import IsolationForest    
#features
df_selected = df[["feature1", "feature2", "feature3", "feature4", "feature5", "feature6", "feature7", "feature8"]]
X = np.array(df_selected)

#isolation forest
clf = IsolationForest(max_samples='auto', random_state=42, behaviour="new", contamination=.01)
clf.fit(X)
y_pred_train = clf.predict(X)

print(np.where(y_pred_train == -1)[0])

现在,我想使用 isolation forest 来确定哪些是 异常文档。为此,我使用 gensim 训练了一个 doc2vec 模型。现在,对于数据集中的每个文档,我都有一个 300-dimensional vector.

我的问题是我可以直接使用 isolation forest 中的文档向量作为上面代码中的 X 来检测异常值吗?或者我是否需要在将向量应用到 isolation forest 之前降低向量的维度?

如果需要,我很乐意提供更多详细信息。

您可以直接使用 predict() 检测异常值,除非您计划删除一些不会在训练模型中考虑的变量。

总的来说,我会说做一个相关性分析并删除彼此高度相关的变量(逻辑基础是如果它们高度相关,那么它们是相同的并且不应该鼓励偏差通过加倍考虑的变量)。

请随意提出异议或陈述您的考虑,因为我认为以上确实是我对如何解决问题的看法。