'How Do I Uploading Data Externally in Explainerdashboard

I am trying to upload external data into the dashboard using explainer.set_x_row_func() and explainer.set_y_func(). Does anyone know how to do this? Below is how to get around it, I tried it out with the following code.

def: This algorithm runs some basic models and lets the user select the X and y variables.

class ExternalSourceClassifierTests(unittest.TestCase):
     model = RandomForestRegressor()
     model.fit(X_train, y_train)
 
  
     X_test.reset_index(drop=False, inplace=True)
     X_test.index = X_test.index.astype(str)

     X_test1, y_test1 = X_test.iloc[:100], y_test.iloc[:100]
     X_test2, y_test2 = X_test.iloc[100:], y_test.iloc[100:]
     
     
     explainer = RegressionExplainer(model, X_test, y_test)

     def index_exists_func(index):
         return index in X_test2.index

     def index_list_func():
        # only returns first 50 indexes
        return list(X_test2.index[:50])

     def y_func(index):
            idx = X_test2.index.get_loc(index)
            return y_test2.iloc[[idx]]

     def X_func(index):
            idx = X_test2.index.get_loc(index)
            return X_test2.iloc[[idx]]

     print (explainer.set_index_exists_func(index_exists_func))
     print(explainer.set_index_list_func(index_list_func))
     print(explainer.set_X_row_func(X_func))
     print(explainer.set_y_func(y_func))
     print(explainer.plot_importances())

and I got the following output:

1

More info here

I intend to create an upload tab and then upload external data forthwith but I don't know how.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source