石灰水模型在R

石灰水模型在R,r,dataframe,h2o,R,Dataframe,H2o,我想在R中使用h2o(深度学习)创建的模型上实现。为了在模型中使用数据,我创建了h2oFrames并将其转换回dataframe,然后在LIME中使用它(LIME函数,因为LIME的解释函数无法识别h2oFrame)。在这里,我可以运行该函数 下一步是对测试数据使用explain函数来生成解释。在这里,R抛出了一个使用数据帧和数据帧的错误 这是使用数据帧时生成的错误: 这是使用帧时产生的错误: if(!require(pacman))安装程序包(“pacman”) pacman::p_荷载(水、

我想在R中使用h2o(深度学习)创建的模型上实现。为了在模型中使用数据,我创建了h2oFrames并将其转换回dataframe,然后在LIME中使用它(LIME函数,因为LIME的解释函数无法识别h2oFrame)。在这里,我可以运行该函数

下一步是对测试数据使用explain函数来生成解释。在这里,R抛出了一个使用数据帧和数据帧的错误

这是使用数据帧时生成的错误:

这是使用帧时产生的错误:

if(!require(pacman))安装程序包(“pacman”)
pacman::p_荷载(水、石灰、数据表,e1071)
数据(iris)
h2o.init(n读数=-1)
h2o.无进展()
#拆分数据集

iris发动机罩下的
lame
软件包使用两个功能,
predict_model()
model_type()
,您需要为当前不受支持的任何型号设置这两个功能

对于您的具体示例,以下是您需要做的

步骤1:为类
H2O多项式模型
的模型设置通用
模型类型
函数。您在这里所要做的就是告诉
lime
您希望它执行的模型类型,例如“分类”或“回归”

一旦正确设置了这些函数,就可以运行
lime
脚本

# Lime is used to get explain on the train data
explainer <- lime(train_org, model_dl_1, bin_continuous = FALSE, n_bins = 5, n_permutations = 1000)

# Explain new observation
explanation <- explain(test_sample, explainer, n_labels = 1, n_features = 1)
#石灰用于获取列车数据的解释

解释者请提供一个完全可复制的代码示例以及关于lime和h2o R软件包的版本信息。你需要在你的帖子中更新代码,使其可复制——它可以是任何数据集(iris也可以)。请参阅此处有关MCVE的堆栈溢出指导原则:如果我无法复制/粘贴您的代码以帮助您调试代码,那么它就不是MCVE。@Eriledell,谢谢您的反馈,我将进行更改。@Eriledell,我已经发布了完整的代码。请你看看。感谢您的时间。您能否澄清两条错误消息中的哪一条与您发布的代码有关,以及它发生在哪一行?请注意,
lime
包已更新为集成
h2o
。您可能需要在此处下载GitHub版本:
Error in UseMethod("permute_cases") : 
  no applicable method for 'permute_cases' applied to an object of class "H2OFrame"
if(!require(pacman))  install.packages("pacman")
pacman::p_load(h2o, lime, data.table, e1071)

data(iris)
h2o.init( nthreads = -1 )
h2o.no_progress()

# Split up the data set
iris <- as.h2o(iris)

split <- h2o.splitFrame( iris, c(0.6, 0.2), seed = 1234 )
iris_train <- h2o.assign( split[[1]], "train" ) # 60%
iris_valid <- h2o.assign( split[[2]], "valid" ) # 20%
iris_test  <- h2o.assign( split[[3]], "test" )  # 20%


output <- 'Species'
input <- setdiff(names(iris),output)


model_dl_1 <- h2o.deeplearning(
  model_id = "dl_1", 
  training_frame = iris_train, 
  validation_frame = iris_valid,
  x = input,
  y = output,
  hidden = c(32, 32, 32),
  epochs = 10, # hopefully converges earlier...
  score_validation_samples = 10000, 
  stopping_rounds = 5,
  stopping_tolerance = 0.01
)

pred1 <- h2o.predict(model_dl_1, iris_test)
list(dimension = dim(pred1), pred1$predict)

#convert to df from h2ofdataframe

train_org<-as.data.frame(iris_train) 
#converting train h2oframe to dataframe
sapply(train_org,class) #checking the class of train_org
test_df <- as.data.frame(iris_test) 
#converting test data h2oFrame to dataframe
test_sample <- test_df[1:1,] 

#works
#lime is used to get explain on the train data
explain <- lime(train_org, model_dl_1, bin_continuous = FALSE, n_bins = 
                  5, n_permutations = 1000)


# Explain new observation
explanation <- explain(test_sample, n_labels = 1, n_features = 1)
h2o.shutdown(prompt=F)
model_type.H2OMultinomialModel <- function(x, ...) {
    # Function tells lime() what model type we are dealing with
    # 'classification', 'regression', 'survival', 'clustering', 'multilabel', etc
    #
    # x is our h2o model

    return("classification")

}
predict_model.H2OMultinomialModel <- function(x, newdata, type, ...) {
    # Function performs prediction and returns dataframe with Response
    #
    # x is h2o model
    # newdata is data frame
    # type is only setup for data frame

    pred <- h2o.predict(x, as.h2o(newdata))

    # return classification probabilities only
    return(as.data.frame(pred[,-1]))

}
# Lime is used to get explain on the train data
explainer <- lime(train_org, model_dl_1, bin_continuous = FALSE, n_bins = 5, n_permutations = 1000)

# Explain new observation
explanation <- explain(test_sample, explainer, n_labels = 1, n_features = 1)