-
Notifications
You must be signed in to change notification settings - Fork 197
[ENH] EmpiricalFitter distribution fitter
#1095
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
Open
utsab345
wants to merge
7
commits into
sktime:main
Choose a base branch
from
utsab345:feature/empirical-fitter
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.
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9b4b32f
Add EmpiricalFitter distribution fitter
utsab345 627f800
Create distfitter.rst
fkiraly c27b026
Merge branch 'main' into pr/1095
fkiraly 0be9296
Merge branch 'main' into pr/1095
fkiraly 24a17e7
Fix EmpiricalFitter: flatten multi-column data to produce 0D distribu…
utsab345 7de6d08
Fix formatting: add blank line after module docstring per black
utsab345 5392088
[MNT] fix EmpiricalFitter per review: remove time_indep, fix authors
utsab345 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,47 @@ | ||
|
|
||
| .. _distfitter_ref: | ||
|
|
||
| Distribution fitters | ||
| ==================== | ||
|
|
||
| The :mod:`skpro.distfitter` module contains | ||
| distribution fitters which combine a ``pandas.DataFrame``-like API | ||
| with a ``scikit-base`` compatible object interface. | ||
|
|
||
| All distribution fitters in ``skpro`` can be listed using the ``skpro.registry.all_objects`` utility, | ||
| using ``object_types="distfitter"``, optionally filtered by tags. | ||
| Valid tags can be listed using ``skpro.registry.all_tags``. | ||
|
|
||
| Parametric fitters | ||
| ------------------ | ||
|
|
||
| .. currentmodule:: skpro.distfitter | ||
|
|
||
| .. autosummary:: | ||
| :toctree: auto_generated/ | ||
| :template: class.rst | ||
|
|
||
| MOMFitter | ||
| NormalFitter | ||
|
|
||
| Non-parametric fitters | ||
| ---------------------- | ||
|
|
||
| .. currentmodule:: skpro.distfitter | ||
|
|
||
| .. autosummary:: | ||
| :toctree: auto_generated/ | ||
| :template: class.rst | ||
|
|
||
| EmpiricalFitter | ||
|
|
||
| Base | ||
| ---- | ||
|
|
||
| .. currentmodule:: skpro.distfitter.base | ||
|
|
||
| .. autosummary:: | ||
| :toctree: auto_generated/ | ||
| :template: class.rst | ||
|
|
||
| BaseDistFitter |
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,10 +1,12 @@ | ||
| """Distribution fitter estimators.""" | ||
| # copyright: skpro developers, BSD-3-Clause License (see LICENSE file) | ||
|
|
||
| from skpro.distfitter._empiricalfitter import EmpiricalFitter | ||
| from skpro.distfitter._momfitter import MOMFitter | ||
| from skpro.distfitter._normalfitter import NormalFitter | ||
|
|
||
| __all__ = [ | ||
| "EmpiricalFitter", | ||
| "NormalFitter", | ||
| "MOMFitter", | ||
| ] |
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,99 @@ | ||
| """Empirical distribution fitter.""" | ||
| # copyright: skpro developers, BSD-3-Clause License (see LICENSE file) | ||
|
|
||
| from skpro.distfitter.base import BaseDistFitter | ||
|
|
||
|
|
||
| class EmpiricalFitter(BaseDistFitter): | ||
| """Fit an empirical distribution by wrapping data in an Empirical distribution. | ||
|
|
||
| Converts the full sample into an empirical distribution. | ||
| For the univariate case (empirical per variable), this simply wraps the | ||
| data in an ``Empirical`` distribution. | ||
|
|
||
| This is useful as a base component, e.g., for naive distribution fitting | ||
| in ensemble or reduction strategies. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| time_indep : bool, optional (default=True) | ||
| If True, the empirical distribution will sample individual instance | ||
| indices independently. If False, it will sample entire instances. | ||
| Passed through to ``Empirical``. | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> import pandas as pd | ||
| >>> from skpro.distfitter import EmpiricalFitter | ||
| >>> X = pd.DataFrame([1.0, 2.0, 3.0, 4.0, 5.0]) | ||
|
|
||
| >>> fitter = EmpiricalFitter() | ||
| >>> fitter.fit(X) | ||
| EmpiricalFitter() | ||
| >>> dist = fitter.proba() | ||
| """ | ||
|
|
||
| _tags = { | ||
| "authors": ["fkiraly"], | ||
| } | ||
|
|
||
| def __init__(self, time_indep=True): | ||
| self.time_indep = time_indep | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need for this as we are flattening the data so this time_indep is going to make no difference as there is going to be an single row |
||
|
|
||
| super().__init__() | ||
|
|
||
| def _fit(self, X, C=None): | ||
| """Fit empirical distribution by storing the data. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| X : pandas DataFrame | ||
| Data to fit the distribution to. | ||
| C : ignored | ||
|
|
||
| Returns | ||
| ------- | ||
| self : reference to self | ||
| """ | ||
| import pandas as pd | ||
|
|
||
| if X.shape[1] > 1: | ||
| n = len(X) | ||
| idx = pd.MultiIndex.from_arrays( | ||
| [range(n), [0] * n], names=["sample", None] | ||
| ) | ||
| spl = X.copy() | ||
| spl.index = idx | ||
| else: | ||
| spl = X | ||
| self.spl_ = spl | ||
| return self | ||
|
|
||
| def _proba(self): | ||
| """Return fitted Empirical distribution. | ||
|
|
||
| Returns | ||
| ------- | ||
| dist : skpro Empirical distribution (scalar) | ||
| """ | ||
| from skpro.distributions.empirical import Empirical | ||
|
|
||
| return Empirical(spl=self.spl_, time_indep=self.time_indep) | ||
|
|
||
| @classmethod | ||
| def get_test_params(cls, parameter_set="default"): | ||
| """Return testing parameter settings for the estimator. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| parameter_set : str, default="default" | ||
| Name of the set of test parameters to return. | ||
|
|
||
| Returns | ||
| ------- | ||
| params : dict or list of dict | ||
| Parameters to create testing instances of the class. | ||
| """ | ||
| params1 = {} | ||
| params2 = {"time_indep": False} | ||
| return [params1, params2] | ||
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.
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.
I think you are the author for this class