代码之家  ›  专栏  ›  技术社区  ›  abu

更新到3.18后,估计h2o中的xgboost时出错

  •  0
  • abu  · 技术社区  · 7 年前

    我遇到了一个已知的问题,即无法保存xgboost模型并在稍后加载它以获得预测,而它可能在h2o 3.18中发生了更改(问题出现在3.16中)。我从h2o的网站(可下载的zip)更新了包,现在没有问题的模型出现以下错误:

    Error in .h2o.doSafeREST(h2oRestApiVersion = h2oRestApiVersion, urlSuffix = urlSuffix,  : 
      Unexpected CURL error: Failed to connect to localhost port 54321: Connection refused
    

    这仅适用于xgboost(二进制分类),因为我使用的其他模型工作正常。当然,h2o已经初始化,之前的模型估计没有问题。有人知道问题出在哪里吗?

    编辑:以下是一个产生错误的可复制示例(基于Erin的答案):

    library(h2o)
    library(caret)
    h2o.init()
    
    # Import a sample binary outcome train set into H2O
    train <- h2o.importFile("https://s3.amazonaws.com/erin-data/higgs/higgs_train_10k.csv")
    
    # Identify predictors and response
    y <- "response"
    x <- setdiff(names(train), y)
    
    # Assigning fold column
    set.seed(1)
    cv_folds <- createFolds(as.data.frame(train)$response,
                            k = 5,
                            list = FALSE,
                            returnTrain = FALSE)
    
    # version 1
    train <- train %>%
        as.data.frame() %>% 
        mutate(fold_assignment = cv_folds) %>%
        as.h2o()
    
    # version 2
    train <- h2o.cbind(train, as.h2o(cv_folds))
    names(train)[dim(train)[2]] <- c("fold_assignment")
    
    
    # For binary classification, response should be a factor
    train[,y] <- as.factor(train[,y])
    
    xgb <- h2o.xgboost(x = x,
                       y = y, 
                       seed = 1,
                       training_frame = train,
                       fold_column = "fold_assignment",
                       keep_cross_validation_predictions = TRUE,
                       eta = 0.01,
                       max_depth = 3,
                       sample_rate = 0.8,
                       col_sample_rate = 0.6,
                       ntrees = 500,
                       reg_lambda = 0,
                       reg_alpha = 1000,
                       distribution = 'bernoulli') 
    

    创建列车数据的两个版本。帧会导致相同的错误。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Erin LeDell    7 年前

    你没有说你是否用3.18对模型进行了重新训练。通常,H2O只保证主要版本H2O之间的模型兼容性。如果您没有重新培训模型,这可能就是XGBoost不能正常工作的原因。如果您已经用3.18对模型进行了重新培训,而XGBoost仍然不起作用,那么请发布一个可复制的示例,我们将进一步检查。

    编辑: 我正在添加可复制的示例(与您的代码和此代码的唯一区别是我没有使用 fold_column 此处)。这在3.18.0.2上运行良好。如果没有一个产生错误的可复制示例,我将无法进一步帮助您。

    library(h2o)
    h2o.init()
    
    # Import a sample binary outcome train set into H2O
    train <- h2o.importFile("https://s3.amazonaws.com/erin-data/higgs/higgs_train_10k.csv")
    
    # Identify predictors and response
    y <- "response"
    x <- setdiff(names(train), y)
    
    # For binary classification, response should be a factor
    train[,y] <- as.factor(train[,y])
    
    xgb <- h2o.xgboost(x = x,
                       y = y, 
                       seed = 1,
                       training_frame = train,
                       keep_cross_validation_predictions = TRUE,
                       eta = 0.01,
                       max_depth = 3,
                       sample_rate = 0.8,
                       col_sample_rate = 0.6,
                       ntrees = 500,
                       reg_lambda = 0,
                       reg_alpha = 1000,
                       distribution = 'bernoulli')