检查模型是否存在

我们可以通过查找模型名称来检查模型是否在目录中可用。

语法

检查模型是否存在于目录中
CALL gds.model.exists(modelName: String)
YIELD
    modelName: String,
    modelType: String,
    exists: Boolean
表 1. 参数
名称 类型 默认值 可选 描述

modelName

字符串

n/a

模型的名称。

表 2. 结果
名称 类型 描述

modelName

字符串

模型的名称。

modelType

字符串

模型的类型。

exists

布尔值

如果模型存在于模型目录中,则为 True。

示例

在本节中,我们将演示 gds.model.exists 的用法。为简单起见,我们将假设一个名为 my-model1 的示例模型已经过训练,并且存在于模型目录中。

检查现有模型

我们可以通过指定模型名称来检查模型是否存在于目录中。

检查模型是否存在于目录中
CALL gds.model.exists('my-model1');
表 3. 结果
modelName modelType exists

"my-model1"

"example-model-type"

true

如我们所见,该模型确实存在于模型目录中。

检查不存在的模型

如果我们改用不存在的模型名称,则 exists 字段将获得 false 值。

检查模型是否存在于目录中
CALL gds.model.exists('does-not-exist');
表 4. 结果
modelName modelType exists

"does-not-exist"

"n/a"

false

如我们所见,此模型不存在于模型目录中。由于此模型不存在,因此其类型为 n/a