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 apandas.DataFrameorpandas.Series.y: (Optional) Target column corresponding to the features. Can be apandas.Seriesorpandas.DataFrame.test_size: Proportion of the dataset to use as the test set (default is 0.2).
Returns
-
If
yis provided, returns four objects:X_train: Training features.X_test: Testing features.y_train: Training targets.y_test: Testing targets.
All returned as
numpy.ndarrayorpandas.DataFrame/pandas.Series. -
If
yis not provided, returns two objects:X_train: Training features.X_test: Testing features.
Both returned as
numpy.ndarrayorpandas.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.
Metadata
Release files for time-series-split 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| time_series_split-0.1.8.tar.gz | 3.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| time_series_split-0.1.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.1 kB
Release files / time_series_split-0.1.8.tar.gz
| Download URL | time_series_split-0.1.8.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17ef9f30688d449b422f6d434e7e93557f5d93e92de402e2aa91a0fd9e721585
|
|
BLAKE2b-256 checksum How to use checksums |
c62576877e63b2eccda3392c92a40f34dd75a3438f1bd2ec554ed4925ba4e7a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.4
|
Release files / time_series_split-0.1.8-py3-none-any.whl
| Download URL | time_series_split-0.1.8-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0c429d7cacd5fcc1df5c197dedcfddef11adff8a9afc9f6894694d304e35bf6a
|
|
BLAKE2b-256 checksum How to use checksums |
e76c36669ba8ec8cd48e40e68bc4e72138031582f2cfc3829924f85296236def
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.4
|