我正在尝试复制h2o文档-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用户指南页面上演示代码的一个错误,我们会修复它(。如果你更改代码的第一行(去掉数字周围的引号(,它就会起作用:
# 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)