qolmat.imputations.imputers.ImputerInterpolation

class qolmat.imputations.imputers.ImputerInterpolation(groups: Tuple[str, ...] = (), method: str = 'linear', order: Optional[int] = None, col_time: Optional[str] = None)[source]

Interpolation imputer.

This class implements a way to impute time series using some interpolation strategies supported by pd.Series.interpolate, such as “linear”, “slinear”, “quadratic”, … By default, linear interpolation. As for pd.Series.interpolate, if “method” is “spline” or “polynomial”, an “order” has to be passed.

Parameters
groups: Tuple[str, …]

List of column names to group by, by default []

methodOptional[str] = “linear”

name of the method for interpolation: “linear”, “cubic”, “spline”, “slinear”, … see pd.Series.interpolate for more example. By default, the value is set to “linear”.

orderOptional[int]

order for the spline interpolation

col_timeOptional[str]

Name of the column representing the time index to use for the interpolation. If None, the index is used assuming it is one-dimensional.

Examples

>>> import numpy as np
>>> import pandas as pd
>>> from qolmat.imputations import imputers
>>> imputer = imputers.ImputerInterpolation(method="spline", order=2)
>>> df = pd.DataFrame(
...     data=[
...         [1, 1, 1, 1],
...         [np.nan, np.nan, np.nan, np.nan],
...         [1, 2, 2, 5],
...         [2, 2, 2, 2],
...     ],
...     columns=["var1", "var2", "var3", "var4"],
... )
>>> imputer.fit_transform(df)
       var1      var2      var3      var4
0  1.000000  1.000000  1.000000  1.000000
1  0.666667  1.666667  1.666667  4.666667
2  1.000000  2.000000  2.000000  5.000000
3  2.000000  2.000000  2.000000  2.000000
__init__(groups: Tuple[str, ...] = (), method: str = 'linear', order: Optional[int] = None, col_time: Optional[str] = None) None[source]

Examples using qolmat.imputations.imputers.ImputerInterpolation

Benchmark for time series

Benchmark for time series