Skip to content

Commit

Permalink
expose strategy param for calibration curve reiinakano#118
Browse files Browse the repository at this point in the history
  • Loading branch information
celik-muhammed committed Aug 16, 2024
1 parent ccb9969 commit 9111ce5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 15 deletions.
39 changes: 37 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,49 @@ Fixing a bug you found in Scikit-plot? Suggesting a feature? Adding your own plo

2. **Fork the repository**. If you're contributing code, clone the forked repository into your local machine.

- If you are a first-time contributor:
- Go to github and click the “fork” button to create your own copy of the project.
- Clone the project to your local computer:
```bash
git clone --recurse-submodules https://github.com/your-username/scikit-plot.git
```
- Now, `git remote -v` will show two remote repositories named:
- upstream, which refers to the scikit-plot repository
- origin, which refers to your personal fork
- Pull the latest changes from upstream, including tags:
```bash
git checkout main
git pull upstream main --tags
```
- Initialize submodules:
```bash
git submodule update --init
```
3. **Run the tests** to make sure they pass on your machine. Simply run `pytest` at the root folder and make sure all tests pass.

4. **Create a new branch**. Please do not commit directly to the master branch. Create your own branch and place your additions there.

5. **Write your code**. Please follow PEP8 coding standards. Also, if you're adding a function, you must [write a docstring using the Google format](http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html) detailing the API of your function. Take a look at the docstrings of the other Scikit-plot functions to get an idea of what the docstring of yours should look like.
- Develop your contribution:
- Create a branch for the feature you want to work on. Since the branch name will appear in the merge message, use a sensible name such as 'linspace-speedups':
```bash
git checkout -b linspace-speedups
```
5. **Write your code**. Please follow PEP8 coding standards. Also, if you're adding a function, you must currently [write a docstring using the Google format](http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html) detailing the API of your function or In Feature [NumPy docstring standard](https://numpy.org/devdocs/dev/howto-docs.html#howto-document). Take a look at the docstrings of the other Scikit-plot functions to get an idea of what the docstring of yours should look like.
- Commit locally as you progress (`git add` and `git commit`) Use a properly formatted commit message, write tests that fail before your change and pass afterward, run all the tests locally. Be sure to document any changed behavior in docstrings, keeping to the NumPy docstring [standard](https://numpy.org/devdocs/dev/howto-docs.html#howto-document).
6. **Write/modify the corresponding unit tests**. After adding in your code and the corresponding unit tests, run `pytest` again to make sure they pass.
7. **Submit a pull request**. After submitting a PR, if all tests pass, your code will be reviewed and merged promptly.
7. **Submit a pull request**. After submitting a PR (pull requests), if all tests pass, your code will be reviewed and merged promptly.
- To submit your contribution:
- Push your changes back to your fork on GitHub:
```bash
git push origin linspace-speedups
```
- Go to GitHub. The new branch will show up with a green Pull Request button. Make sure the title and message are clear, concise, and self- explanatory. Then click the button to submit it.
- If your commit introduces a new feature or changes functionality, post on the mailing list to explain your changes. For bug fixes, documentation updates, etc., this is generally not necessary, though if you do not get any reaction, do feel free to ask for review.
- Review process:
Thank you for taking the time to make Scikit-plot better!
17 changes: 12 additions & 5 deletions scikitplot/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,11 +906,11 @@ def plot_silhouette(X, cluster_labels, title='Silhouette Analysis',
return ax


def plot_calibration_curve(y_true, probas_list, clf_names=None, n_bins=10,
def plot_calibration_curve(y_true, probas_list, clf_names=None, n_bins=10,
title='Calibration plots (Reliability Curves)',
ax=None, figsize=None, cmap='nipy_spectral',
title_fontsize="large", text_fontsize="medium",
pos_label=None):
pos_label=None, strategy="uniform",):
"""Plots calibration curves for a set of classifier probability estimates.
Plotting the calibration curves of a classifier is useful for determining
Expand Down Expand Up @@ -964,6 +964,12 @@ def plot_calibration_curve(y_true, probas_list, clf_names=None, n_bins=10,
If `y_true` contains string labels or labels other than {0, 1} or {-1, 1},
you must specify this parameter explicitly.
strategy (str, optional): Strategy used to define the widths of the bins.
uniform
The bins have identical widths.
quantile
The bins have the same number of samples and depend on `y_prob`.
Returns:
:class:`matplotlib.axes.Axes`: The axes on which the plot was drawn.
Expand Down Expand Up @@ -1033,9 +1039,10 @@ def plot_calibration_curve(y_true, probas_list, clf_names=None, n_bins=10,

probas = (probas - probas.min()) / (probas.max() - probas.min())

fraction_of_positives, mean_predicted_value = \
calibration_curve(y_true, probas, n_bins=n_bins, pos_label=pos_label)

fraction_of_positives, mean_predicted_value = calibration_curve(
y_true, probas, n_bins=n_bins,
pos_label=pos_label, strategy=strategy
)
color = plt.cm.get_cmap(cmap)(float(i) / len(probas_list))

ax.plot(mean_predicted_value, fraction_of_positives, 's-',
Expand Down
29 changes: 21 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,43 @@ def get_version(rel_path):
long_description=README,
version=VERSION,
url='https://github.com/reiinakano/scikit-plot',
download_url='https://github.com/reiinakano/scikit-plot?tab=readme-ov-file#installation',
project_urls={
'Documentation': 'https://github.com/reiinakano/scikit-plot',
'Source Code': 'https://github.com/reiinakano/scikit-plot',
'Bug Tracker': 'https://github.com/reiinakano/scikit-plot/issues',
'Forum': '',
'Donate': '',
},
author='Reiichiro Nakano',
author_email='[email protected]',
license='MIT License',
install_requires=[
'matplotlib>=1.4.0',
'scikit-learn>=0.18',
'scikit-learn>=0.21',
'scipy>=0.9',
'joblib>=0.10'
],
# Supported Python versions
# python_requires=">=2.7",
classifiers = [
'Development Status :: 1 - Planning',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Operating System :: OS Independent',
'Intended Audience :: Science/Research',
'Intended Audience :: Developers',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.14',
'Topic :: Communications :: Email',
'Topic :: Documentation :: Sphinx',
'Topic :: Scientific/Engineering :: Visualization',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Topic :: Utilities',
],
packages=['scikitplot'],
include_package_data=True,
Expand Down

0 comments on commit 9111ce5

Please sign in to comment.