API Reference

Core Modules

Core base classes, tags, and validation for time series estimators.

class timesmith.core.BaseDetector[source]

Bases: BaseEstimator

Base class for anomaly detectors.

Detectors identify anomalies in time series.

predict(y, X=None, threshold=None)[source]

Predict anomaly flags.

Parameters:
  • y (Any) – Target data.

  • X (Optional[Any]) – Optional exogenous/feature data.

  • threshold (Optional[float]) – Optional threshold for binary classification.

Return type:

Any

Returns:

Anomaly flags (boolean array or similar).

score(y, X=None)[source]

Compute anomaly scores.

Parameters:
  • y (Any) – Target data.

  • X (Optional[Any]) – Optional exogenous/feature data.

Return type:

Any

Returns:

Anomaly scores.

class timesmith.core.BaseEstimator[source]

Bases: BaseObject

Base class for all estimators with fit capability.

Adds fitted state management to BaseObject.

__init__()[source]

Initialize the estimator.

fit(y, X=None, **fit_params)[source]

Fit the estimator to data.

Parameters:
  • y (Any) – Target data.

  • X (Optional[Any]) – Optional exogenous/feature data.

  • **fit_params (Any) – Additional fit parameters.

Return type:

BaseEstimator

Returns:

Self for method chaining.

property is_fitted: bool

Check if the estimator has been fitted.

Returns:

True if fitted, False otherwise.

class timesmith.core.BaseFeaturizer[source]

Bases: BaseTransformer

Base class for featurizers.

Featurizers are transformers that output TableLike data.

transform(y, X=None)[source]

Transform data to table format.

Parameters:
  • y (Union[SeriesLike, Any]) – Target data to transform (SeriesLike).

  • X (Union[TableLike, Any, None]) – Optional exogenous/feature data (TableLike).

Return type:

TableLike

Returns:

TableLike data (DataFrame with time-aligned rows).

class timesmith.core.BaseForecaster[source]

Bases: BaseEstimator

Base class for forecasters.

Forecasters predict future values of time series.

predict(fh, X=None, **predict_params)[source]

Make forecasts.

Parameters:
  • fh (Any) – Forecast horizon (can be integer, array, or other format).

  • X (Optional[Any]) – Optional exogenous/feature data for the forecast horizon.

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Any

Returns:

Forecast results (ForecastLike).

predict_interval(fh, X=None, coverage=0.9, **predict_params)[source]

Make forecasts with prediction intervals.

Parameters:
  • fh (Any) – Forecast horizon.

  • X (Optional[Any]) – Optional exogenous/feature data for the forecast horizon.

  • coverage (float) – Coverage level for prediction intervals (e.g., 0.9 for 90%).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Any

Returns:

Forecast results with intervals (ForecastLike with y_int).

class timesmith.core.BaseObject[source]

Bases: object

Base class for all time series objects with parameter management.

Provides get_params, set_params, clone, and __repr__ methods.

clone()[source]

Create a deep copy of this object.

Return type:

BaseObject

Returns:

A new instance with the same parameters.

get_params(deep=True)[source]

Get parameters for this object.

Parameters:

deep (bool) – If True, will return the parameters of this object and contained subobjects that are estimators.

Return type:

Dict[str, Any]

Returns:

Parameter names mapped to their values.

set_params(**params)[source]

Set the parameters of this object.

Parameters:

**params (Any) – Parameter names mapped to their values.

Return type:

BaseObject

Returns:

Self for method chaining.

Raises:

ValueError – If parameter name is invalid or is a private attribute.

class timesmith.core.BaseTransformer[source]

Bases: BaseEstimator

Base class for transformers.

Transformers modify data but don’t predict future values.

fit_transform(y, X=None, **fit_params)[source]

Fit the transformer and transform the data.

Parameters:
  • y (Union[SeriesLike, Any]) – Target data.

  • X (Union[TableLike, Any, None]) – Optional exogenous/feature data.

  • **fit_params (Any) – Additional fit parameters.

Return type:

Union[SeriesLike, Any]

Returns:

Transformed data.

inverse_transform(y, X=None)[source]

Inverse transform the data.

Parameters:
  • y (Union[SeriesLike, Any]) – Transformed data to inverse transform (SeriesLike).

  • X (Union[TableLike, Any, None]) – Optional exogenous/feature data (TableLike).

Return type:

Union[SeriesLike, Any]

Returns:

Inverse transformed data (SeriesLike).

transform(y, X=None)[source]

Transform the data.

Parameters:
  • y (Union[SeriesLike, Any]) – Target data to transform (SeriesLike).

  • X (Union[TableLike, Any, None]) – Optional exogenous/feature data (TableLike).

Return type:

Union[SeriesLike, Any]

Returns:

Transformed data (SeriesLike).

class timesmith.core.BayesianChangePointDetector(expected_segment_length=100.0, threshold=0.5, preprocess=True)[source]

Bases: BaseDetector

Change point detector using Bayesian online change-point detection.

__init__(expected_segment_length=100.0, threshold=0.5, preprocess=True)[source]

Initialize Bayesian change point detector.

Parameters:
  • expected_segment_length (float) – Expected length between change points.

  • threshold (float) – Probability threshold for flagging change points (0-1).

  • preprocess (bool) – Whether to preprocess data before detection.

fit(y, X=None, **fit_params)[source]

Fit the change point detector.

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

BayesianChangePointDetector

Returns:

Self for method chaining.

predict(y, X=None, threshold=None)[source]

Predict change point flags.

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • threshold (Optional[float]) – Optional threshold (uses self.threshold if not provided).

Return type:

ndarray

Returns:

Boolean array with True at change points.

score(y, X=None)[source]

Compute change point probabilities.

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

ndarray

Returns:

Array of change point probabilities at each time step.

class timesmith.core.ButterworthFilter(cutoff_freq=0.1, filter_order=4, btype='low')[source]

Bases: BaseTransformer

Butterworth low-pass filter transformer.

__init__(cutoff_freq=0.1, filter_order=4, btype='low')[source]

Initialize Butterworth filter.

Parameters:
  • cutoff_freq (float) – Cutoff frequency (normalized, 0-0.5).

  • filter_order (int) – Filter order.

  • btype (str) – Filter type: ‘low’, ‘high’, ‘band’, ‘bandstop’.

fit(y, X=None, **fit_params)[source]

Fit the filter (no-op, but required by interface).

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

ButterworthFilter

Returns:

Self for method chaining.

transform(y, X=None)[source]

Apply Butterworth filter to time series.

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

Series

Returns:

Filtered series.

class timesmith.core.CUSUMDetector(baseline_window=10, threshold=3.0)[source]

Bases: BaseDetector

Change point detector using CUSUM (Cumulative Sum) method.

CUSUM detects changes by tracking cumulative deviations from a baseline. Detects change points by looking for significant shifts in the rate values.

__init__(baseline_window=10, threshold=3.0)[source]

Initialize CUSUM detector.

Parameters:
  • baseline_window (int) – Window size for detecting changes.

  • threshold (float) – Z-score threshold for change detection (lower = more sensitive).

fit(y, X=None, **fit_params)[source]

Fit the change point detector.

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

CUSUMDetector

Returns:

Self for method chaining.

predict(y, X=None, threshold=None)[source]

Predict change point flags (binary array).

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • threshold (Optional[float]) – Optional threshold (ignored for CUSUM, uses self.threshold).

Return type:

ndarray

Returns:

Boolean array with True at change points.

score(y, X=None)[source]

Compute change point scores (indices of detected change points).

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

ndarray

Returns:

Array of change point indices.

class timesmith.core.DecomposeTransformer(method='moving_average', seasonal_period=None, trend_window=None)[source]

Bases: BaseTransformer

Decompose time series into trend, seasonal, and residual components.

__init__(method='moving_average', seasonal_period=None, trend_window=None)[source]

Initialize decomposition transformer.

Parameters:
  • method (str) – Decomposition method: ‘moving_average’ or ‘stl’.

  • seasonal_period (Optional[int]) – Seasonal period (auto-detected if not specified).

  • trend_window (Optional[int]) – Window size for trend extraction (auto-determined if not specified).

fit(y, X=None, **fit_params)[source]

Fit the decomposition transformer.

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

DecomposeTransformer

Returns:

Self for method chaining.

get_components()[source]

Get decomposition components.

Return type:

Dict[str, ndarray]

Returns:

Dictionary with ‘trend’, ‘seasonal’, ‘residual’, and ‘original’ components.

inverse_transform(y, X=None)[source]

Reconstruct original from residual by adding trend and seasonal.

Parameters:
  • y (Any) – Residual component.

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

Series

Returns:

Reconstructed original series.

transform(y, X=None)[source]

Return residual component (original - trend - seasonal).

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

Series

Returns:

Residual component as Series.

class timesmith.core.DegradationRateFeaturizer(periods=[1, 3, 5])[source]

Bases: BaseFeaturizer

Create degradation rate features (rate of change) from time series.

Transforms SeriesLike to TableLike by creating percentage change features.

__init__(periods=[1, 3, 5])[source]

Initialize degradation rate featurizer.

Parameters:

periods (List[int]) – List of periods for rate of change calculation.

fit(y, X=None, **fit_params)[source]

Fit the featurizer (no-op for degradation rates).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

DegradationRateFeaturizer

Returns:

Self for method chaining.

transform(y, X=None)[source]

Create degradation rate features.

Parameters:
  • y (Any) – SeriesLike data.

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

DataFrame

Returns:

TableLike DataFrame with degradation rate features.

class timesmith.core.DeseasonalizeTransformer(seasonal_period=None, max_period=50)[source]

Bases: BaseTransformer

Remove seasonality from time series.

__init__(seasonal_period=None, max_period=50)[source]

Initialize deseasonalize transformer.

Parameters:
  • seasonal_period (Optional[int]) – Seasonal period (auto-detected if not specified).

  • max_period (int) – Maximum period to check for auto-detection.

fit(y, X=None, **fit_params)[source]

Fit the deseasonalize transformer.

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

DeseasonalizeTransformer

Returns:

Self for method chaining.

inverse_transform(y, X=None)[source]

Add seasonality back to deseasonalized series.

Parameters:
  • y (Any) – Deseasonalized series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

Series

Returns:

Series with seasonality restored.

transform(y, X=None)[source]

Remove seasonality from time series.

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

Series

Returns:

Deseasonalized series.

class timesmith.core.DetrendTransformer(method='linear')[source]

Bases: BaseTransformer

Remove trend from time series.

__init__(method='linear')[source]

Initialize detrend transformer.

Parameters:

method (str) – Trend removal method: ‘linear’, ‘polynomial’, or ‘moving_average’.

fit(y, X=None, **fit_params)[source]

Fit the detrend transformer.

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

DetrendTransformer

Returns:

Self for method chaining.

inverse_transform(y, X=None)[source]

Add trend back to detrended series.

Parameters:
  • y (Any) – Detrended series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

Series

Returns:

Series with trend restored.

transform(y, X=None)[source]

Remove trend from time series.

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

Series

Returns:

Detrended series.

class timesmith.core.DifferencingFeaturizer(orders=[1])[source]

Bases: BaseFeaturizer

Create differenced features from time series.

Transforms SeriesLike to TableLike by creating differenced features.

__init__(orders=[1])[source]

Initialize differencing featurizer.

Parameters:

orders (List[int]) – List of differencing orders (e.g., [1] for first difference).

fit(y, X=None, **fit_params)[source]

Fit the featurizer (no-op for differencing).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

DifferencingFeaturizer

Returns:

Self for method chaining.

transform(y, X=None)[source]

Create differenced features.

Parameters:
  • y (Any) – SeriesLike data.

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

DataFrame

Returns:

TableLike DataFrame with differenced features.

class timesmith.core.HampelOutlierRemover(window=10, n_sigma=3.0)[source]

Bases: BaseTransformer

Remove outliers using Hampel filter (MAD-based).

Hampel filter uses median absolute deviation (MAD) to detect outliers relative to a rolling median baseline. More robust than Z-score methods.

__init__(window=10, n_sigma=3.0)[source]

Initialize Hampel outlier remover.

Parameters:
  • window (int) – Window size for rolling median.

  • n_sigma (float) – Number of standard deviations for threshold.

fit(y, X=None, **fit_params)[source]

Fit the transformer (computes outlier mask).

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

HampelOutlierRemover

Returns:

Self for method chaining.

transform(y, X=None)[source]

Remove outliers.

