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.split_ts 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.8.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.8-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: time_series_split-0.1.8.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.8.tar.gz
Algorithm Hash digest
SHA256 17ef9f30688d449b422f6d434e7e93557f5d93e92de402e2aa91a0fd9e721585
MD5 3dd01d26d2b52ab8ad73aee4c9c2bfae
BLAKE2b-256 c62576877e63b2eccda3392c92a40f34dd75a3438f1bd2ec554ed4925ba4e7a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for time_series_split-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0c429d7cacd5fcc1df5c197dedcfddef11adff8a9afc9f6894694d304e35bf6a
MD5 0fd1e58b6a16c17296558e1c983b2daf
BLAKE2b-256 e76c36669ba8ec8cd48e40e68bc4e72138031582f2cfc3829924f85296236def

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