decision_function is not available when novelty=False. Use novelty=True if you want to use LOF for novelty detection and compute decision_function for new unseen data. Note that the opposite LOF of the training samples is always available by considering the negative_outlier_factor_ attribute.怎么解决python
时间: 2024-02-06 14:04:31 浏览: 330
这个错误通常发生在你使用 scikit-learn 的 LocalOutlierFactor 模型时,尝试在 novelty=False 的情况下调用 decision_function() 方法时。
LocalOutlierFactor 模型的 decision_function() 方法只适用于 novelty=True 的情况,即用于新的未见过的数据的离群值检测。如果 novelty=False,表示你只是在对已有的数据进行离群值检测,那么就不能使用 decision_function() 方法。
如果你确实需要在 novelty=False 的情况下使用 decision_function() 方法,你可以将模型的 novelty 参数设置为 True,例如:
```python
from sklearn.neighbors import LocalOutlierFactor
clf = LocalOutlierFactor(novelty=True)
clf.fit(X_train)
scores = clf.decision_function(X_test)
```
这样就可以使用 decision_function() 方法来计算测试数据的离群得分了。需要注意的是,这样做会将模型用于新的未见过的数据,而不是仅用于已有的数据。另外,训练数据的相反LOF值始终可通过考虑 negative_outlier_factor_ 属性获得。
相关问题
novelty detection
新颖性检测(Novelty Detection)也被称为异常检测(Anomaly Detection)或离群点检测(Outlier Detection),其目的是使机器能够识别出当前场景的输入与之前场景的输入(训练或实践过程中)是否一致,从而避免潜在的危险,或是开始对新场景的学习。新颖性检测的研究主要包括两种思路:一种是构建One-Other的分类器,通过利用特征空间上各数据点的距离等度量方式实现;另一种是基于Encode-Decode思想,通过训练集训练学习算法压缩数据特征并恢复的能力,而测试集中那些不能很好被恢复的特征所对应的数据点一定与训练集有一定区别,因而被视为新颖点。\[2\]
需要注意的是,neighbors.LocalOutlierFactor是一种用于异常值检测的估计器,不直接支持新颖性检测。如果想要使用neighbors.LocalOutlierFactor进行新颖性检测,可以在实例化估计器时将新颖性参数设置为True。在这种情况下,fit_predict方法不可用,但可以通过negative_outlier_factor_属性访问训练样本的异常分数。\[3\]
#### 引用[.reference_title]
- *1* *3* [离群点(outlier detection)和新颖点(novelty detection)检测与OneClassSVM应用实例(基于python)](https://blog.csdn.net/lyxleft/article/details/89344219)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Anytime Online Novelty Detection for Vehicle Safeguarding:实时新颖性检测方法](https://blog.csdn.net/weixin_39078049/article/details/102057682)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
用英文润色一下下面一段论文:y.After each round of interaction, the consumer estimates the utility of the predicate used in the query, which is useful for planning the next round of interaction. The utility of a predicate 푃 expresses the anticipated accuracy improvement that R푃 brings to M. We define a measure that we call novelty to quantify predicate utility. The basic idea of this measure is to quantify the difference between the data acquired in the interaction to those that the consumer currently possesses. The higher the difference, the more information this interaction brings to the consumer. Let RM:푃 be the records the consumer currently possesses satisfying 푃. The novelty of predicate 푃, denoted as 푈푃 , is defined on RM:푃 and R푃 . More specifically, we consider a binary classification problem that treats RM:푃 and R푃 as samples from class 0 and class 1 respectively, and train a classifier CLF to distinguish between the two sets of records. The utility of 푃 is computed as follows:
请用中文润色:每一轮交互后,消费者估计查询中使用的谓词的效用,这对规划下一轮交互很有用。谓词 푃 的效用表示 R푃 给 M 带来的预期精确度提高。我们定义了一个称为新颖性的度量来量化谓词效用。这个度量的基本思想是量化交互中获得的数据与消费者当前拥有的数据的差异。差异越大,这次交互为消费者带来的信息就越多。设 RM:푃 为消费者当前拥有满足 푃 的记录。谓词 푃 的新颖性,符号为 푈푃 ,是基于 RM:푃 和 R푃 定义的。更具体地,我们考虑一个二分类问题,将 RM:푃 和 R푃 分别作为类 0 和类 1 的样本,并训练分类器 CLF 来区分这两组记录。计算 푃 的效用如下:
阅读全文