Parameters:
  • y (Any) – SeriesLike data (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

Series

Returns:

SeriesLike data with outliers removed.

class timesmith.core.IsolationForestOutlierRemover(contamination=0.1, random_state=None, window=10)[source]

Bases: BaseTransformer

Remove outliers using IsolationForest.

Uses feature set: rate, delta rate, rolling median residual.

__init__(contamination=0.1, random_state=None, window=10)[source]

Initialize IsolationForest outlier remover.

Parameters:
  • contamination (float) – Expected proportion of outliers.

  • random_state (Optional[int]) – Random seed for reproducibility.

  • window (int) – Window size for rolling median feature.

fit(y, X=None, **fit_params)[source]

Fit the transformer (trains IsolationForest).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

IsolationForestOutlierRemover

Returns:

Self for method chaining.

transform(y, X=None)[source]

Remove outliers.

Parameters:
  • y (Any) – SeriesLike data (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

Series

Returns:

SeriesLike data with outliers removed.

class timesmith.core.LagFeaturizer(lags=[1, 2, 3, 7, 14], include_diff=False, include_pct_change=False, seasonal_lags=None, prevent_leads=True)[source]

Bases: BaseFeaturizer

Create lagged features from time series.

Transforms SeriesLike to TableLike by creating lag features. Supports automatic lead prevention, differences, percentage changes, and seasonal lags.

__init__(lags=[1, 2, 3, 7, 14], include_diff=False, include_pct_change=False, seasonal_lags=None, prevent_leads=True)[source]

Initialize lag featurizer.

Parameters:
  • lags (List[int]) – List of lag periods to create.

  • include_diff (bool) – If True, include differenced features (lag differences).

  • include_pct_change (bool) – If True, include percentage change features.

  • seasonal_lags (Optional[List[int]]) – Optional list of seasonal lag periods (e.g., [12, 24] for monthly).

  • prevent_leads (bool) – If True, ensures no future data leakage (only positive lags).

fit(y, X=None, **fit_params)[source]

Fit the featurizer (no-op for lags).

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

LagFeaturizer

Returns:

Self for method chaining.

transform(y, X=None)[source]

Create lag features using vectorized NumPy operations.

Parameters:
  • y (Any) – SeriesLike data.

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

DataFrame

Returns:

TableLike DataFrame with lag features.

class timesmith.core.MissingDateFiller(method='forward')[source]

Bases: BaseTransformer

Fill missing dates in time series.

Transforms SeriesLike by adding missing dates and filling values.

__init__(method='forward')[source]

Initialize missing date filler.

Parameters:

method (str) – Fill method (‘forward’, ‘backward’, ‘interpolate’).

fit(y, X=None, **fit_params)[source]

Fit the transformer (detects frequency).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

MissingDateFiller

Returns:

Self for method chaining.

transform(y, X=None)[source]

Fill missing dates.

Parameters:
  • y (Union[SeriesLike, Any]) – SeriesLike data.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

Return type:

Union[SeriesLike, Any]

Returns:

SeriesLike data with missing dates filled.

class timesmith.core.MissingValueFiller(method='forward')[source]

Bases: BaseTransformer

Fill missing values in time series.

Transforms SeriesLike by filling missing values.

__init__(method='forward')[source]

Initialize missing value filler.

Parameters:

method (str) – Fill method (‘forward’, ‘backward’, ‘interpolate’).

fit(y, X=None, **fit_params)[source]

Fit the transformer (no-op for filling).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

MissingValueFiller

Returns:

Self for method chaining.

transform(y, X=None)[source]

Fill missing values.

Parameters:
  • y (Union[SeriesLike, Any]) – SeriesLike data.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

Return type:

Union[SeriesLike, Any]

Returns:

SeriesLike data with missing values filled.

class timesmith.core.OutlierRemover(factor=1.5)[source]

Bases: BaseTransformer

Remove outliers using IQR method.

Transforms SeriesLike by removing outliers.

__init__(factor=1.5)[source]

Initialize outlier remover.

Parameters:

factor (float) – IQR factor for outlier detection (default: 1.5).

fit(y, X=None, **fit_params)[source]

Fit the transformer (computes IQR bounds).

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

OutlierRemover

Returns:

Self for method chaining.

transform(y, X=None)[source]

Remove outliers.

Parameters:
  • y (Union[SeriesLike, Any]) – SeriesLike data.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

Return type:

Union[SeriesLike, Any]

Returns:

SeriesLike data with outliers removed.

class timesmith.core.PELTDetector(penalty=None, model='l2', min_size=3, jump=1, preprocess=True)[source]

Bases: BaseDetector

Change point detector using PELT (Pruned Exact Linear Time) algorithm.

__init__(penalty=None, model='l2', min_size=3, jump=1, preprocess=True)[source]

Initialize PELT detector.

Parameters:
  • penalty (Optional[float]) – Penalty value (higher = fewer change points). Auto-tuned if None.

  • model (str) – Cost function model (‘l2’ for mean shift, ‘rbf’ for distributional change).

  • min_size (int) – Minimum segment length.

  • jump (int) – Subsample (1 = no subsampling).

  • preprocess (bool) – Whether to preprocess data before detection.

fit(y, X=None, **fit_params)[source]

Fit the change point detector.

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

PELTDetector

Returns:

Self for method chaining.

predict(y, X=None, threshold=None)[source]

Predict change point flags (binary array).

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • threshold (Optional[float]) – Optional threshold (ignored for PELT, uses penalty instead).

Return type:

ndarray

Returns:

Boolean array with True at change points.

score(y, X=None)[source]

Compute change point scores (indices of detected change points).

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

ndarray

Returns:

Array of change point indices.

class timesmith.core.Resampler(freq='D', method='mean')[source]

Bases: BaseTransformer

Resample time series to different frequency.

Transforms SeriesLike by resampling to target frequency.

__init__(freq='D', method='mean')[source]

Initialize resampler.

Parameters:
  • freq (str) – Target frequency (e.g., ‘D’, ‘W’, ‘M’, ‘H’).

  • method (str) – Aggregation method (‘mean’, ‘sum’, ‘last’, ‘first’).

fit(y, X=None, **fit_params)[source]

Fit the transformer (no-op for resampling).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

Resampler

Returns:

Self for method chaining.

transform(y, X=None)[source]

Resample time series.

Parameters:
  • y (Union[SeriesLike, Any]) – SeriesLike data.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

Return type:

Union[SeriesLike, Any]

Returns:

Resampled SeriesLike data.

class timesmith.core.RollingFeaturizer(windows=[7, 14, 30], functions=['mean', 'std'], n_jobs=None)[source]

Bases: BaseFeaturizer

Create rolling window features from time series.

Transforms SeriesLike to TableLike by creating rolling statistics.

__init__(windows=[7, 14, 30], functions=['mean', 'std'], n_jobs=None)[source]

Initialize rolling featurizer.

Parameters:
  • windows (List[int]) – List of window sizes.

  • functions (List[str]) – List of functions to apply (‘mean’, ‘std’, ‘min’, ‘max’, ‘median’).

  • n_jobs (Optional[int]) – Number of parallel jobs for computing statistics. None uses all CPUs.

fit(y, X=None, **fit_params)[source]

Fit the featurizer (no-op for rolling features).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

RollingFeaturizer

Returns:

Self for method chaining.

transform(y, X=None)[source]

Create rolling features using optimized NumPy vectorized operations.

Parameters:
  • y (Any) – SeriesLike data.

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

DataFrame

Returns:

TableLike DataFrame with rolling features.

class timesmith.core.SavitzkyGolayFilter(window_length=5, polyorder=2)[source]

Bases: BaseTransformer

Savitzky-Golay filter transformer for smoothing.

__init__(window_length=5, polyorder=2)[source]

Initialize Savitzky-Golay filter.

Parameters:
  • window_length (int) – Window length (must be odd).

  • polyorder (int) – Polynomial order.

fit(y, X=None, **fit_params)[source]

Fit the filter (no-op, but required by interface).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

SavitzkyGolayFilter

Returns:

Self for method chaining.

transform(y, X=None)[source]

Apply Savitzky-Golay filter to time series.

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

Series

Returns:

Filtered series.

class timesmith.core.SeasonalBaselineDetector(seasonality='week', threshold_sigma=2.5)[source]

Bases: BaseDetector

Seasonal baseline anomaly detector for time series.

Calculates seasonal baselines (e.g., weekly, monthly) and flags points that deviate significantly from expected seasonal patterns.

__init__(seasonality='week', threshold_sigma=2.5)[source]

Initialize seasonal baseline detector.

Parameters:
  • seasonality (str) – Seasonality to use. Options: ‘week’, ‘month’, ‘day’, ‘hour’.

  • threshold_sigma (float) – Number of standard deviations for threshold.

fit(y, X=None, **fit_params)[source]

Fit the detector by computing seasonal baselines.

Parameters:
  • y (Any) – Target time series with datetime index.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

SeasonalBaselineDetector

Returns:

Self for method chaining.

predict(y, X=None, threshold=None)[source]

Predict anomaly flags.

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • threshold (Optional[float]) – Optional threshold (uses self.threshold_sigma if not provided).

Return type:

ndarray

Returns:

Boolean array with True at anomalies.

score(y, X=None)[source]

Compute Z-scores relative to seasonal baseline.

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

ndarray

Returns:

Array of Z-scores relative to seasonal baseline.

class timesmith.core.SeasonalFeaturizer(seasonal_periods)[source]

Bases: BaseFeaturizer

Create seasonal features using sine/cosine transformations.

Transforms SeriesLike to TableLike by creating seasonal sine/cosine features.

__init__(seasonal_periods)[source]

Initialize seasonal featurizer.

Parameters:
  • seasonal_periods (List[int]) – List of seasonal periods (e.g., [12, 365] for monthly/yearly).

  • seasonal_periods – List of seasonal periods (e.g., [12, 365] for monthly/yearly).

fit(y, X=None, **fit_params)[source]

Fit the featurizer (no-op for seasonal features).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

SeasonalFeaturizer

Returns:

Self for method chaining.

transform(y, X=None)[source]

Create seasonal features.

Parameters:
  • y (Any) – SeriesLike data.

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

DataFrame

Returns:

TableLike DataFrame with seasonal features.

class timesmith.core.TimeFeaturizer[source]

Bases: BaseFeaturizer

Create time-based features from datetime index.

Transforms SeriesLike to TableLike by extracting time features.

__init__()[source]

Initialize time featurizer.

fit(y, X=None, **fit_params)[source]

Fit the featurizer (no-op for time features).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

TimeFeaturizer

Returns:

Self for method chaining.

transform(y, X=None)[source]

Create time features.

Parameters:
  • y (Any) – SeriesLike data with datetime index.

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

DataFrame

Returns:

TableLike DataFrame with time features.

class timesmith.core.VotingEnsembleDetector(detectors, threshold=2)[source]

Bases: BaseDetector

Voting ensemble for anomaly detection.

Combines multiple anomaly detectors using majority voting. Flags a point as anomalous if at least threshold detectors agree.

__init__(detectors, threshold=2)[source]

Initialize voting ensemble detector.

Parameters:
  • detectors (List[BaseDetector]) – List of BaseDetector instances to ensemble.

  • threshold (int) – Minimum number of detectors that must flag an anomaly.

fit(y, X=None, **fit_params)[source]

Fit all detectors in the ensemble.

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data.

  • **fit_params (Any) – Additional fit parameters.

Return type:

VotingEnsembleDetector

Returns:

Self for method chaining.

predict(y, X=None, threshold=None)[source]

Predict anomaly flags using majority voting.

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data.

  • threshold (Optional[int]) – Optional threshold (uses self.threshold if not provided).

Return type:

ndarray

Returns:

Boolean array with True at anomalies.

score(y, X=None)[source]

Compute ensemble anomaly scores (number of detectors flagging each point).

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data.

Return type:

ndarray

Returns:

Array of scores (number of detectors flagging each point, 0 to n_detectors).

class timesmith.core.WaveletDenoiser(wavelet='db4', threshold_mode='soft', level=5)[source]

Bases: BaseTransformer

Wavelet-based signal denoising transformer.

Uses wavelet thresholding to remove noise from time series signals.

__init__(wavelet='db4', threshold_mode='soft', level=5)[source]

Initialize wavelet denoiser.

Parameters:
  • wavelet (str) – Wavelet type (e.g., ‘db4’, ‘haar’, ‘bior2.2’).

  • threshold_mode (str) – Thresholding mode (‘soft’ or ‘hard’).

  • level (int) – Decomposition level.

fit(y, X=None, **fit_params)[source]

Fit the transformer (no-op, but required by interface).

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

WaveletDenoiser

Returns:

Self for method chaining.

transform(y, X=None)[source]

Denoise time series using wavelet thresholding.

Parameters:
  • y (Any) – SeriesLike data (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

Series

Returns:

Denoised SeriesLike data.

class timesmith.core.WaveletDetector(wavelet='db4', threshold_factor=3.0, level=5)[source]

Bases: BaseDetector

Wavelet-based anomaly detector for time series.

Detects anomalies by identifying large coefficients in wavelet detail levels, which indicate sudden changes or anomalies.

__init__(wavelet='db4', threshold_factor=3.0, level=5)[source]

Initialize wavelet detector.

Parameters:
  • wavelet (str) – Wavelet type (e.g., ‘db4’, ‘haar’, ‘bior2.2’).

  • threshold_factor (float) – Threshold factor for anomaly detection (in terms of MAD).

  • level (int) – Decomposition level.

fit(y, X=None, **fit_params)[source]

Fit the detector.

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

WaveletDetector

Returns:

Self for method chaining.

get_wavelet_coefficients(y)[source]

Get wavelet decomposition coefficients.

Parameters:

y (Any) – Time series data (should match fit data).

Return type:

Tuple[ndarray, list]

Returns:

Tuple of (approximation, details).

predict(y, X=None, threshold=None)[source]

Predict anomaly flags.

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • threshold (Optional[float]) – Optional threshold (uses percentile if not provided).

Return type:

ndarray

Returns:

Boolean array with True at anomalies.

score(y, X=None)[source]

Compute anomaly scores using wavelet decomposition.

Parameters:
  • y (Any) – Target time series (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

ndarray

Returns:

Array of anomaly scores.

class timesmith.core.ZScoreOutlierRemover(window=10, z_threshold=3.0, use_log=True)[source]

Bases: BaseTransformer

Remove outliers using Z-score on log residual.

Better for multiplicative errors than linear Z-score.

__init__(window=10, z_threshold=3.0, use_log=True)[source]

Initialize Z-score outlier remover.

Parameters:
  • window (int) – Window size for rolling median baseline.

  • z_threshold (float) – Z-score threshold.

  • use_log (bool) – If True, use log residual (better for multiplicative errors).

fit(y, X=None, **fit_params)[source]

Fit the transformer (computes outlier mask).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

ZScoreOutlierRemover

Returns:

Self for method chaining.

transform(y, X=None)[source]

Remove outliers.

Parameters:
  • y (Any) – SeriesLike data (should match fit data).

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

Series

Returns:

SeriesLike data with outliers removed.

timesmith.core.detect_seasonality(y, max_period=50)[source]

Detect seasonality in time series data.

Parameters:
  • y (SeriesLike) – Time series values.

  • max_period (int) – Maximum period to check.

Return type:

Dict[str, Any]

Returns:

Dictionary with seasonality information.

timesmith.core.detect_trend(y, method='linear')[source]

Detect trend in time series data.

Parameters:
  • y (SeriesLike) – Time series values.

  • method (str) – Trend detection method: ‘linear’, ‘polynomial’, or ‘moving_average’.

Return type:

Dict[str, Any]

Returns:

Dictionary with trend information.

timesmith.core.get_tags(obj, tag=None)[source]

Get tags from an object.

Parameters:
  • obj (Any) – Object to get tags from.

  • tag (Optional[str]) – Optional specific tag name to retrieve. If None, returns all tags.

Return type:

Dict[str, Any]

Returns:

Dictionary of tags, or single tag value if tag name specified.

timesmith.core.preprocess_for_changepoint(y, median_window=5, detrend_window=100)[source]

Preprocess time series for change point detection.

Applies median filtering to remove spikes and baseline removal to eliminate drift.

Parameters:
  • y (SeriesLike) – Time series values.

  • median_window (int) – Window size for spike removal.

  • detrend_window (int) – Window size for baseline removal (0 to skip).

Return type:

ndarray

Returns:

Preprocessed time series.

timesmith.core.set_tags(obj, **tags)[source]

Set tags on an object.

Parameters:
  • obj (Any) – Object to set tags on.

  • **tags (Any) – Tag names and values to set.

Return type:

None

timesmith.core.validate_input(data, scitype, name='data', allow_none=False)[source]

Validate input data matches expected scitype.

Parameters:
  • data (Any) – Data to validate.

  • scitype (str) – Expected scitype (“SeriesLike”, “PanelLike”, or “TableLike”).

  • name (str) – Name of the variable for error messages.

  • allow_none (bool) – If True, None values are allowed.

Raises:
  • TypeError – If data doesn’t match expected scitype.

  • ValueError – If data is None and allow_none is False.

Return type:

None

Forecasters

Forecaster implementations for time series forecasting.

class timesmith.forecasters.ARIMAForecaster(start_p=0, start_q=0, max_p=5, max_q=5, seasonal=False, stepwise=True, suppress_warnings=True, error_action='ignore', **kwargs)[source]

Bases: BaseForecaster

ARIMA forecaster using auto_arima for automatic order selection.

Wraps pmdarima.auto_arima to provide a BaseForecaster interface.

__init__(start_p=0, start_q=0, max_p=5, max_q=5, seasonal=False, stepwise=True, suppress_warnings=True, error_action='ignore', **kwargs)[source]

Initialize ARIMA forecaster.

Parameters:
  • start_p (int) – Starting value for p parameter.

  • start_q (int) – Starting value for q parameter.

  • max_p (int) – Maximum value for p parameter.

  • max_q (int) – Maximum value for q parameter.

  • seasonal (bool) – Whether to include seasonal component.

  • stepwise (bool) – Whether to use stepwise selection.

  • suppress_warnings (bool) – Whether to suppress warnings.

  • error_action (str) – Action on error (‘ignore’, ‘warn’, ‘raise’).

  • **kwargs – Additional arguments passed to auto_arima.

fit(y, X=None, **fit_params)[source]

Fit ARIMA model to time series.

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (not yet supported).

  • **fit_params (Any) – Additional fit parameters.

Return type:

ARIMAForecaster

Returns:

Self for method chaining.

get_order()[source]

Get ARIMA order (p, d, q).

Return type:

tuple

Returns:

Tuple of (p, d, q) order.

predict(fh, X=None, **predict_params)[source]

Generate forecast.

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon (integer or array).

  • X (Union[TableLike, Any, None]) – Optional exogenous data (not yet supported).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast object with predictions.

predict_interval(fh, X=None, coverage=0.9, **predict_params)[source]

Generate forecast with prediction intervals.

Parameters:
  • fh (Any) – Forecast horizon.

  • X (Optional[Any]) – Optional exogenous data.

  • coverage (float) – Coverage level (e.g., 0.9 for 90%).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast with intervals.

class timesmith.forecasters.BayesianForecaster(model_type='linear_trend', n_samples=2000, n_tune=1000, random_state=None, prior_params=None)[source]

Bases: BaseForecaster

Bayesian forecaster with uncertainty quantification using MCMC.

Uses Bayesian inference to estimate forecaster parameters and provides uncertainty quantification through posterior sampling. Works by fitting a probabilistic model to the time series and sampling from the posterior.

This is a general-purpose Bayesian forecaster that can be used with any time series model. For specific models (like ARIMA), consider using model-specific Bayesian implementations.

__init__(model_type='linear_trend', n_samples=2000, n_tune=1000, random_state=None, prior_params=None)[source]

Initialize Bayesian forecaster.

Parameters:
  • model_type (str) – Type of probabilistic model: - ‘linear_trend’: Linear trend with noise - ‘exponential_trend’: Exponential trend - ‘ar1’: AR(1) model

  • n_samples (int) – Number of MCMC samples.

  • n_tune (int) – Number of tuning samples.

  • random_state (Optional[int]) – Random state for reproducibility.

  • prior_params (Optional[Dict[str, Any]]) – Optional prior parameter distributions.

fit(y, X=None, **fit_params)[source]

Fit Bayesian model using MCMC.

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (not yet supported).

  • **fit_params (Any) – Additional fit parameters.

Return type:

BayesianForecaster

Returns:

Self for method chaining.

get_posterior_summary()[source]

Get summary statistics of posterior distributions.

Return type:

DataFrame

Returns:

DataFrame with posterior summary (mean, std, credible intervals).

predict(fh, X=None, **predict_params)[source]

Generate Bayesian forecast with uncertainty.

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon (integer or array-like).

  • X (Union[TableLike, Any, None]) – Optional exogenous data (not yet supported).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast with mean prediction and uncertainty intervals.

predict_interval(fh, X=None, coverage=0.9, **predict_params)[source]

Generate forecast with prediction intervals.

Parameters:
  • fh (Any) – Forecast horizon.

  • X (Optional[Any]) – Optional exogenous data (not yet supported).

  • coverage (float) – Coverage level (e.g., 0.9 for 90%).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast with prediction intervals.

class timesmith.forecasters.BlackScholesMonteCarloForecaster(n_simulations=1000, random_state=None, use_log_returns=True)[source]

Bases: BaseForecaster

Black-Scholes Monte Carlo forecaster for asset prices.

Uses geometric Brownian motion to simulate future price paths based on historical log returns. Estimates drift and volatility from historical data and generates ensemble forecasts with uncertainty quantification.

This is specifically designed for financial time series (stock prices, commodity prices, etc.) and follows the Black-Scholes model assumptions: - Log returns are normally distributed - Market is efficient (random walk) - Geometric Brownian motion process

Parameters:
  • n_simulations (int) – Number of Monte Carlo simulation paths (default: 1000).

  • random_state (Optional[int]) – Random seed for reproducibility.

  • use_log_returns (bool) – Whether to use log returns (default: True, recommended).

Example

>>> import pandas as pd
>>> import numpy as np
>>> dates = pd.date_range('2020-01-01', periods=100, freq='D')
>>> prices = pd.Series(100 + np.random.randn(100).cumsum(), index=dates)
>>> forecaster = BlackScholesMonteCarloForecaster(n_simulations=1000)
>>> forecaster.fit(prices)
>>> forecast = forecaster.predict(fh=30)
>>> print(forecast.predicted.mean())  # Mean forecast
__init__(n_simulations=1000, random_state=None, use_log_returns=True)[source]

Initialize Black-Scholes Monte Carlo forecaster.

Parameters:
  • n_simulations (int) – Number of Monte Carlo simulation paths.

  • random_state (Optional[int]) – Random seed for reproducibility.

  • use_log_returns (bool) – Whether to use log returns (True) or simple returns (False).

fit(y, X=None, **fit_params)[source]

Fit the forecaster to historical data.

Parameters:
  • y (Union[SeriesLike, Any]) – Historical price series (pandas Series with datetime index).

  • X (Union[TableLike, Any, None]) – Not used, present for API compatibility.

  • **fit_params (Any) – Additional fit parameters (not used).

Return type:

BlackScholesMonteCarloForecaster

Returns:

Self for method chaining.

predict(fh, X=None, **predict_params)[source]

Generate forecast using Black-Scholes Monte Carlo simulation.

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon. Can be: - Integer: number of periods ahead - Array-like: specific periods to forecast - pd.Index: specific dates/indices to forecast

  • X (Union[TableLike, Any, None]) – Not used, present for API compatibility.

  • **predict_params (Any) – Additional prediction parameters (not used).

Returns:

  • predicted: Mean forecast (pandas Series)

  • intervals: Prediction intervals (DataFrame with ‘lower’ and ‘upper’)

  • metadata: Additional information including all simulation paths

Return type:

Forecast

predict_interval(fh, X=None, coverage=0.9, **predict_params)[source]

Generate forecast with custom prediction intervals.

Parameters:
  • fh (Any) – Forecast horizon.

  • X (Optional[Any]) – Not used, present for API compatibility.

  • coverage (float) – Coverage level (e.g., 0.9 for 90% interval).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast with custom prediction intervals.

class timesmith.forecasters.EnsembleForecaster(n_lags=2, random_state=None, n_estimators_classifier=100, n_estimators_regressor=100, max_depth=None)[source]

Bases: BaseForecaster

Ensemble forecaster combining classification and regression models.

Uses Random Forest classifier to predict direction (up/down) and Random Forest regressor to predict magnitude, with classification predictions as features.

__init__(n_lags=2, random_state=None, n_estimators_classifier=100, n_estimators_regressor=100, max_depth=None)[source]

Initialize ensemble forecaster.

Parameters:
  • n_lags (int) – Number of lagged features to use.

  • random_state (Optional[int]) – Random seed for reproducibility.

  • n_estimators_classifier (int) – Number of trees for classifier.

  • n_estimators_regressor (int) – Number of trees for regressor.

  • max_depth (Optional[int]) – Maximum depth of trees (None = unlimited).

fit(y, X=None, **fit_params)[source]

Fit ensemble models on training data.

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (not yet supported).

  • **fit_params (Any) – Additional fit parameters.

Return type:

EnsembleForecaster

Returns:

Self for method chaining.

predict(fh, X=None, **predict_params)[source]

Generate forecasts.

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon (integer or array-like).

  • X (Union[TableLike, Any, None]) – Optional exogenous data (not yet supported).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast results.

class timesmith.forecasters.ExponentialMovingAverageForecaster(alpha=0.3)[source]

Bases: BaseForecaster

Exponential moving average forecaster.

Uses exponential smoothing with alpha parameter.

__init__(alpha=0.3)[source]

Initialize exponential moving average forecaster.

Parameters:

alpha (float) – Smoothing factor (0 < alpha <= 1).

fit(y, X=None, **fit_params)[source]

Fit the forecaster (computes EMA).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

ExponentialMovingAverageForecaster

Returns:

Self for method chaining.

predict(fh, X=None, **predict_params)[source]

Generate forecast.

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon (integer or array).

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast object with predictions.

class timesmith.forecasters.ExponentialSmoothingForecaster(trend='add', seasonal='add', seasonal_periods=None, optimized=True)[source]

Bases: BaseForecaster

Exponential smoothing forecaster using Holt-Winters method.

Wraps statsmodels.tsa.holtwinters.ExponentialSmoothing.

__init__(trend='add', seasonal='add', seasonal_periods=None, optimized=True)[source]

Initialize exponential smoothing forecaster.

Parameters:
  • trend (Optional[str]) – Type of trend component (‘add’, ‘mul’, None).

  • seasonal (Optional[str]) – Type of seasonal component (‘add’, ‘mul’, None).

  • seasonal_periods (Optional[int]) – Number of periods in a season.

  • optimized (bool) – Whether to optimize parameters.

fit(y, X=None, **fit_params)[source]

Fit exponential smoothing model.

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

ExponentialSmoothingForecaster

Returns:

Self for method chaining.

predict(fh, X=None, **predict_params)[source]

Generate forecast.

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon (integer or array).

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast object with predictions.

predict_interval(fh, X=None, coverage=0.9, **predict_params)[source]

Generate forecast with prediction intervals.

Parameters:
  • fh (Any) – Forecast horizon.

  • X (Optional[Any]) – Optional exogenous data.

  • coverage (float) – Coverage level (e.g., 0.9 for 90%).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast with intervals.

class timesmith.forecasters.KalmanFilterForecaster(state_dimension=2, measurement_dimension=1, initial_state=None, state_transition=None, measurement_matrix=None, initial_covariance=1000.0, measurement_noise=5.0, process_noise=0.1, dt=1.0)[source]

Bases: BaseForecaster

Kalman filter forecaster for state space models.

Uses Kalman filtering for time series forecasting with state space models.

__init__(state_dimension=2, measurement_dimension=1, initial_state=None, state_transition=None, measurement_matrix=None, initial_covariance=1000.0, measurement_noise=5.0, process_noise=0.1, dt=1.0)[source]

Initialize Kalman filter forecaster.

Parameters:
  • state_dimension (int) – Dimension of state vector (default: 2).

  • measurement_dimension (int) – Dimension of measurement vector (default: 1).

  • initial_state (Optional[ndarray]) – Initial state vector (default: zeros).

  • state_transition (Optional[ndarray]) – State transition matrix F (default: constant velocity model).

  • measurement_matrix (Optional[ndarray]) – Measurement matrix H (default: [1, 0]).

  • initial_covariance (float) – Initial covariance P (default: 1000.0).

  • measurement_noise (float) – Measurement noise R (default: 5.0).

  • process_noise (float) – Process noise variance (default: 0.1).

  • dt (float) – Time step (default: 1.0).

fit(y, X=None, **fit_params)[source]

Fit Kalman filter to data.

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

KalmanFilterForecaster

Returns:

Self for method chaining.

predict(fh, X=None, **predict_params)[source]

Generate forecast.

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon (integer or array).

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast object with predictions.

predict_interval(fh, X=None, coverage=0.9, **predict_params)[source]

Generate forecast with prediction intervals.

Parameters:
  • fh (Any) – Forecast horizon.

  • X (Optional[Any]) – Optional exogenous data.

  • coverage (float) – Coverage level (e.g., 0.9 for 90%).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast with intervals.

class timesmith.forecasters.LSTMForecaster(input_chunk_length=12, output_chunk_length=1, n_rnn_layers=2, hidden_dim=64, n_epochs=100, random_state=None, scale=True, **darts_params)[source]

Bases: BaseForecaster

LSTM forecaster using Darts RNNModel (PyTorch only).

TimeSmith does not provide Facebook Prophet or other Darts Prophet bindings; this class only uses Darts’ recurrent neural network stack.

__init__(input_chunk_length=12, output_chunk_length=1, n_rnn_layers=2, hidden_dim=64, n_epochs=100, random_state=None, scale=True, **darts_params)[source]

Initialize LSTM forecaster.

Parameters:
  • input_chunk_length (int) – Number of time steps to use as input.

  • output_chunk_length (int) – Number of time steps to predict at once.

  • n_rnn_layers (int) – Number of RNN layers (default: 2).

  • hidden_dim (int) – Hidden dimension size (default: 64).

  • n_epochs (int) – Number of training epochs (default: 100).

  • random_state (Optional[int]) – Random seed for reproducibility.

  • scale (bool) – Whether to scale the data (default: True).

  • **darts_params (Any) – Additional Darts RNNModel parameters.

fit(y, X=None, **fit_params)[source]

Fit LSTM model.

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (not yet supported).

  • **fit_params (Any) – Additional fit parameters.

Return type:

LSTMForecaster

Returns:

Self for method chaining.

predict(fh, X=None, **predict_params)[source]

Generate forecast.

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon (integer or array).

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast object with predictions.

predict_interval(fh, X=None, coverage=0.9, **predict_params)[source]

Generate forecast with prediction intervals.

Parameters:
  • fh (Any) – Forecast horizon.

  • X (Optional[Any]) – Optional exogenous data.

  • coverage (float) – Coverage level (e.g., 0.9 for 90%).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast with intervals.

class timesmith.forecasters.LinearTrendForecaster[source]

Bases: BaseForecaster

Forecaster using linear trend extrapolation.

Fits a linear trend to historical data and extrapolates forward.

__init__()[source]

Initialize linear trend forecaster.

fit(y, X=None, **fit_params)[source]

Fit linear trend to training data.

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

LinearTrendForecaster

Returns:

Self for method chaining.

predict(fh, X=None, **predict_params)[source]

Generate forecasts using linear trend extrapolation.

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon (integer or array-like).

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast results.

class timesmith.forecasters.MonteCarloForecaster(base_forecaster, n_samples=1000, random_state=None, parameter_uncertainty=None, noise_level=None)[source]

Bases: BaseForecaster

Monte Carlo ensemble forecaster with uncertainty quantification.

Wraps a base forecaster and generates ensemble forecasts by sampling from parameter distributions or adding noise to predictions.

__init__(base_forecaster, n_samples=1000, random_state=None, parameter_uncertainty=None, noise_level=None)[source]

Initialize Monte Carlo forecaster.

Parameters:
  • base_forecaster (BaseForecaster) – Base forecaster to use for predictions.

  • n_samples (int) – Number of Monte Carlo samples.

  • random_state (Optional[int]) – Random state for reproducibility.

  • parameter_uncertainty (Optional[Dict[str, tuple]]) – Optional dict mapping parameter names to (mean, std) tuples.

  • noise_level (Optional[float]) – Optional noise level to add to predictions (as fraction of std).

fit(y, X=None, **fit_params)[source]

Fit the base forecaster.

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data.

  • **fit_params (Any) – Additional fit parameters.

Return type:

MonteCarloForecaster

Returns:

Self for method chaining.

predict(fh, X=None, **predict_params)[source]

Generate ensemble forecast with uncertainty.

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon.

  • X (Union[TableLike, Any, None]) – Optional exogenous data for forecast horizon.

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast with mean prediction and uncertainty intervals.

predict_interval(fh, X=None, coverage=0.9, **predict_params)[source]

Generate forecast with prediction intervals.

Parameters:
  • fh (Any) – Forecast horizon.

  • X (Optional[Any]) – Optional exogenous data for forecast horizon.

  • coverage (float) – Coverage level (e.g., 0.9 for 90%).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast with prediction intervals.

class timesmith.forecasters.SimpleMovingAverageForecaster(window=7)[source]

Bases: BaseForecaster

Simple moving average forecaster.

Uses the average of the last N values as the forecast.

__init__(window=7)[source]

Initialize simple moving average forecaster.

Parameters:

window (int) – Window size for moving average.

fit(y, X=None, **fit_params)[source]

Fit the forecaster (computes moving average).

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series.

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

SimpleMovingAverageForecaster

Returns:

Self for method chaining.

predict(fh, X=None, **predict_params)[source]

Generate forecast.

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon (integer or array).

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast object with predictions.

class timesmith.forecasters.SyntheticControlForecaster(treatment_start=None, pre_period_min=5)[source]

Bases: BaseForecaster

Synthetic control forecaster for counterfactual analysis.

Creates a synthetic control unit as a weighted combination of control units to estimate what would have happened in the absence of treatment.

__init__(treatment_start=None, pre_period_min=5)[source]

Initialize synthetic control forecaster.

Parameters:
  • treatment_start (Optional[int]) – Index where treatment begins (None = end of data).

  • pre_period_min (int) – Minimum number of pre-treatment periods required.

fit(y, X=None, **fit_params)[source]

Fit synthetic control model.

Parameters:
  • y (Union[SeriesLike, Any]) – Target time series (treated unit).

  • X (Union[TableLike, Any, None]) – Control units as DataFrame (each column is a control unit).

  • **fit_params (Any) – Additional fit parameters.

Return type:

SyntheticControlForecaster

Returns:

Self for method chaining.

get_weights()[source]

Get synthetic control weights.

Return type:

Dict[str, float]

Returns:

Dictionary mapping control unit names to weights.

predict(fh, X=None, **predict_params)[source]

Generate counterfactual forecast (what would have happened without treatment).

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon (ignored, uses post-treatment period).

  • X (Union[TableLike, Any, None]) – Optional control units for post-treatment (uses fit data if None).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast results with counterfactual predictions.

class timesmith.forecasters.VARForecaster(maxlags=10, ic='aic', force_differencing=False, verbose=False)[source]

Bases: BaseForecaster

Vector Autoregression (VAR) forecaster for multivariate time series.

Fits a VAR model to multiple interdependent time series and generates forecasts for all series simultaneously.

__init__(maxlags=10, ic='aic', force_differencing=False, verbose=False)[source]

Initialize VAR forecaster.

Parameters:
  • maxlags (int) – Maximum number of lags to consider for model selection.

  • ic (str) – Information criterion for lag selection (‘aic’, ‘bic’, ‘fpe’, ‘hqic’).

  • force_differencing (bool) – Whether to force first-order differencing (default: False).

  • verbose (bool) – Whether to print diagnostic information.

fit(y, X=None, **fit_params)[source]

Fit VAR model.

Parameters:
  • y (Union[SeriesLike, Any]) – Multivariate time series (DataFrame with multiple columns or PanelLike).

  • X (Union[TableLike, Any, None]) – Optional exogenous data (not yet supported).

  • **fit_params (Any) – Additional fit parameters.

Return type:

VARForecaster

Returns:

Self for method chaining.

predict(fh, X=None, **predict_params)[source]

Generate forecast.

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon (integer or array).

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast object with predictions for all series.

predict_interval(fh, X=None, coverage=0.9, **predict_params)[source]

Generate forecast with prediction intervals.

Parameters:
  • fh (Any) – Forecast horizon.

  • X (Optional[Any]) – Optional exogenous data.

  • coverage (float) – Coverage level (e.g., 0.9 for 90%).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast with intervals.

class timesmith.forecasters.WeightedMovingAverageForecaster(window=7, weights=None)[source]

Bases: BaseForecaster

Weighted moving average forecaster.

Uses weighted average of the last N values.

__init__(window=7, weights=None)[source]

Initialize weighted moving average forecaster.

Parameters:
  • window (int) – Window size for moving average.

  • weights (Optional[List[float]]) – Optional weights for each position (defaults to equal weights).

fit(y, X=None, **fit_params)[source]

Fit the forecaster (computes weighted MA).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

WeightedMovingAverageForecaster

Returns:

Self for method chaining.

predict(fh, X=None, **predict_params)[source]

Generate forecast.

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon (integer or array).

  • X (Union[TableLike, Any, None]) – Optional exogenous data (ignored).

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast object with predictions.

Network Analysis

Network analysis for time series.

This module provides tools for converting time series to networks and analyzing network properties.

class timesmith.network.Graph(edges, n_nodes, directed=False, weighted=False)[source]

Bases: object

Lightweight graph representation.

Primary storage is edges + optional adjacency matrix. NetworkX conversion is lazy and optional.

edges

List of (int, int) or (int, int, float) tuples (edge list).

n_nodes

Number of nodes.

directed

Whether graph is directed.

weighted

Whether edges have weights.

__init__(edges, n_nodes, directed=False, weighted=False)[source]

Initialize graph.

Parameters:
  • edges (List[Tuple]) – List of edge tuples (unweighted or weighted).

  • n_nodes (int) – Number of nodes.

  • directed (bool) – Whether graph is directed.

  • weighted (bool) – Whether edges have weights.

adjacency_matrix(format='sparse')[source]

Adjacency matrix (lazy, sparse by default).

Parameters:

format (str) – Output format: “sparse” (CSR), “dense”, or “coo”.

Returns:

Adjacency matrix. Sparse by default to avoid memory blowup.

Raises:

ValueError – If format=”dense” and n_nodes > 50_000.

as_networkx(force=False)[source]

Convert to NetworkX graph (optional dependency).

Parameters:

force (bool) – If False, refuse conversion for n > 200_000 nodes.

Returns:

NetworkX graph object.

Raises:
degree_sequence()[source]

Degree sequence (cached).

For undirected graphs, returns total degree. For directed graphs, returns out-degree.

Return type:

ndarray[tuple[Any, ...], dtype[int_]]

Returns:

Array of degrees for each node.

in_degree_sequence()[source]

In-degree sequence for directed graphs (cached).

Return type:

ndarray[tuple[Any, ...], dtype[int_]]

Returns:

Array of in-degrees for each node.

property n_edges: int

Number of edges.

out_degree_sequence()[source]

Out-degree sequence for directed graphs (cached).

Return type:

ndarray[tuple[Any, ...], dtype[int_]]

Returns:

Array of out-degrees for each node.

summary(include_triangles=False)[source]

Graph summary statistics (computed from edges/degrees, no dense matrix).

Parameters:

include_triangles (bool) – If True, compute triangle count (requires edge list, slower).

Return type:

dict

Returns:

Dictionary with graph statistics.

class timesmith.network.HVGFeaturizer(weighted=False, limit=None, directed=False, include_degrees=True)[source]

Bases: BaseFeaturizer

Horizontal Visibility Graph featurizer.

Converts SeriesLike to TableLike by building HVG and extracting features.

__init__(weighted=False, limit=None, directed=False, include_degrees=True)[source]

Initialize HVG featurizer.

Parameters:
  • weighted (bool) – If True, edges will be weighted.

  • limit (Optional[int]) – Maximum temporal distance for edges.

  • directed (bool) – If True, create directed graph.

  • include_degrees (bool) – Whether to include degree sequence in output.

fit(y, X=None, **fit_params)[source]

Fit the featurizer (no-op for HVG).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

HVGFeaturizer

Returns:

Self for method chaining.

transform(y, X=None)[source]

Build HVG and extract features.

Parameters:
  • y (Any) – SeriesLike data.

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

DataFrame

Returns:

TableLike DataFrame with network features.

class timesmith.network.MultiscaleGraphs(method='hvg', scales=None, coarse_method='mean', **method_kwargs)[source]

Bases: object

Multiscale graph analysis for time series.

Analyzes time series at multiple temporal scales by coarse-graining and computing graph features at each scale. Creates a scale signature (feature vector across scales) useful for detection stability.

__init__(method='hvg', scales=None, coarse_method='mean', **method_kwargs)[source]

Initialize multiscale graph analyzer.

Parameters:
  • method (str) – Network method: ‘hvg’, ‘nvg’, ‘recurrence’, ‘transition’.

  • scales (Optional[List[int]]) – List of coarse-graining scales. If None, uses [1, 2, 4, 8, 16].

  • coarse_method (str) – Coarse-graining aggregation: “mean”, “median”, “max”, “min”, “std”.

  • **method_kwargs – Additional parameters for the network builder.

fit(x)[source]

Fit the multiscale analyzer to a time series.

Parameters:

x (ndarray) – Input time series (1D array).

Return type:

MultiscaleGraphs

Returns:

Self for method chaining.

fit_transform(x, features=None)[source]

Fit and return scale signature in one step.

Parameters:
  • x (ndarray) – Input time series (1D array).

  • features (Optional[List[str]]) – Features to include in signature.

Return type:

Dict[str, ndarray]

Returns:

Scale signature dictionary.

scale_signature(features=None)[source]

Get scale signature (feature values across scales).

Parameters:

features (Optional[List[str]]) – List of feature names to include. If None, uses common features: [‘n_nodes’, ‘n_edges’, ‘avg_degree’, ‘std_degree’, ‘density’].

Return type:

Dict[str, ndarray]

Returns:

Dictionary mapping feature names to arrays of length n_scales.

stats()[source]

Get full statistics at each scale.

Return type:

Dict[int, Dict]

Returns:

Dictionary mapping scale to statistics dictionary.

class timesmith.network.NVGFeaturizer(weighted=False, limit=None, directed=False, include_degrees=True)[source]

Bases: BaseFeaturizer

Natural Visibility Graph featurizer.

Converts SeriesLike to TableLike by building NVG and extracting features.

__init__(weighted=False, limit=None, directed=False, include_degrees=True)[source]

Initialize NVG featurizer.

Parameters:
  • weighted (bool) – If True, edges will be weighted.

  • limit (Optional[int]) – Maximum temporal distance for edges.

  • directed (bool) – If True, create directed graph.

  • include_degrees (bool) – Whether to include degree sequence in output.

fit(y, X=None, **fit_params)[source]

Fit the featurizer (no-op for NVG).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

NVGFeaturizer

Returns:

Self for method chaining.

transform(y, X=None)[source]

Build NVG and extract features.

Parameters:
  • y (Any) – SeriesLike data.

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

DataFrame

Returns:

TableLike DataFrame with network features.

class timesmith.network.NetworkSignificanceResult(metric_name, observed_value, null_mean, null_std, z_score, p_value, n_surrogates, surrogate_method, significant, confidence_interval, alpha=0.05)[source]

Bases: object

Results from network significance testing.

metric_name

Name of the metric being tested.

observed_value

Observed value of the metric.

null_mean

Mean of the null distribution.

null_std

Standard deviation of the null distribution.

z_score

Z-score: (observed - mean) / std.

p_value

Two-tailed p-value (approximate, based on normal distribution).

n_surrogates

Number of surrogates used.

surrogate_method

Method used to generate surrogates.

significant

Whether the result is significant at alpha=0.05 (two-tailed).

confidence_interval

95% confidence interval for the metric under the null.

__init__(metric_name, observed_value, null_mean, null_std, z_score, p_value, n_surrogates, surrogate_method, significant, confidence_interval, alpha=0.05)
alpha: float = 0.05
confidence_interval: tuple[float, float]
metric_name: str
n_surrogates: int
null_mean: float
null_std: float
observed_value: float
p_value: float
significant: bool
surrogate_method: str
z_score: float
class timesmith.network.RecurrenceNetworkFeaturizer(threshold=None, embedding_dimension=None, time_delay=1, metric='euclidean', rule=None, k=None, include_degrees=True)[source]

Bases: BaseFeaturizer

Recurrence Network featurizer.

Converts SeriesLike to TableLike by building recurrence network and extracting features.

__init__(threshold=None, embedding_dimension=None, time_delay=1, metric='euclidean', rule=None, k=None, include_degrees=True)[source]

Initialize recurrence network featurizer.

Parameters:
  • threshold (Optional[float]) – Distance threshold for recurrence (epsilon rule).

  • embedding_dimension (Optional[int]) – Embedding dimension (m).

  • time_delay (int) – Time delay (tau).

  • metric (str) – Distance metric.

  • rule (Optional[str]) – Threshold rule (‘epsilon’ or ‘knn’).

  • k (Optional[int]) – Number of neighbors for k-NN rule.

  • include_degrees (bool) – Whether to include degree sequence in output.

fit(y, X=None, **fit_params)[source]

Fit the featurizer (no-op for recurrence network).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

RecurrenceNetworkFeaturizer

Returns:

Self for method chaining.

transform(y, X=None)[source]

Build recurrence network and extract features.

Parameters:
  • y (Any) – SeriesLike data.

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

DataFrame

Returns:

TableLike DataFrame with network features.

class timesmith.network.TransferEntropyDetector(lag=1, bins=10, threshold=None)[source]

Bases: BaseDetector

Detector using transfer entropy for causal inference.

Uses transfer entropy to detect causal relationships and anomalies.

__init__(lag=1, bins=10, threshold=None)[source]

Initialize transfer entropy detector.

Parameters:
  • lag (int) – Time lag for past values.

  • bins (int) – Number of bins for discretization.

  • threshold (Optional[float]) – Optional threshold for binary classification.

fit(y, X=None, **fit_params)[source]

Fit the detector (computes transfer entropy if X provided).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional source time series for causal inference.

  • **fit_params (Any) – Additional fit parameters.

Return type:

TransferEntropyDetector

Returns:

Self for method chaining.

predict(y, X=None, threshold=None)[source]

Predict causal relationships based on transfer entropy.

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional source time series.

  • threshold (Optional[float]) – Optional threshold for binary classification.

Return type:

Any

Returns:

Boolean array indicating causal relationship (if threshold provided), or transfer entropy value.

score(y, X=None)[source]

Compute transfer entropy scores.

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional source time series.

Return type:

Any

Returns:

Transfer entropy score(s).

class timesmith.network.TransitionNetworkFeaturizer(n_bins=10, order=1, symbolizer=None, include_degrees=True)[source]

Bases: BaseFeaturizer

Transition Network featurizer.

Converts SeriesLike to TableLike by building transition network and extracting features.

__init__(n_bins=10, order=1, symbolizer=None, include_degrees=True)[source]

Initialize transition network featurizer.

Parameters:
  • n_bins (int) – Number of bins for symbolization.

  • order (int) – Order of transition patterns.

  • symbolizer (Optional[str]) – Symbolization method (‘equal_width’ or ‘ordinal’).

  • include_degrees (bool) – Whether to include degree sequence in output.

fit(y, X=None, **fit_params)[source]

Fit the featurizer (no-op for transition network).

Parameters:
  • y (Any) – Target time series.

  • X (Optional[Any]) – Optional exogenous data (ignored).

  • **fit_params (Any) – Additional fit parameters.

Return type:

TransitionNetworkFeaturizer

Returns:

Self for method chaining.

transform(y, X=None)[source]

Build transition network and extract features.

Parameters:
  • y (Any) – SeriesLike data.

  • X (Optional[Any]) – Optional exogenous data (ignored).

Return type:

DataFrame

Returns:

TableLike DataFrame with network features.

timesmith.network.build_windows(x, window, step=1, method='hvg', output='stats', **method_kwargs)[source]

Build graph statistics per window (memory efficient for large series).

For meter data with millions of points, this computes graph stats per window and returns only the time series of stats, not full graphs.

Parameters:
  • x (ndarray) – Input time series (1D array).

  • window (int) – Window width (number of time points per window).

  • step (int) – Step size between consecutive windows.

  • method (str) – Network method: ‘hvg’, ‘nvg’, ‘recurrence’, ‘transition’.

  • output (str) – Output mode: ‘stats’ (recommended), ‘degrees’, or ‘edges’.

  • **method_kwargs – Additional parameters for the network builder.

Return type:

Dict[str, ndarray]

Returns:

Dictionary mapping stat names to arrays of length n_windows.

timesmith.network.coarse_grain(x, scale, method='mean')[source]

Coarse-grain a time series by aggregating points at a given scale.

Parameters:
  • x (ndarray) – Input time series (1D array).

  • scale (int) – Coarse-graining scale (number of points to aggregate).

  • method (str) – Aggregation method: “mean”, “median”, “max”, “min”, “std”.

Return type:

ndarray

Returns:

Coarse-grained time series.

timesmith.network.compute_clustering(G, method='average', sample_size=None)[source]

Compute clustering coefficient metrics.

Parameters:
  • G (Any) – NetworkX graph or timesmith.network.Graph object.

  • method (str) – Method: “average” (average clustering), “global” (transitivity), or “local” (returns per-node clustering).

  • sample_size (Optional[int]) – For large graphs, sample nodes for local clustering computation.

Return type:

Dict[str, float]

Returns:

Dictionary with clustering metrics.

timesmith.network.compute_modularity(G, method='louvain', weight=None, resolution=1.0, seed=None)[source]

Compute modularity and community structure.

Parameters:
  • G (Any) – NetworkX graph or timesmith.network.Graph object.

  • method (str) – Community detection method: “louvain”, “leiden”, “greedy”, or “label_propagation”.

  • weight (Optional[str]) – Edge attribute to use as weight (default: unweighted).

  • resolution (float) – Resolution parameter for modularity (higher = more communities).

  • seed (Optional[int]) – Random seed for community detection.

Return type:

Dict[str, Union[float, dict]]

Returns:

Dictionary with modularity metrics.

timesmith.network.compute_network_metric_significance(x, metric_fn, method='shuffle', n_surrogates=200, alpha=0.05, metric_name='metric', rng=None, **kwargs)[source]

Test significance of a network metric against null distribution.

Parameters:
  • x (ndarray) – Original time series.

  • metric_fn (Callable[[ndarray], float]) – Function that takes a time series and returns a metric value.

  • method (Literal['shuffle', 'phase', 'circular', 'iaaft', 'block_bootstrap']) – Surrogate generation method.

  • n_surrogates (int) – Number of surrogate series to generate.

  • alpha (float) – Significance level (two-tailed).

  • metric_name (str) – Name of the metric for reporting.

  • rng (Optional[Generator]) – Random number generator.

  • **kwargs – Additional arguments for surrogate generation.

Return type:

NetworkSignificanceResult

Returns:

NetworkSignificanceResult with test results.

timesmith.network.compute_path_lengths(G, method='average', sample_size=None, weight=None)[source]

Compute shortest path length metrics.

Parameters:
  • G (Any) – NetworkX graph or timesmith.network.Graph object.

  • method (str) – Method: “average” (average path length), “diameter” (longest shortest path), or “eccentricity” (returns per-node eccentricity).

  • sample_size (Optional[int]) – For large graphs, sample node pairs for path computation.

  • weight (Optional[str]) – Edge attribute to use as weight (default: unweighted).

Return type:

Dict[str, float]

Returns:

Dictionary with path length metrics.

timesmith.network.conditional_transfer_entropy(x, y, z, lag=1, bins=10)[source]

Compute conditional transfer entropy from X to Y given Z.

Conditional transfer entropy accounts for confounding variables Z, measuring the direct causal influence from X to Y.

Parameters:
  • x (ndarray) – Source time series.

  • y (ndarray) – Target time series.

  • z (ndarray) – Conditioning time series (confounding variable).

  • lag (int) – Time lag for past values.

  • bins (int) – Number of bins for discretization.

Return type:

float

Returns:

Conditional transfer entropy from X to Y given Z (non-negative, bits).

timesmith.network.directed_3node_motifs(G)[source]

Count connected directed 3-node motifs using adjacency pattern codes.

Parameters:

G – Directed NetworkX graph.

Return type:

Dict

Returns:

Dictionary mapping motif codes to counts and frequencies.

timesmith.network.generate_surrogate(x, method='shuffle', rng=None, **kwargs)[source]

Generate a surrogate time series using the specified method.

Parameters:
  • x (ndarray) – Original time series.

  • method (Literal['shuffle', 'phase', 'circular', 'iaaft', 'block_bootstrap']) – Surrogate generation method.

  • rng (Optional[Generator]) – Random number generator.

  • **kwargs – Additional arguments for surrogate generation.

Return type:

ndarray

Returns:

Surrogate time series.

timesmith.network.graph_summary(G, motifs=None, motif_samples=None, seed=3363)[source]

Compute a comprehensive summary of graph properties.

Parameters:
  • G (Any) – NetworkX graph or timesmith.network.Graph object.

  • motifs (Optional[str]) – Type of motifs to compute (‘3node’, ‘4node’, or None).

  • motif_samples (Optional[int]) – Maximum number of samples for motif counting.

  • seed (int) – Random seed for sampling.

Return type:

dict

Returns:

Dictionary of graph properties.

timesmith.network.net_enn(D, epsilon=None, percentile=None, weighted=False, directed=False)[source]

ε-Nearest Neighbors network from distance matrix.

Each node is connected to all nodes within distance epsilon.

Parameters:
  • D (ndarray) – Distance matrix (n, n) - smaller = more similar.

  • epsilon (Optional[float]) – Distance threshold. If None, use percentile.

  • percentile (Optional[float]) – Percentile of distances to use as threshold (0-100).

  • weighted (bool) – If True, edge weights = distances.

  • directed (bool) – If True, create directed graph.

Returns:

Tuple of (NetworkX graph, adjacency matrix).

timesmith.network.net_knn(D, k, mutual=False, weighted=False, directed=False)[source]
timesmith.network.network_metrics(G, include=None, sample_size=None, **kwargs)[source]

Compute comprehensive network metrics.

Parameters:
  • G (Any) – NetworkX graph or timesmith.network.Graph object.

  • include (Optional[list]) – Metrics to include: [“clustering”, “path_lengths”, “modularity”]. If None, includes all metrics.

  • sample_size (Optional[int]) – For large graphs, sample nodes/pairs for expensive computations.

  • **kwargs – Additional arguments passed to metric functions.

Return type:

Dict[str, Union[float, dict]]

Returns:

Dictionary with all requested network metrics.

timesmith.network.node_roles(G, n_roles=4, features='basic', n_init=10, seed=3363)[source]

Compute node roles using clustering of network features.

Parameters:
  • G – NetworkX graph (will be converted to undirected).

  • n_roles (int) – Number of roles to identify.

  • features (str) – Feature set to use (“basic” only currently).

  • n_init (int) – Number of K-means initializations.

  • seed (int) – Random seed.

Return type:

Tuple[Dict, ndarray]

Returns:

Tuple of (node_to_role dictionary, cluster centers array).

timesmith.network.transfer_entropy(x, y, lag=1, bins=10)[source]

Compute transfer entropy from X to Y.

Transfer entropy measures the amount of information transferred from X to Y, quantifying causal influence.

Parameters:
  • x (ndarray) – Source time series.

  • y (ndarray) – Target time series (must have same length as x).

  • lag (int) – Time lag for past values.

  • bins (int) – Number of bins for discretization.

Return type:

float

Returns:

Transfer entropy from X to Y (non-negative, bits).

timesmith.network.transfer_entropy_network(X, lag=1, bins=10, threshold=None, series_names=None)[source]

Construct a directed network based on transfer entropy between time series.

Each edge (i, j) represents causal influence from series i to series j, weighted by the transfer entropy value.

Parameters:
  • X (list) – List of time series arrays to analyze.

  • lag (int) – Time lag for transfer entropy computation.

  • bins (int) – Number of bins for discretization.

  • threshold (Optional[float]) – Minimum transfer entropy threshold for edges (if None, include all edges).

  • series_names (Optional[list]) – Names for each series (default: “Series_0”, “Series_1”, …).

Returns:

Tuple of (NetworkX DiGraph, transfer entropy matrix, statistics dictionary).

timesmith.network.ts_to_windows(x, width, by=1, start=0, end=None)[source]

Extract sliding windows from a time series.

Parameters:
  • x (ndarray) – Input time series (1D array).

  • width (int) – Window width (number of time points per window).

  • by (int) – Step size between consecutive windows.

  • start (int) – Starting index (0-based).

  • end (Optional[int]) – Ending index (exclusive). If None, use len(x).

Return type:

ndarray

Returns:

Array of shape (n_windows, width) where each row is a window.

timesmith.network.undirected_4node_motifs(G)[source]
Return type:

Dict

Utilities

Utility functions for time series operations.

timesmith.utils.autocorrelation(data, max_lag=None)[source]

Calculate autocorrelation function (ACF).

Computes the autocorrelation coefficients for different lags, measuring the correlation between a time series and a lagged version of itself.

Parameters:
  • data (SeriesLike) – Time series data (Series, DataFrame, or array-like).

  • max_lag (Optional[int]) – Maximum lag to calculate (default: len(data) - 1).

Return type:

List[float]

Returns:

List of autocorrelation coefficients for each lag (lag 0 to max_lag).

Raises:

ValueError – If data is too short or max_lag is invalid.

Example

>>> data = [1, 2, 3, 4, 5, 4, 3, 2, 1]
>>> acf = autocorrelation(data, max_lag=3)
>>> len(acf)
4
>>> acf[0]  # Lag 0 is always 1.0
1.0
timesmith.utils.autocorrelation_plot_data(data, max_lag=None)[source]

Calculate ACF and PACF for plotting.

Convenience function that returns both ACF and PACF along with lag indices for easy plotting.

Parameters:
  • data (SeriesLike) – Time series data.

  • max_lag (Optional[int]) – Maximum lag to calculate.

Returns:

  • ‘lags’: Array of lag values

  • ’acf’: Autocorrelation values

  • ’pacf’: Partial autocorrelation values

Return type:

dict

timesmith.utils.black_scholes_monte_carlo(historical_data, forecast_days, n_simulations=1000, random_state=None)[source]

Black-Scholes Monte Carlo simulation for asset price forecasting.

Estimates drift and volatility from historical log returns and simulates future price paths using geometric Brownian motion. This is the standard approach used in option pricing and financial forecasting.

The model assumes: - Log returns are normally distributed - Market is efficient (random walk) - Geometric Brownian motion: ΔS = S * (μΔt + σε√Δt)

Parameters:
  • historical_data (SeriesLike) – Historical price series (pandas Series with datetime index).

  • forecast_days (int) – Number of days to forecast.

  • n_simulations (int) – Number of simulation paths to generate.

  • random_state (Optional[int]) – Random seed for reproducibility.

Return type:

ndarray

Returns:

Array of shape (forecast_days, n_simulations) with simulated price paths. Each column represents one simulation path.

Example

>>> import pandas as pd
>>> import numpy as np
>>> dates = pd.date_range('2020-01-01', periods=100, freq='D')
>>> prices = pd.Series(100 + np.random.randn(100).cumsum(), index=dates)
>>> paths = black_scholes_monte_carlo(prices, forecast_days=30, n_simulations=1000)
>>> print(paths.shape)  # (30, 1000)
timesmith.utils.bootstrap_confidence_intervals(model_fit_func, data, forecast_steps, n_bootstraps=100, confidence=0.95, random_seed=None)[source]

Generate bootstrap confidence intervals for forecasts.

Parameters:
  • model_fit_func (Callable) – Function that takes data and returns a fitted model with a forecast(steps) or predict() method.

  • data (SeriesLike) – Time series data.

  • forecast_steps (int) – Number of steps to forecast.

  • n_bootstraps (int) – Number of bootstrap iterations (default: 100).

  • confidence (float) – Confidence level (default: 0.95).

  • random_seed (Optional[int]) – Random seed for reproducibility.

Return type:

Tuple[ndarray, ndarray, ndarray]

Returns:

Tuple of (mean_forecast, lower_bound, upper_bound) as numpy arrays.

timesmith.utils.compute_anomalies(y, climatology=None, anomaly_type='absolute')[source]

Compute climatological anomalies.

Parameters:
  • y (SeriesLike) – Time series with datetime index.

  • climatology (Optional[Dict[str, Any]]) – Pre-computed climatology (computed if None).

  • anomaly_type (str) – ‘absolute’, ‘relative’, or ‘standardized’.

Return type:

Series

Returns:

Time series of anomalies.

timesmith.utils.compute_climatology(y, reference_period=None)[source]

Compute climatological statistics for time series.

Parameters:
  • y (SeriesLike) – Time series with datetime index.

  • reference_period (Optional[Tuple[str, str]]) – Optional tuple of (start_date, end_date) for reference period.

Return type:

Dict[str, Any]

Returns:

Dictionary with climatology statistics.

timesmith.utils.correlation_distance(x, y, method='pearson', absolute=False)[source]

Compute correlation-based distance between two time series.

Parameters:
  • x (ndarray) – First time series.

  • y (ndarray) – Second time series (must have same length as x).

  • method (str) – Correlation method (‘pearson’ or ‘spearman’).

  • absolute (bool) – If True, use absolute value of correlation.

Return type:

float

Returns:

Distance value (0-2 range, where 0 = perfect correlation).

timesmith.utils.create_sequences(data, lookback=5, forecast_horizon=1)[source]

Create sequences for LSTM/RNN models using sliding window.

Creates input sequences (X) and target sequences (y) from time series data using a sliding window approach.

Parameters:
  • data (SeriesLike) – Time series data (Series or array-like).

  • lookback (int) – Number of time steps to look back (sequence length).

  • forecast_horizon (int) – Number of steps ahead to forecast (default: 1).

Returns:

  • X: Array of shape (n_samples, lookback, n_features)

  • y: Array of shape (n_samples, forecast_horizon)

Return type:

Tuple[ndarray, ndarray]

Example

>>> data = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
>>> X, y = create_sequences(data, lookback=3, forecast_horizon=1)
>>> # X[0] = [1, 2, 3], y[0] = [4]
>>> # X[1] = [2, 3, 4], y[1] = [5]
timesmith.utils.create_sequences_with_exog(y, X, lookback=5, forecast_horizon=1)[source]

Create sequences with exogenous variables.

Creates input sequences for both target (y) and exogenous (X) variables.

Parameters:
  • y (SeriesLike) – Target time series.

  • X (SeriesLike) – Exogenous time series (can be multi-variate).

  • lookback (int) – Number of time steps to look back.

  • forecast_horizon (int) – Number of steps ahead to forecast.

Returns:

  • X_seq: Exogenous sequences (n_samples, lookback, n_exog_features)

  • y_seq: Target sequences (n_samples, lookback, 1)

  • y_target: Target values (n_samples, forecast_horizon)

Return type:

Tuple[ndarray, ndarray, ndarray]

timesmith.utils.cross_correlation_distance(x, y, max_lag=10)[source]

Compute distance using maximum cross-correlation.

Parameters:
  • x (ndarray) – First time series.

  • y (ndarray) – Second time series.

  • max_lag (int) – Maximum lag to consider for cross-correlation.

Return type:

float

Returns:

Distance value based on maximum cross-correlation.

timesmith.utils.detect_anomalies_mad(series, threshold_std=3.0, window=3)[source]

Detect anomalous values using median absolute deviation (MAD).

Flags values that are more than threshold_std MAD from the rolling median. Uses MAD instead of std for robustness to outliers.

Parameters:
  • series (Series) – Time series data.

  • threshold_std (float) – Number of MAD units for threshold (roughly equivalent to std).

  • window (int) – Window size for rolling median.

Return type:

Series

Returns:

Boolean series indicating anomalies.

Example

>>> anomalies = detect_anomalies_mad(oil_series, threshold_std=3.0)
>>> print(f"Found {anomalies.sum()} anomalies")
timesmith.utils.detect_extreme_events(y, threshold_type='percentile', threshold_value=5.0)[source]

Detect extreme events in time series.

Parameters:
  • y (SeriesLike) – Time series with datetime index.

  • threshold_type (str) – ‘percentile’, ‘std_dev’, or ‘absolute’.

  • threshold_value (float) – Threshold value (percentile, std devs, or absolute).

Return type:

DataFrame

Returns:

DataFrame with extreme events.

timesmith.utils.detect_frequency(data)[source]

Detect the frequency of a time series.

Parameters:

data (Series) – Time series data.

Return type:

str

Returns:

Detected frequency string (e.g., ‘D’, ‘H’, ‘M’).

timesmith.utils.dtw_distance(x, y)[source]

Compute Dynamic Time Warping (DTW) distance.

Parameters:
  • x (ndarray) – First time series.

  • y (ndarray) – Second time series.

Return type:

float

Returns:

DTW distance value.

timesmith.utils.ensure_datetime_index(data)[source]

Ensure data has datetime index.

Parameters:

data (Union[Series, DataFrame]) – Series or DataFrame to check.

Return type:

Union[Series, DataFrame]

Returns:

Data with datetime index (converted if needed).

timesmith.utils.euclidean_distance(x, y)[source]

Compute Euclidean distance between two time series.

Parameters:
  • x (ndarray) – First time series.

  • y (ndarray) – Second time series (must have same length as x).

Return type:

float

Returns:

Euclidean distance.

timesmith.utils.fill_missing_dates(data, method='forward')[source]

Fill missing dates in time series.

Parameters:
  • data (Series) – Time series data.

  • method (str) – Fill method (‘forward’, ‘backward’, ‘interpolate’).

Return type:

Series

Returns:

Time series with filled missing dates.

timesmith.utils.is_stationary(y, test='adf', significance_level=0.05)[source]

Simple stationarity test that returns boolean and p-value.

Parameters:
  • y (SeriesLike) – Time series data.

  • test (str) – Test method (‘adf’ for Augmented Dickey-Fuller, ‘kpss’ for KPSS).

  • significance_level (float) – Significance level for the test.

Return type:

Tuple[bool, float]

Returns:

Tuple of (is_stationary, p_value).

Example

>>> is_stationary, p_value = ts.is_stationary(series, test='adf')
timesmith.utils.load_ts_data(file_path, date_col='date', value_col='value', index_col=None)[source]

Load time series data from CSV file.

Parameters:
  • file_path (Union[str, Path]) – Path to CSV file.

  • date_col (str) – Name of date column.

  • value_col (str) – Name of value column.

  • index_col (Optional[str]) – Column to use as index (if None, uses date_col).

Return type:

Series

Returns:

Time series with datetime index.

timesmith.utils.manhattan_distance(x, y)[source]

Compute Manhattan (L1) distance between two time series.

Parameters:
  • x (ndarray) – First time series.

  • y (ndarray) – Second time series (must have same length as x).

Return type:

float

Returns:

Manhattan distance.

timesmith.utils.monte_carlo_simulation(initial_value, mu, sigma, days, simulations=1000)[source]

Perform a Monte Carlo simulation for time series forecasting.

Uses geometric Brownian motion model.

Parameters:
  • initial_value (float) – Initial value of the series.

  • mu (float) – Drift parameter (mean return).

  • sigma (float) – Volatility parameter (standard deviation).

  • days (int) – Number of days to simulate.

  • simulations (int) – Number of simulation paths.

Return type:

ndarray

Returns:

Array of shape (days, simulations) with simulated paths.

timesmith.utils.parametric_confidence_intervals(model, forecast_steps, confidence=0.95)[source]

Generate parametric confidence intervals from model.

Parameters:
  • model (Any) – Fitted model with get_forecast() method (e.g., statsmodels ARIMA).

  • forecast_steps (int) – Number of steps to forecast.

  • confidence (float) – Confidence level (default: 0.95).

Return type:

Tuple[ndarray, ndarray, ndarray]

Returns:

Tuple of (mean_forecast, lower_bound, upper_bound) as numpy arrays.

timesmith.utils.partial_autocorrelation(data, max_lag=None)[source]

Calculate partial autocorrelation function (PACF).

Computes the partial autocorrelation coefficients, which measure the correlation between observations at different lags while controlling for intermediate lags.

Uses the Durbin-Levinson algorithm for computation.

Parameters:
  • data (SeriesLike) – Time series data (Series, DataFrame, or array-like).

  • max_lag (Optional[int]) – Maximum lag to calculate (default: min(len(data)//2, 10)).

Return type:

List[float]

Returns:

List of partial autocorrelation coefficients (lag 0 to max_lag).

Raises:

ValueError – If data is too short.

Example

>>> data = [1, 2, 3, 4, 5, 4, 3, 2, 1]
>>> pacf = partial_autocorrelation(data, max_lag=3)
>>> len(pacf)
4
>>> pacf[0]  # Lag 0 is always 1.0
1.0
timesmith.utils.plot_autocorrelation(acf_values, pacf_values=None, max_lag=None, title='Autocorrelation', **kwargs)[source]

Plot autocorrelation and partial autocorrelation functions.

Parameters:
  • acf_values (ndarray) – ACF values.

  • pacf_values (Optional[ndarray]) – Optional PACF values.

  • max_lag (Optional[int]) – Maximum lag to display.

  • title (Optional[str]) – Plot title.

  • **kwargs – Additional arguments passed to plotsmith.

Returns:

Figure and axes objects.

timesmith.utils.plot_forecast(historical, forecast, intervals=None, title='Forecast', **kwargs)[source]

Plot forecast with historical data and optional confidence intervals.

Parameters:
  • historical (Series) – Historical time series data.

  • forecast (Series) – Forecasted values.

  • intervals (Optional[DataFrame]) – Optional DataFrame with ‘lower’ and ‘upper’ columns for confidence intervals.

  • title (Optional[str]) – Plot title.

  • **kwargs – Additional arguments passed to plotsmith.

Returns:

Figure and axes objects.

timesmith.utils.plot_monte_carlo(prices, title='Monte Carlo Simulation', save_path=None)[source]

Plot the Monte Carlo simulation results using plotsmith.

Parameters:
  • prices (ndarray) – Array of simulated paths from monte_carlo_simulation.

  • title (str) – Plot title.

  • save_path (Optional[str]) – Optional path to save the plot.

Raises:

ImportError – If plotsmith is not installed.

Return type:

None

timesmith.utils.plot_monte_carlo_paths(paths, title='Monte Carlo Simulation', show_mean=True, show_percentiles=True, **kwargs)[source]

Plot Monte Carlo simulation paths using plotsmith.

Parameters:
  • paths (ndarray) – Array of shape (n_steps, n_simulations) with simulation paths.

  • title (Optional[str]) – Plot title.

  • show_mean (bool) – Whether to show mean path.

  • show_percentiles (bool) – Whether to show percentile bands.

  • **kwargs – Additional arguments passed to plotsmith.

Returns:

Figure and axes objects.

timesmith.utils.plot_multiple_series(series_dict, title=None, figsize=None, **kwargs)[source]

Plot multiple time series on the same plot.

Parameters:
  • series_dict (dict) – Dictionary mapping labels to Series/DataFrame.

  • title (Optional[str]) – Plot title.

  • figsize (Optional[Tuple[int, int]]) – Figure size (width, height).

  • **kwargs – Additional arguments passed to plotsmith.

Returns:

Figure and axes objects.

timesmith.utils.plot_residuals(actual, predicted, plot_type='scatter', title='Residuals', **kwargs)[source]

Plot residuals using plotsmith.

Parameters:
  • actual (ndarray) – Actual values.

  • predicted (ndarray) – Predicted values.

  • plot_type (str) – Type of plot (‘scatter’, ‘line’, ‘histogram’).

  • title (Optional[str]) – Plot title.

  • **kwargs – Additional arguments passed to plotsmith.

Returns:

Figure and axes objects.

timesmith.utils.plot_timeseries(data, title=None, xlabel=None, ylabel=None, figsize=None, **kwargs)[source]

Plot time series data using plotsmith.

Parameters:
Returns:

Figure and axes objects.

timesmith.utils.remove_outliers_iqr(data, factor=1.5)[source]

Remove outliers using IQR method.

Parameters:
  • data (Series) – Time series data.

  • factor (float) – IQR factor for outlier detection.

Return type:

Series

Returns:

Time series with outliers removed.

timesmith.utils.resample_ts(data, freq='D', method='mean')[source]

Resample time series to different frequency.

Parameters:
  • data (Series) – Time series data.

  • freq (str) – Target frequency (e.g., ‘D’, ‘W’, ‘M’, ‘H’).

  • method (str) – Aggregation method (‘mean’, ‘sum’, ‘last’, ‘first’).

Return type:

Series

Returns:

Resampled time series.

timesmith.utils.split_ts(data, train_size=None, test_size=None, date_split=None)[source]

Split time series into train and test sets.

Parameters:
  • data (Union[Series, DataFrame]) – Time series data.

  • train_size (Union[float, int, None]) – If float: proportion of data for training. If int: number of observations for training. Default: 0.8 (if test_size not provided).

  • test_size (Union[float, int, None]) – If float: proportion of data for testing. If int: number of observations for testing. If provided, takes precedence over train_size.

  • date_split (Optional[str]) – Date string to split on (e.g., ‘2023-01-01’).

Return type:

Tuple[Union[Series, DataFrame], Union[Series, DataFrame]]

Returns:

Tuple of (train_data, test_data).

timesmith.utils.test_stationarity(y, significance_level=0.05)[source]

Test time series for stationarity using ADF and KPSS tests.

Parameters:
  • y (SeriesLike) – Time series data.

  • significance_level (float) – Significance level for tests.

Return type:

Dict[str, Any]

Returns:

Dictionary with stationarity test results.

timesmith.utils.train_test_split(data, test_size=0.2, train_size=None, method='time')[source]

Split time series into train and test sets (time-aware split).

This is a convenience function for time series cross-validation that ensures temporal ordering is preserved (no shuffling).

Parameters:
  • data (Union[Series, DataFrame]) – Time series data (Series or DataFrame).

  • test_size (Union[float, int]) – If float: proportion of data for testing (0.0 to 1.0). If int: number of observations for testing.

  • train_size (Union[float, int, None]) – If float: proportion of data for training. If int: number of observations for training. If provided, test_size is ignored.

  • method (str) – Split method. Currently only ‘time’ is supported (temporal split).

Return type:

Tuple[Union[Series, DataFrame], Union[Series, DataFrame]]

Returns:

Tuple of (train_data, test_data).

Example

>>> train, test = ts.train_test_split(data, test_size=0.2, method='time')

Composition

Composition objects for chaining estimators.

class timesmith.compose.Adapter[source]

Bases: BaseTransformer

Base class for adapters that convert between scitypes.

Examples

  • Series to Table via window features

  • Table to Series via aligned join

transform(y, X=None)[source]

Transform data to different scitype.

Parameters:
  • y (Any) – Target data to transform.

  • X (Optional[Any]) – Optional exogenous/feature data.

Return type:

Any

Returns:

Transformed data in different scitype.

class timesmith.compose.FeatureUnion(featurizers)[source]

Bases: BaseFeaturizer

Runs multiple featurizers then concatenates their table outputs.

featurizers

List of (name, featurizer) tuples.

__init__(featurizers)[source]

Initialize feature union.

Parameters:

featurizers (List[tuple]) – List of (name, featurizer) tuples.

fit(y, X=None, **fit_params)[source]

Fit all featurizers.

Parameters:
  • y (Union[SeriesLike, Any]) – Target data.

  • X (Union[TableLike, Any, None]) – Optional exogenous/feature data.

  • **fit_params (Any) – Additional fit parameters.

Return type:

FeatureUnion

Returns:

Self for method chaining.

get_params(deep=True)[source]

Get parameters for all featurizers.

Parameters:

deep (bool) – If True, will return parameters of contained subobjects.

Return type:

dict

Returns:

Dictionary of parameters.

set_params(**params)[source]

Set parameters for featurizers.

Parameters:

**params (Any) – Parameters in format ‘featurizer_name__param_name’: value.

Return type:

FeatureUnion

Returns:

Self for method chaining.

transform(y, X=None)[source]

Transform data through all featurizers and concatenate results.

Parameters:
  • y (Any) – Target data.

  • X (Optional[Any]) – Optional exogenous/feature data.

Return type:

DataFrame

Returns:

Concatenated TableLike data.

class timesmith.compose.ForecasterPipeline(steps, forecaster)[source]

Bases: BaseForecaster

Pipeline that chains transformer(s) then a forecaster.

steps

List of (name, transformer) tuples for preprocessing.

forecaster

Final forecaster step.

__init__(steps, forecaster)[source]

Initialize forecaster pipeline.

Parameters:
  • steps (List[tuple]) – List of (name, transformer) tuples.

  • forecaster (BaseForecaster) – Final forecaster step.

fit(y, X=None, **fit_params)[source]

Fit all transformers then the forecaster.

Parameters:
  • y (Union[SeriesLike, Any]) – Target data.

  • X (Union[TableLike, Any, None]) – Optional exogenous/feature data.

  • **fit_params (Any) – Additional fit parameters.

Return type:

ForecasterPipeline

Returns:

Self for method chaining.

get_params(deep=True)[source]

Get parameters for all steps and forecaster.

Parameters:

deep (bool) – If True, will return parameters of contained subobjects.

Return type:

dict

Returns:

Dictionary of parameters.

predict(fh, X=None, **predict_params)[source]

Make forecasts through the pipeline.

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon.

  • X (Union[TableLike, Any, None]) – Optional exogenous/feature data for forecast horizon.

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast results.

predict_interval(fh, X=None, coverage=0.9, **predict_params)[source]

Make forecasts with intervals through the pipeline.

Parameters:
  • fh (Union[int, list, Any]) – Forecast horizon.

  • X (Union[TableLike, Any, None]) – Optional exogenous/feature data for forecast horizon.

  • coverage (float) – Coverage level for prediction intervals.

  • **predict_params (Any) – Additional prediction parameters.

Return type:

Forecast

Returns:

Forecast results with intervals.

set_params(**params)[source]

Set parameters for steps and forecaster.

Parameters:

**params (Any) – Parameters in format ‘step_name__param_name’: value.

Return type:

ForecasterPipeline

Returns:

Self for method chaining.

class timesmith.compose.Pipeline(steps)[source]

Bases: BaseEstimator

Pipeline that chains transformer steps.

Supports scitype change across steps via adapters.

steps

List of (name, transformer) tuples.

__init__(steps)[source]

Initialize pipeline.

Parameters:

steps (List[tuple]) – List of (name, transformer) tuples.

fit(y, X=None, **fit_params)[source]

Fit all steps in the pipeline.

Parameters:
  • y (Union[SeriesLike, Any]) – Target data.

  • X (Union[TableLike, Any, None]) – Optional exogenous/feature data.

  • **fit_params (Any) – Additional fit parameters.

Return type:

Pipeline

Returns:

Self for method chaining.

get_params(deep=True)[source]

Get parameters for all steps.

Parameters:

deep (bool) – If True, will return parameters of contained subobjects.

Return type:

dict

Returns:

Dictionary of parameters.

inverse_transform(y, X=None)[source]

Inverse transform data through all steps in reverse.

Parameters:
  • y (Union[SeriesLike, Any]) – Transformed data.

  • X (Union[TableLike, Any, None]) – Optional exogenous/feature data.

Return type:

Union[SeriesLike, Any]

Returns:

Inverse transformed data.

set_params(**params)[source]

Set parameters for steps.

Parameters:

**params (Any) – Parameters in format ‘step_name__param_name’: value.

Return type:

Pipeline

Returns:

Self for method chaining.

transform(y, X=None)[source]

Transform data through all steps.

Parameters:
  • y (Union[SeriesLike, Any]) – Target data.

  • X (Union[TableLike, Any, None]) – Optional exogenous/feature data.

Return type:

Union[SeriesLike, Any]

Returns:

Transformed data.

timesmith.compose.make_forecaster_pipeline(*transformers, forecaster)[source]

Create a forecaster pipeline from transformers and a forecaster.

Parameters:
Return type:

ForecasterPipeline

Returns:

ForecasterPipeline object.

timesmith.compose.make_pipeline(*steps)[source]

Create a pipeline from transformers.

Parameters:

*steps (BaseTransformer) – Transformer objects. Names will be auto-generated.

Return type:

Pipeline

Returns:

Pipeline object.

Evaluation

Evaluation tools: splitters, metrics, backtests, and summaries.

class timesmith.eval.ExpandingWindowSplit(initial_window, step_size=1, fh=1)[source]

Bases: object

Expanding window cross-validation splitter.

Each fold uses all data up to the cutoff point for training, and tests on the next window.

initial_window

Initial training window size.

step_size

Step size between folds.

fh

Forecast horizon for each fold.

__init__(initial_window, step_size=1, fh=1)[source]

Initialize expanding window splitter.

Parameters:
  • initial_window (int) – Initial training window size.

  • step_size (int) – Step size between folds.

  • fh (int) – Forecast horizon for each fold.

split(y)[source]

Generate train/test splits.

Parameters:

y (Any) – Time series data (Series or DataFrame with time index).

Yields:

Tuples of (train_indices, test_indices, cutoff).

class timesmith.eval.ModelComparison[source]

Bases: object

Compare multiple forecasting models.

Stores results from multiple models and provides comparison utilities.

__init__()[source]

Initialize model comparison.

add_result(result)[source]

Add a model result to comparison.

Parameters:

result (ModelResult) – ModelResult to add.

Return type:

None

compare_metrics(actual)[source]

Compare all models’ metrics.

Parameters:

actual (SeriesLike) – Actual values to compare against.

Return type:

DataFrame

Returns:

DataFrame with metrics for each model, sorted by RMSE.

get_best_model(metric='RMSE')[source]

Get the best performing model based on a metric.

Parameters:

metric (str) – Metric to use for ranking (‘RMSE’, ‘MAE’, ‘MAPE’, ‘R²’).

Return type:

Optional[ModelResult]

Returns:

Best model result or None if no results.

class timesmith.eval.ModelResult(name, forecast, metrics=None, confidence_intervals=None, model_params=None)[source]

Bases: object

Container for a single model’s forecast and metrics.

__init__(name, forecast, metrics=None, confidence_intervals=None, model_params=None)
confidence_intervals: DataFrame | None = None
forecast: SeriesLike
metrics: Dict[str, float] | None = None
model_params: Dict[str, Any] | None = None
name: str
class timesmith.eval.SlidingWindowSplit(window_size, step_size=1, fh=1)[source]

Bases: object

Sliding window cross-validation splitter.

Each fold uses a fixed-size window for training, and tests on the next window.

window_size

Training window size.

step_size

Step size between folds.

fh

Forecast horizon for each fold.

__init__(window_size, step_size=1, fh=1)[source]

Initialize sliding window splitter.

Parameters:
  • window_size (int) – Training window size.

  • step_size (int) – Step size between folds.

  • fh (int) – Forecast horizon for each fold.

split(y)[source]

Generate train/test splits.

Parameters:

y (Any) – Time series data (Series or DataFrame with time index).

Yields:

Tuples of (train_indices, test_indices, cutoff).

timesmith.eval.backtest_forecaster(forecaster, task, splitter=None, metrics=None)[source]

Run backtest on a forecaster with a task.

Parameters:
  • forecaster (BaseForecaster) – Forecaster or forecaster pipeline to test.

  • task (ForecastTask) – ForecastTask with y, fh, and optional X.

  • splitter (Optional[Any]) – Optional splitter (defaults to ExpandingWindowSplit).

  • metrics (Optional[list]) – Optional list of metric functions (defaults to [mae, rmse, mape]).

Return type:

BacktestResult

Returns:

BacktestResult with results table and summary.

timesmith.eval.bias(y_true, y_pred)[source]

Calculate bias (mean error).

Bias measures the average difference between predicted and actual values. Positive bias indicates over-estimation, negative indicates under-estimation.

Parameters:
  • y_true (Any) – True values.

  • y_pred (Any) – Predicted values.

Return type:

float

Returns:

Bias value.

timesmith.eval.compare_models(actual, forecasts)[source]

Quick comparison function for multiple forecasts.

Parameters:
  • actual (SeriesLike) – Actual values.

  • forecasts (Dict[str, SeriesLike]) – Dictionary mapping model names to forecast Series or Forecast objects.

Return type:

DataFrame

Returns:

DataFrame with comparison metrics for each model.

timesmith.eval.mae(y_true, y_pred)[source]

Mean Absolute Error.

Parameters:
  • y_true (Any) – True values.

  • y_pred (Any) – Predicted values.

Return type:

float

Returns:

Mean absolute error.

timesmith.eval.mape(y_true, y_pred)[source]

Mean Absolute Percentage Error with safe zero handling.

Parameters:
  • y_true (Any) – True values.

  • y_pred (Any) – Predicted values.

Return type:

float

Returns:

Mean absolute percentage error. Returns NaN if all true values are zero.

timesmith.eval.r2_score(y_true, y_pred)[source]

R-squared coefficient of determination.

Parameters:
  • y_true (Any) – True values.

  • y_pred (Any) – Predicted values.

Return type:

float

Returns:

R² score.

timesmith.eval.rmse(y_true, y_pred)[source]

Root Mean Squared Error.

Parameters:
  • y_true (Any) – True values.

  • y_pred (Any) – Predicted values.

Return type:

float

Returns:

Root mean squared error.

timesmith.eval.smape(y_true, y_pred)[source]

Symmetric Mean Absolute Percentage Error.

SMAPE is symmetric and handles zero values better than MAPE.

Parameters:
  • y_true (Any) – True values.

  • y_pred (Any) – Predicted values.

Return type:

float

Returns:

SMAPE value (percentage).

timesmith.eval.summarize_backtest(result)[source]

Summarize backtest results with aggregate and per-fold metrics.

Parameters:

result (BacktestResult) – BacktestResult from backtest_forecaster.

Return type:

Dict

Returns:

Dictionary with aggregate metrics and per-fold metrics DataFrame.

timesmith.eval.ubrmse(y_true, y_pred)[source]

Calculate Unbiased Root Mean Square Error (ubRMSE).

ubRMSE removes the impact of bias from RMSE, measuring only the random component of error. Useful when assessing precision separately from accuracy.

Parameters:
  • y_true (Any) – True values.

  • y_pred (Any) – Predicted values.

Return type:

float

Returns:

ubRMSE value.