Trying to use DALEX on my data. Getting following error in line pb_h2o_automl <- predict_parts(explainer_h2o_automl,new_observation = new_date_birth,type="break_down")
Error
Error in contribution[nrow(contribution), ] <- cumulative[nrow(contribution), :
incorrect number of subscripts on matrix
Code
rm( list = ls() )
library(DALEX) ; library(h2o) ; library(DALEXtra) ; library(readxl) ; library(dplyr)
set.seed(17)
setwd( 'E:\\projects\\political_analysis' )
df0 = read_excel('training.xlsx')
df0$age = as.numeric( df0$age)
df1 <- df0[c("area", "district", "assembly_constituency", "gender", "age", "party_assembly_election_2018",
"party_current_year_election", "chief_minister", "leader_vote_for_mla", "benefit_govt_scheme",
"benefit_current_budget_scheme", "occupation", "education", "social_category", "caste", "caste_other",'party_upcoming_election')]
df1 <- df1 %>% mutate_all(~ifelse(is.na(.), as.character(names(which.max(table(na.omit(.))))), as.character(.))) %>% mutate_at(vars(-age), as.factor)
h2o.init()
target <- "party_upcoming_election"
df <- as.h2o(df1)
model_h2o_automl <- h2o.automl(y = target, training_frame = df, max_models = 5, max_runtime_secs = 600 )
leader_board <- h2o.get_leaderboard(model_h2o_automl)
head(leader_board)
test_df_0 = df1[1,]
explainer_h2o_automl <- DALEXtra::explain_h2o(model = model_h2o_automl,
data = test_df_0,
y = test_df_0$party_upcoming_election,
label = "h2o automl",
colorize = T)
new_date_birth <- test_df_0 %>% select( - c('party_upcoming_election'))
pb_h2o_automl <- predict_parts(explainer_h2o_automl,new_observation = new_date_birth,type="break_down")
Have pasted first 50 rows of data here :