Time Series Dataset
Description
Time series dataset for Time series predictor
Installation
pip install time-series-dataset
Usage example
"""
FlightsDataset
"""
import calendar
import math
import numpy as np
import pandas as pd
import seaborn as sns
from datetime import datetime
from time_series_dataset import TimeSeriesDataset
def _raw_make_predictor(features, *reshape_args):
#pylint: disable=too-many-function-args
return np.concatenate(features, axis=-1).reshape(
list(reshape_args) + [len(features)]).astype(np.float32)
def _make_predictor(features, number_of_training_examples):
#pylint: disable=too-many-function-args
return _raw_make_predictor(features, number_of_training_examples, -1)
def _get_labels(input_features, output_features):
def _features_to_label_list(features):
return [list(feature)[0] for feature in features]
labels = {}
labels['x'] = _features_to_label_list(input_features)
labels['y'] = _features_to_label_list(output_features)
return labels
class FlightsDataset(TimeSeriesDataset):
"""
FlightsDataset class
:param except_last_n: initialize the FlightsDataset without n last months
"""
# pylint: disable=too-many-locals
def __init__(self, except_last_n=0):
flights_dataset = sns.load_dataset("flights")
chopped_flights_dataset = flights_dataset[:len(
flights_dataset)-except_last_n]
passengers = chopped_flights_dataset['passengers']
month = chopped_flights_dataset['month']
year = chopped_flights_dataset['year']
months_3l = [month_name[0:3]
for month_name in list(calendar.month_name)]
month_number = [months_3l.index(_month)
for _month in month]
passengers_df = pd.DataFrame(passengers)
month_number_df = pd.DataFrame(data={'month_number': month_number})
year_df = pd.DataFrame(year)
number_of_training_examples = 1
# Store month_number and year as _x
input_features = [month_number_df, year_df]
_x = _make_predictor(input_features, number_of_training_examples)
# Store passengers as _y
output_features = [passengers_df]
_y = _make_predictor(output_features, number_of_training_examples)
super().__init__(_x, _y, _get_labels(input_features, output_features))
self.month_number_df = month_number_df
self.year_df = year_df
# pylint: disable=arguments-differ
def make_future_dataframe(self, number_of_months, include_history=True):
"""
make_future_dataframe
:param number_of_months: number of months to predict ahead
:param include_history: optional, selects if training history is to be included or not
:returns: future dataframe with the selected amount of months
"""
def create_dataframe(name, data):
return pd.DataFrame(data={name: data})
def create_month_dataframe(data):
return create_dataframe('month_number', data)
def create_year_dataframe(data):
return create_dataframe('year', data)
month_number_df = self.month_number_df
year_df = self.year_df
last_month = month_number_df.values[-1][0]
last_year = year_df.values[-1][0]
if not include_history:
month_number_df = create_month_dataframe([])
year_df = create_year_dataframe([])
for i in range(number_of_months):
month_index = last_month+i
new_months = [math.fmod(month_index, 12)+1]
new_years = [last_year + math.floor(month_index / 12)]
month_number_df = month_number_df.append(
create_month_dataframe(new_months), ignore_index=True)
year_df = year_df.append(
create_year_dataframe(new_years), ignore_index=True)
input_features = [month_number_df, year_df]
return _make_predictor(input_features, 1)
def convert_year_month_array_to_datetime(year_month_array):
def convert_singe_year_month_array_to_datetime(single_year_month_array):
return datetime(year=single_year_month_array[1], month=single_year_month_array[0], day=15)
year_month_array_size = year_month_array.size
if year_month_array_size == 2:
return convert_singe_year_month_array_to_datetime(year_month_array)
return [convert_singe_year_month_array_to_datetime(year_month_array[idx, ...]) for idx in range(len(year_month_array))]
Oze dataset history
Metadata
Release files for time-series-dataset 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| time_series_dataset-0.0.9.tar.gz | 4.7 kB | Without provenance | Details for time_series_dataset-0.0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| time_series_dataset-0.0.9-py3-none-any.whl | Python 3 | none | any | Details for time_series_dataset-0.0.9-py3-none-any.whl |
Total release size: 9.4 kB
Release files / time_series_dataset-0.0.9.tar.gz
| Download URL | time_series_dataset-0.0.9.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
435d580255ae0529d117ee07c759fa446696f8e6383920c719ef5b0dc6227010
|
|
BLAKE2b-256 checksum How to use checksums |
dbc85b5bd28805f2de32e16205f48dbf2650f3746195e89507c3071502223fad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2
|
Release files / time_series_dataset-0.0.9-py3-none-any.whl
| Download URL | time_series_dataset-0.0.9-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d49c5469dfa7e539b6a6d5ca022962b9ea1104d1954c725236e7e414bb2b350e
|
|
BLAKE2b-256 checksum How to use checksums |
ca0df0a8cdf08d14d62af04f65bf46c52593c7f5b4e5b6273e4449a7d7f89f9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2
|
Security for time-series-dataset 0.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.