我尝试复制h2o文档中的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 knotsknots1 <- 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 dataseth2o_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 factorsh2o_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 setsh2o_data.splits <- h2o.splitFrame(data=h2o_data, ratios=.8)train <- h2o_data.splits[[1]]test <- h2o_data.splits[[2]]# Set the predictor and response columnspredictors <- colnames(train[1:2])response <- 'C11'# specify the knots arraynumKnots <- c(5,5,5)# build the GAM modelgam_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 knotsknots1 <- 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)