在R中使用H2o的GAM模型

我尝试复制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)

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注