发布于 2018-05-29 15:39:46
Sklearn提供了各种保存和重用模型的方法,有关更多信息,请参见模型持久性。
但是,值得注意的是,并非所有的无监督离群点检测模型都能对未见数据进行“预测”。预测()方法可能并不总是一致的和可见的,例如洛夫。如您所见,没有“预测()”方法,只有"fit()“和"fit_predict()”。或者,您应该在Sklearn中使用一个用于LOF的内部方法_decision_function()。
def _decision_function(self, X):
"""Opposite of the Local Outlier Factor of X (as bigger is better,
i.e. large values correspond to inliers).
The argument X is supposed to contain *new data*: if X contains a
point from training, it consider the later in its own neighborhood.
Also, the samples in X are not considered in the neighborhood of any
point.
The decision function on training data is available by considering the
opposite of the negative_outlier_factor_ attribute.这种不一致性是由于大多数孤立点检测方法的无监督性质造成的。它们对于“训练”和“测试”没有什么区别,因为不管怎么说,根本的真理都是缺失的。对于一些无监督的离群点检测方法,保存“经过训练的”模型是没有帮助的。不过,这是一个又一个案例。对于有效的算法,将历史数据与新数据结合起来并对模型进行改进可能是很好的,因为它们来自相同的分布。
因此,对于Sklearn中不同的离群点检测方法,您应该小心使用模型持久性和API。如果您正在寻找更统一的APIs来尝试各种异常检测方法,我将推荐我的python离群点检测工具箱PyOD;文档可以在这里找到PyOD文档。
https://datascience.stackexchange.com/questions/28239
复制相似问题