estimators = load_models(time, target, drop_opt, model_names)
    # Subsample time indices to reduce autocorrelations
    X_subset, y_subset = get_independent_samples(X, y, info)
    explainer = InterpretToolkit(estimators=estimators,
                                 estimator_names=model_names,
                                 X=X_subset.copy(),
                                 y=y_subset.copy())
    background_dataset = shap.sample(X, 100)

    results = explainer.local_contributions(
        method='shap',
        background_dataset=background_dataset,
        performance_based=True,
        n_samples=n_samples)

    results = explainer.save(fname=save_fname, data=results)

    duration = datetime.datetime.now() - start_time
    seconds = duration.total_seconds()
    hours = seconds // 3600
    minutes = (seconds % 3600) // 60
    seconds = seconds % 60

    message = f""" 
               SHAP Feature Contributions values for {target} {time}  are done!
               Started at {start_time.strftime("%I:%M %p")}, 
               Duration : {hours:.2f} hours : {minutes:.2f} minutes : {seconds:.2f} seconds
              """
    send_email(message)

message = 'SHAP value computation are done running!'
Beispiel #2
0
iterator = itertools.product(time_set, target_set)

for combo in iterator:
    time, target = combo
    parameters = {
        'time': time,
        'target': target,
        'drop_opt': drop_opt,
    }
    X, y = _load_train_data(**parameters)
    estimators = load_models(time, target, drop_opt, model_names)
    explainer = InterpretToolkit(estimators=estimators,
                                 estimator_names=model_names,
                                 X=X,
                                 y=y)

    # ale_results_all_models_tornado_first_hourL1_based_feature_selection_aggressive.nc
    fnames = join(ale_path,
                  f'ale_results_all_models_{target}_{time}{drop_opt}.nc')
    ale = explainer.load(fnames=fnames)
    results = explainer.interaction_strength(ale,
                                             n_bootstrap=10,
                                             subsample=0.1)

    print(results)

    explainer.save(fname=join(
        ale_path, f'ias_score_all_models_{target}_{time}{drop_opt}.nc'),
                   data=results)
Beispiel #3
0
    estimators = load_models(time, target, drop_opt, model_names)

    explainer = InterpretToolkit(estimators=estimators,
                                 estimator_names=model_names,
                                 X=X,
                                 y=y)
    results = explainer.pd(
        features='all',
        n_bootstrap=n_bootstrap,
        subsample=subsample,
        n_jobs=njobs,
        n_bins=n_bins,
    )

    print(f'Saving {results_fname}...')
    explainer.save(fname=results_fname, data=results)

duration = datetime.datetime.now() - start_time
seconds = duration.total_seconds()
hours = seconds // 3600
minutes = (seconds % 3600) // 60
seconds = seconds % 60

message = f"""
            PD computations are done running! 
            Started at {start_time.strftime("%I:%M %p")}, 
            Duration : {hours:.2f} hours : {minutes:.2f} minutes : {seconds:.2f} seconds
            """

send_email(message)