From 418388cab8132d292aea8548d3a83da28265484b Mon Sep 17 00:00:00 2001 From: Jannis Hoch <10956703+JannisHoch@users.noreply.github.com> Date: Wed, 15 Mar 2023 11:47:18 +0100 Subject: [PATCH] v0.1.2 (#162) * updated dependencies * correct dtype of list with selection conflict type * got rid of fiona requirement * improved downloading of example data * deprecated plotting for now as sklearn API has changed * v0.1.2 --- copro/__init__.py | 2 +- copro/plots.py | 7 +++++++ copro/scripts/copro_runner.py | 20 +++++++++++--------- copro/selection.py | 1 + environment.yml | 1 - example/_scripts/download_example_data.sh | 8 ++++---- setup.cfg | 2 +- setup.py | 12 +++++------- 8 files changed, 30 insertions(+), 23 deletions(-) diff --git a/copro/__init__.py b/copro/__init__.py index 6e49331..b936490 100644 --- a/copro/__init__.py +++ b/copro/__init__.py @@ -13,4 +13,4 @@ __author__ = """Jannis M. Hoch, Sophie de Bruin, Niko Wanders""" __email__ = 'j.m.hoch@uu.nl' -__version__ = '0.1.1' +__version__ = '0.1.2' diff --git a/copro/plots.py b/copro/plots.py index 0e82404..568a63b 100644 --- a/copro/plots.py +++ b/copro/plots.py @@ -101,8 +101,13 @@ def plot_ROC_curve_n_times(ax, clf, X_test, y_test, tprs, aucs, mean_fpr, **kwar list: lists with true positive rates and area-under-curve values per plot. """ + raise DeprecationWarning('Plotting API in sklearn is changed, function needs updating.') + viz = metrics.plot_roc_curve(clf, X_test, y_test, ax=ax, alpha=0.15, color='b', lw=1, label=None, **kwargs) + + # rfc_disp = metrics.RocCurveDisplay.from_estimator(clf, X_test, y_test, ax=ax, + # alpha=0.15, color='b', lw=1, label=None, **kwargs) interp_tpr = np.interp(mean_fpr, viz.fpr, viz.tpr) interp_tpr[0] = 0.0 @@ -121,6 +126,8 @@ def plot_ROC_curve_n_mean(ax, tprs, aucs, mean_fpr, **kwargs): mean_fpr (array): array with mean false positive rate. """ + raise DeprecationWarning('Plotting API in sklearn is changed, function needs updating.') + mean_tpr = np.mean(tprs, axis=0) mean_tpr[-1] = 1.0 mean_auc = metrics.auc(mean_fpr, mean_tpr) diff --git a/copro/scripts/copro_runner.py b/copro/scripts/copro_runner.py index d943e5d..559482e 100644 --- a/copro/scripts/copro_runner.py +++ b/copro/scripts/copro_runner.py @@ -90,16 +90,18 @@ def cli(cfg, make_plots=True, verbose=False): out_y_df = copro.evaluation.fill_out_df(out_y_df, y_df) out_dict = copro.evaluation.fill_out_dict(out_dict, eval_dict) + ## NOTE 15-Mar-2023: ROC plotting has been changed in sklearn, needs updating #- plot ROC curve per model execution - tprs, aucs = copro.plots.plot_ROC_curve_n_times(ax1, clf, X_df.to_numpy(), y_df.y_test.to_list(), - trps, aucs, mean_fpr) - - #- plot mean ROC curve - copro.plots.plot_ROC_curve_n_mean(ax1, tprs, aucs, mean_fpr) - #- save plot - plt.savefig(os.path.join(out_dir_REF, 'ROC_curve_per_run.png'), dpi=300, bbox_inches='tight') - #- save data for plot - copro.evaluation.save_out_ROC_curve(tprs, aucs, out_dir_REF) + # tprs, aucs = copro.plots.plot_ROC_curve_n_times(ax1, clf, X_df.to_numpy(), y_df.y_test.to_list(), + # trps, aucs, mean_fpr) + + ## NOTE 15-Mar-2023: ROC plotting has been changed in sklearn, needs updating + # #- plot mean ROC curve + # copro.plots.plot_ROC_curve_n_mean(ax1, tprs, aucs, mean_fpr) + # #- save plot + # plt.savefig(os.path.join(out_dir_REF, 'ROC_curve_per_run.png'), dpi=300, bbox_inches='tight') + # #- save data for plot + # copro.evaluation.save_out_ROC_curve(tprs, aucs, out_dir_REF) #- save output dictionary to csv-file copro.utils.save_to_csv(out_dict, out_dir_REF, 'evaluation_metrics') diff --git a/copro/selection.py b/copro/selection.py index e87f07d..e7018fc 100644 --- a/copro/selection.py +++ b/copro/selection.py @@ -37,6 +37,7 @@ def filter_conflict_properties(gdf, config): pass else: if config.getboolean('general', 'verbose'): print('DEBUG: filtering key', key, 'with value(s)', selection_criteria[key]) + selection_criteria[key] = [eval(i) for i in selection_criteria[key]] gdf = gdf[gdf[key].isin(selection_criteria[key])] return gdf diff --git a/environment.yml b/environment.yml index 7c9857d..e870d86 100644 --- a/environment.yml +++ b/environment.yml @@ -29,6 +29,5 @@ dependencies: - pillow==8.1.0 - geopandas>=0.8.0 - rasterio>=1.1.0 - - fiona - rasterstats>=0.14.0 diff --git a/example/_scripts/download_example_data.sh b/example/_scripts/download_example_data.sh index d7b5a96..ea61bbd 100644 --- a/example/_scripts/download_example_data.sh +++ b/example/_scripts/download_example_data.sh @@ -5,15 +5,15 @@ echo download zip-file # for WIN -curl https://zenodo.org/record/4617719/files/example_data.zip -o example_data.zip +#curl https://zenodo.org/record/4617719/files/example_data.zip -o example_data.zip # for UNIX -wget curl https://zenodo.org/record/4617719/files/example_data.zip +wget https://zenodo.org/record/4617719/files/example_data.zip echo unzip data unzip example_data.zip -d example_data echo copy data -cp example_data ../example_data +mv example_data/example_data ../example_data echo remove zip-file -rm example_data.zip \ No newline at end of file +rm -r example_data* diff --git a/setup.cfg b/setup.cfg index db83382..542bd2c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.1.1 +current_version = 0.1.2 commit = True tag = True diff --git a/setup.py b/setup.py index 9c03d54..8172c00 100644 --- a/setup.py +++ b/setup.py @@ -17,8 +17,7 @@ 'numpy>=1.21.0', 'scikit-learn>=0.22.1', 'seaborn>=0.11', - 'numpy>=1.21.0'] - + ] setup_requirements = ['pytest-runner', ] @@ -27,16 +26,15 @@ setup( author="Jannis M. Hoch", author_email='j.m.hoch@uu.nl', - python_requires='>=3.6', + python_requires='>=3.9', classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Natural Language :: English', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', ], description="Python-model build on scikit-learn functions, designed to facilitate the set-up, execution, and evaluation of machine-learning models for the study of the climate-conflict nexus.", entry_points={ @@ -55,6 +53,6 @@ test_suite='tests', tests_require=test_requirements, url='https://copro.readthedocs.io/', - version='0.1.1', + version='0.1.2', zip_safe=False, )