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.6.tar.gz (3.1 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.6-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: time_series_split-0.1.6.tar.gz
  • Upload date:
  • Size: 3.1 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.6.tar.gz
Algorithm Hash digest
SHA256 11dbdd35dfc9844a5448bdd967fe5716dae70e1471ba2463a724815909753e06
MD5 7c12c49ff91bc2ca74136224ba69fb47
BLAKE2b-256 d6a49f2374dc42bc9f7f825a04a759a6edaf3290a66f8d3bab2eac297a2439be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for time_series_split-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b75b0c0021a14c59200405fcf6e52428a511a368f96ca474a370579fed9d19c1
MD5 e1df81e2350b0a58b96febb58b02f527
BLAKE2b-256 b994389f07877543a119b92b61e98c70bf1e34ab709d9005ddd0f119089d75bc

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