-
-
Notifications
You must be signed in to change notification settings - Fork 26.3k
FEA Add array API support for temperature scaling in CalibratedClassifierCV #32246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
OmarManzoor
wants to merge
17
commits into
scikit-learn:main
Choose a base branch
from
OmarManzoor:array-api-temperature-scaling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+268
−40
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
11aed7a
FEA Add array API support for TemperatureScaling in CalibratedClassif…
OmarManzoor 3fa226f
Merge branch 'main' into array-api-temperature-scaling
OmarManzoor 86fbfef
Minor fix
OmarManzoor ee42dce
Just add support for computing the multinomial loss and convert to fl…
OmarManzoor 0aed74d
Add benchmark for testing
OmarManzoor 892a3af
Update bench
OmarManzoor dc1bd35
Update bench
OmarManzoor 01347b0
Update bench
OmarManzoor 4cae31d
Update bench
OmarManzoor 7f92b99
Update the code to use a classifier which supports array API
OmarManzoor 3492934
Merge branch 'main' into array-api-temperature-scaling
OmarManzoor c57fef8
Some updates as suggested in the PR
OmarManzoor 3d5e5ad
Merge branch 'main' into array-api-temperature-scaling
OmarManzoor 87eb996
Update to utilize and also make some further adjustments in the array…
OmarManzoor cdd876e
Updates
OmarManzoor eb6ef7f
Fix sample_weight handling in HalfMultinomialLoss
OmarManzoor cc16f19
Some updates and changelog
OmarManzoor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Authors: The scikit-learn developers | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
from time import time | ||
|
||
import numpy as np | ||
import torch | ||
from tqdm import tqdm | ||
|
||
from sklearn.base import config_context | ||
from sklearn.calibration import _TemperatureScaling | ||
|
||
xp = torch | ||
device_ = "cuda" | ||
dtype_np = np.float64 | ||
dtype_xp = xp.float64 | ||
n_samples = 100000 | ||
n_classes = 300 | ||
|
||
|
||
execution_times = [] | ||
for _ in tqdm(range(10), desc="Numpy"): | ||
y = np.random.randint(0, n_classes, n_samples).astype(dtype_np) | ||
pred = np.random.rand(n_samples, n_classes).astype(dtype_np) | ||
start = time() | ||
cal = _TemperatureScaling() | ||
cal.fit(pred, y) | ||
execution_times.append(time() - start) | ||
|
||
avg_time = sum(execution_times) / 10 | ||
print(f"Avg execution_time for numpy: {avg_time}") | ||
|
||
execution_times = [] | ||
for _ in tqdm(range(10), desc=f"Torch {device_}"): | ||
y = xp.randint(0, n_classes, (n_samples,), dtype=dtype_xp, device=device_) | ||
pred = xp.rand((n_samples, n_classes), dtype=dtype_xp, device=device_) | ||
start = time() | ||
with config_context(array_api_dispatch=True): | ||
cal = _TemperatureScaling() | ||
cal.fit(pred, y) | ||
execution_times.append(time() - start) | ||
|
||
avg_time = sum(execution_times) / 10 | ||
print(f"Avg execution_time for torch {device_}: {avg_time}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- :class:`calibration.CalibratedClassifierCV` now supports array API compatible | ||
inputs with `method="temperature"` and when the underlying `estimator` also | ||
supports the array API. | ||
By :user:`Omar Salman <OmarManzoor>` |
2 changes: 1 addition & 1 deletion
2
doc/whats_new/upcoming_changes/sklearn.calibration/31068.feature.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
- Added temperature scaling method in :class:`caliabration.CalibratedClassifierCV`. | ||
- Added temperature scaling method in :class:`calibration.CalibratedClassifierCV`. | ||
By :user:`Virgil Chan <virchan>` and :user:`Christian Lorentzen <lorentzenchr>`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changelog check fails because of this.