Skip to content

Commit

Permalink
v0.1.2 (#162)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JannisHoch committed Mar 15, 2023
1 parent d833735 commit 418388c
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion copro/__init__.py
Expand Up @@ -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'
7 changes: 7 additions & 0 deletions copro/plots.py
Expand Up @@ -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
Expand All @@ -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)
Expand Down
20 changes: 11 additions & 9 deletions copro/scripts/copro_runner.py
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions copro/selection.py
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion environment.yml
Expand Up @@ -29,6 +29,5 @@ dependencies:
- pillow==8.1.0
- geopandas>=0.8.0
- rasterio>=1.1.0
- fiona
- rasterstats>=0.14.0

8 changes: 4 additions & 4 deletions example/_scripts/download_example_data.sh
Expand Up @@ -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
rm -r example_data*
2 changes: 1 addition & 1 deletion setup.cfg
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.1
current_version = 0.1.2
commit = True
tag = True

Expand Down
12 changes: 5 additions & 7 deletions setup.py
Expand Up @@ -17,8 +17,7 @@
'numpy>=1.21.0',
'scikit-learn>=0.22.1',
'seaborn>=0.11',
'numpy>=1.21.0']

]

setup_requirements = ['pytest-runner', ]

Expand All @@ -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={
Expand All @@ -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,
)

0 comments on commit 418388c

Please sign in to comment.