return krr_model.predict(array) # dimension of the ambient space dim = X_scaled.shape[1] # the example to explain xi = X_scaled[0, :] # grid of bandwidths n_nu = 50 nu_min = 0.001 nu_max = 4 nu_grid = np.linspace(nu_min, nu_max, num=n_nu) # get the summary of the training data my_stats = get_training_data_stats(X_scaled, p) coef_store = np.zeros((n_nu, dim + 1)) std_store = np.zeros((n_nu, dim + 1)) beta_emp_store = np.zeros((n_nu, n_exp, dim + 1)) # main loop: for each bandwidth obtain many LIME explanations for i_nu in range(n_nu): nu = nu_grid[i_nu] s_nu = "bandwidth: {}".format(nu) print(s_nu) # creating the explainer explainer = lime.lime_tabular.LimeTabularExplainer( X_orig,
# the example to explain xi = np.random.uniform(-10,10,(dim,)) # training set n_train = 1000 train = np.random.uniform(-10,10,(n_train,dim)) # bandwidth parameter nu = 10 # number of bins along each dimension p = 10 # creating the discretizer my_stats = get_training_data_stats(train,p) # creating the explainer explainer = lime.lime_tabular.LimeTabularExplainer(train, mode='regression', feature_selection='none', training_data_stats=my_stats, kernel_width=nu) beta_emp_store = np.zeros((n_exp,dim+1)) for i_exp in range(n_exp): if np.mod(i_exp + 1,10) == 0: s_exp = "Experiment {} / {} is running...".format(i_exp + 1,n_exp) print(s_exp)
# the example to explain xi = np.random.uniform(-10, 10, (dim, )) # training set: uniform on [-10,10]^dim n_train = 1000 train_set = np.random.uniform(-10, 10, (n_train, dim)) # bandwidth parameter nu = 10 # number of bins p = 4 # creating the discretizer my_stats = get_training_data_stats(train_set, p) # creating the explainer explainer = lime.lime_tabular.LimeTabularExplainer( train_set, mode='regression', feature_selection='none', training_data_stats=my_stats, kernel_width=nu) beta_emp_store_1 = np.zeros((n_exp, dim + 1)) beta_emp_store_2 = np.zeros((n_exp, dim + 1)) beta_emp_store_sum = np.zeros((n_exp, dim + 1)) for i_exp in range(n_exp): if np.mod(i_exp + 1, 10) == 0: