def runtime(X, y, model_generator, method_name):
    """ Runtime
    transform = "negate"
    sort_order = 1
    """

    old_seed = np.random.seed()
    np.random.seed(3293)

    # average the method scores over several train/test splits
    method_reps = []
    for i in range(1):
        X_train, X_test, y_train, _ = train_test_split(__toarray(X), y, test_size=100, random_state=i)

        # define the model we are going to explain
        model = model_generator()
        model.fit(X_train, y_train)

        # evaluate each method
        start = time.time()
        explainer = getattr(methods, method_name)(model, X_train)
        build_time = time.time() - start

        start = time.time()
        explainer(X_test)
        explain_time = time.time() - start

        # we always normalize the explain time as though we were explaining 1000 samples
        # even if to reduce the runtime of the benchmark we do less (like just 100)
        method_reps.append(build_time + explain_time * 1000.0 / X_test.shape[0])
    np.random.seed(old_seed)

    return None, np.mean(method_reps)
def runtime ( X , y , model_generator , method_name ) : old_seed = np . random . seed ( ) np . random . seed ( 3293 ) method_reps = [ ] for i in range ( 1 ) : X_train , X_test , y_train , _ = train_test_split ( __toarray ( X ) , y , test_size = 100 , random_state = i ) model = model_generator ( ) model . fit ( X_train , y_train ) start = time . time ( ) explainer = getattr ( methods , method_name ) ( model , X_train ) build_time = time . time ( ) - start start = time . time ( ) explainer ( X_test ) explain_time = time . time ( ) - start method_reps . append ( build_time + explain_time * 1000.0 / X_test . shape [ 0 ] ) np . random . seed ( old_seed ) return None , np . mean ( method_reps )
Runtime
    transform = "negate"
    sort_order = 1