} #aupdc = make_scorer(score_func=average_precision_score, greater_is_better=True,needs_proba=True,) #results = permutation_importance(rf, X, y, scorer=aupdc, n_vars=10, n_jobs=50) from mintpy.mintpy.main.interpret_toolkit import InterpretToolkit myInterpreter = InterpretToolkit(model=[rf], model_names=['Random Forest'], examples=X, targets=y) start_time = datetime.datetime.now() results = myInterpreter.calc_permutation_importance(n_vars=10, evaluation_fn='auprc', subsample=1.0, njobs=50, nbootstrap=10) duration = datetime.datetime.now() - start_time seconds = duration.total_seconds() hours = seconds // 3600 minutes = (seconds % 3600) // 60 seconds = seconds % 60 message = f""" Duration : {hours:.2f} hours : {minutes:.2f} minutes : {seconds:.2f} seconds """ print(message)
# examples_transformed, target_values_transformed = rus.fit_resample(examples, target_values) # else: # examples_transformed = examples # target_values_transformed = target_values #else: # models=[model.steps[-1][1]] # examples_transformed, target_values_transformed = just_transforms(model, examples, target_values) # feature_names.remove('Run Date') myInterpreter = InterpretToolkit(models=models, model_names=model_names, examples=examples, targets=targets, ) results = myInterpreter.calc_permutation_importance(n_vars=n_vars, evaluation_fn=metric, subsample=subsample, n_jobs=njobs, n_bootstrap=nbootstrap, verbose=True, perm_method=method) results_fname = join(perm_imp_path, f'permutation_importance_{model_name}_{target}_{time}_{data_mode}_{metric}{drop_opt}{resample}{calibrate}{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 minutes = (seconds % 3600) // 60 seconds = seconds % 60 message = f""" {model_name} {target} {time} Permutation important results are done!