Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions docs/source/api_reference/distfitter.rst
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
2 changes: 2 additions & 0 deletions skpro/distfitter/__init__.py
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",
]
99 changes: 99 additions & 0 deletions skpro/distfitter/_empiricalfitter.py
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"],

Copy link
Copy Markdown
Member

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

}

def __init__(self, time_indep=True):
self.time_indep = time_indep

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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]