【发布时间】:2020-03-12 14:48:27
【问题描述】:
我是机器学习领域的新手,我正在(尝试)实现异常检测算法,一种算法是自动编码器,借助 tensorflow 库中的 keras 实现,第二种算法是 IsolationForest,借助 sklearn 库实现,我想要在 roc_auc_score (function from Python) 的帮助下比较这些算法,但我不确定我是否正确。
在 roc_auc_score 函数的文档中我可以看到,输入应该是这样的:
sklearn.metrics.roc_auc_score(y_true, y_score, average='macro', sample_weight=None, max_fpr=None
y_true: 真正的二进制标签或二进制标签指示符。
y_score: 目标分数可以是正类的概率估计、置信度值或决策的非阈值度量(由某些分类器上的“decision_function”返回)。对于二进制 y_true,y_score 应该是具有更大标签的类的分数。
对于 AE,我正在像这样计算 roc_auc_score:
model.fit(...) # model from https://www.tensorflow.org/api_docs/python/tf/keras/Sequential
pred = model.predict(x_test) # predict function from https://www.tensorflow.org/api_docs/python/tf/keras/Sequential#predict
metric = np.mean(np.power(x_test - pred, 2), axis=1) #MSE
print(roc_auc_score(y_test, metric) # where y_test is true binary labels 0/1
对于 IsolationForest,我正在计算 roc_auc_score,如下所示:
model.fit(...) # model from https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.IsolationForest.html
metric = -(model.score_samples(x_test)) # https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.IsolationForest.html#sklearn.ensemble.IsolationForest.score_samples
print(roc_auc_score(y_test, metric) #where y_test is true binary labels 0/1
我只是好奇从 AE 和 IsolationForest 的两个实现返回的 roc_auc_score 是否具有可比性(我的意思是,如果我以正确的方式计算它们)?特别是在 AE 模型中,我将 MSE 放入 roc_auc_score(如果没有,这个函数的 y_score 应该是什么输入?)
【问题讨论】:
标签: machine-learning scikit-learn metrics autoencoder anomaly-detection