R 中 H2o 中的 GAM 模型

Models GAM in H2o from R

我正在尝试复制 h2o documentation- GAM 中的 GAM 模型示例,但是,我收到以下错误:

*Error: water.exceptions.H2OModelBuilderIllegalArgumentException: Illegal argument(s) for GAM model: GAM_model_R_1586448366888_1.  Details: ERRR on field: knots formation: knots not sorted in ascending order. Knots at index 0: 1,000000.  Knots at index 1: 0,000000*

不知道为什么会报错,我复制粘贴了和例子中完全一样的代码

我 运行 的脚本与 h2o 文档示例中的脚本相同。

这是代码:

# create frame knots
knots1 <- c('-1.99905699', '-0.98143075', '0.02599159', '1.00770987', '1.99942290')
frameKnots1 <- as.h2o(knots1)
knots2 <- c('-1.999821861', '-1.005257990', '-0.006716042', '1.002197392', '1.999073589')
frameKnots2 <- as.h2o(knots2)
knots3 <- c('-1.999675688', '-0.979893796', '0.007573327', '1.011437347', '1.999611676')
frameKnots3 <- as.h2o(knots3)

# import the dataset
h2o_data <- h2o.importFile("https://s3.amazonaws.com/h2o-public-test-data/smalldata/glm_test/multinomial_10_classes_10_cols_10000_Rows_train.csv")

# Convert the C1, C2, and C11 columns to factors
h2o_data["C1"] <- as.factor(h2o_data["C1"])
h2o_data["C2"] <- as.factor(h2o_data["C2"])
h2o_data["C11"] <- as.factor(h2o_data["C11"])

# split into train and test sets
h2o_data.splits <- h2o.splitFrame(data=h2o_data, ratios=.8)
train <- h2o_data.splits[[1]]
test <- h2o_data.splits[[2]]

# Set the predictor and response columns
predictors <- colnames(train[1:2])
response <- 'C11'

# specify the knots array
numKnots <- c(5,5,5)

# build the GAM model
gam_model <- h2o.gam(x=predictors,
                     y=response,
                     training_frame = train,
                     family='multinomial',
                     gam_columns=c("C6","C7","C8"),
                     scale=c(1,1,1),
                     num_knots=numKnots,
                     knot_ids=c(h2o.keyof(frameKnots1), h2o.keyof(frameKnots2), h2o.keyof(frameKnots3)))

谢谢。

问题是您将结位置存储为字符串(抱歉,这是 GAM User Guide page 上的演示代码的错误——我们会修复它)。如果您更改代码的第一行(删除数字周围的引号),它将起作用:

# create frame knots
knots1 <- c(-1.99905699, -0.98143075, 0.02599159, 1.00770987, 1.99942290)
frameKnots1 <- as.h2o(knots1)
knots2 <- c(-1.999821861, -1.005257990, -0.006716042, 1.002197392, 1.999073589)
frameKnots2 <- as.h2o(knots2)
knots3 <- c(-1.999675688, -0.979893796, 0.007573327, 1.011437347, 1.999611676)
frameKnots3 <- as.h2o(knots3)