예제 #1
0
        models=[calibrated_pipeline],
        model_names=model_names,
        examples=examples,
        targets=target_values,
    )

    # Load the permutation important results from the saved pickle file
    with open(f'IMPORTANT_FEATURES_ALL_MODELS_{target}_{time}.pkl',
              'rb') as pkl_file:
        important_vars = pickle.load(pkl_file)

    features = list(itertools.combinations(important_vars, r=2))
    results = myInterpreter.calc_ale(
        features=features,
        n_bootstrap=n_bootstrap,
        subsample=subsample,
        n_jobs=njobs,
        n_bins=n_bins,
    )

    results_fname = join(
        ale_path,
        f'ale_2d_results_{model_name}_{target}_{time}{drop_opt}{resample_method}.nc'
    )

    print(f'Saving {results_fname}...')
    myInterpreter.save_results(fname=results_fname, data=results)

duration = datetime.datetime.now() - start_time
seconds = duration.total_seconds()
hours = seconds // 3600
                                         model_names=[model_name],
                                         examples=examples_transformed,
                                         targets=target_values_transformed,
                                         feature_names=feature_names)

        njobs = 1 if model_name == 'XGBoost' else len(important_vars)

        if normalize_method != None:
            unnormalize_func = UnNormalize(model.steps[1][1], feature_names)
        else:
            unnormalize_func = None

        result_dict = myInterpreter.calc_ale(
            features=important_vars,
            nbootstrap=100,
            subsample=1.0,
            njobs=njobs,
            nbins=30,
        )
        ale_results.append(result_dict)

    myInterpreter.model_names = model_set

    ale_results = merge_nested_dict(ale_results)
    myInterpreter.set_results(ale_results, option='ale')
    fig, axes = myInterpreter.plot_ale(
        display_feature_names=display_feature_names,
        to_probability=True,
        display_units=feature_units,
        title=
        f'{plt_config.title_dict[target]} {time.replace("_", " ").title()}',
        parameters['model_name'] = model_name
        calibrated_pipeline = _load_model(**parameters)
        model = calibrated_pipeline.calibrated_classifiers_[0].base_estimator

        examples_transformed, target_values_transformed = just_transforms(
            model, examples, target_values)
        myInterpreter = InterpretToolkit(model=[model.steps[-1][1]],
                                         model_names=[model_name],
                                         examples=examples_transformed,
                                         targets=target_values_transformed,
                                         feature_names=feature_names)

        result_dict = myInterpreter.calc_ale(
            features=feature_names,
            nbootstrap=1,
            subsample=0.6,
            njobs=40,
            nbins=30,
        )
        ale_std = []
        for f in feature_names:
            ale_std.append(np.std(result_dict[f][model_name]['values'],
                                  ddof=1))

        dropped_features = []
        idx = np.argsort(ale_std)[::-1]
        c = 0
        # Drop a feature if its std(ALE) is an order of magnitude
        # less than the max std(ALE)
        for i in idx:
            if c == 0: