我想知道我是否可以为无监督学习执行任何类型的交叉验证或 GridSearchCV。问题是我有地面实况标签(但由于它是无监督的,我只是将它们丢弃用于训练,然后重用它们来测量测试集上的准确度、auc、aucpr、f1-score)。
有没有办法做到这一点?
我想知道我是否可以为无监督学习执行任何类型的交叉验证或 GridSearchCV。问题是我有地面实况标签(但由于它是无监督的,我只是将它们丢弃用于训练,然后重用它们来测量测试集上的准确度、auc、aucpr、f1-score)。
有没有办法做到这一点?
是的 - 您可以将 scikit-learn 的GridSearchCV与无监督算法一起使用。由于 scikit-learn 的 Isolation Forest 没有评分功能,因此必须实现自定义评分功能。它会是这样的:
import numpy as np
from sklearn.ensemble import IsolationForest
from sklearn.model_selection import GridSearchCV
def scorer(estimator, X):
"Custom scoring function"
return np.mean(estimator.score_samples(X))
isolation_forest = GridSearchCV(IsolationForest(), scoring=scorer)
isolation_forest.fit(X)