Skip to main content

No project description provided

Project description

Time Series Split Package

A Python package for splitting time series data into training and testing sets, preserving the temporal order.

Installation

You can install this package using pip:

pip install time_series_split

Usage

The split_ts function splits time series data into training and testing sets. It handles both pandas.DataFrame and pandas.Series inputs and ensures that the split maintains the temporal order.

Function: split_ts

import pandas as pd

def split_ts(X, y=None, test_size=0.2):
    """
    Splits time series data into training and testing sets.

    Parameters:
    X (pd.DataFrame or pd.Series): Features of the time series.
    y (pd.Series or pd.DataFrame, optional): Target column corresponding to the features. (default: None)
    test_size (float): Proportion of the dataset to use as test set. (default: 0.2)

    Returns:
    If `y` is provided:
    X_train, X_test, y_train, y_test (np.ndarray or pd.DataFrame, np.ndarray or pd.DataFrame, np.ndarray or pd.Series, np.ndarray or pd.Series): Training and testing sets.

    If `y` is not provided:
    X_train, X_test (np.ndarray or pd.DataFrame, np.ndarray or pd.DataFrame): Training and testing sets.
    """

Parameters

  • X: Features of the time series. Can be a pandas.DataFrame or pandas.Series.
  • y: (Optional) Target column corresponding to the features. Can be a pandas.Series or pandas.DataFrame.
  • test_size: Proportion of the dataset to use as the test set (default is 0.2).

Returns

  • If y is provided, returns four objects:

    • X_train: Training features.
    • X_test: Testing features.
    • y_train: Training targets.
    • y_test: Testing targets.

    All returned as numpy.ndarray or pandas.DataFrame/pandas.Series.

  • If y is not provided, returns two objects:

    • X_train: Training features.
    • X_test: Testing features.

    Both returned as numpy.ndarray or pandas.DataFrame.

Example

Here's how you can use the split_ts function:

import pandas as pd
from time_series_split import split_ts

# Sample DataFrame
data = {'date': [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009],
        'value': [5, 6, 8, 7, 10, 12, 13, 14, 15, 16]}
df = pd.DataFrame(data)

# Splitting data with target
X_train, X_test, y_train, y_test = split_ts(df['date'], df['value'], test_size=0.3)

# Splitting data
train, test = split_ts(df, test_size=0.3)

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

For any questions or support, please contact danttis.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

time_series_split-0.1.7.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

time_series_split-0.1.7-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file time_series_split-0.1.7.tar.gz.

File metadata

  • Download URL: time_series_split-0.1.7.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for time_series_split-0.1.7.tar.gz
Algorithm Hash digest
SHA256 d722cddcb1f9ae3928921bf201c8a233103b905383a8748613a7fae8d4f3d02a
MD5 1446d24fb8b3ddaa0d5e147e4c1497e4
BLAKE2b-256 0d6044b7c880b32a201a856447cee19de345e399bfca9e0d7cfe3675eb5d40c2

See more details on using hashes here.

File details

Details for the file time_series_split-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for time_series_split-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2a628dd74b4c114a8f16be4797d047b082470c62de9c449b3070bd22ef6eebf8
MD5 9a0f7150475e28b00058f11d5143ba7a
BLAKE2b-256 da8f2c9c96043a7b80c255e6e65d83784d63ea7686b685265c4d9d771bffe182

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page