### Install tsfresh
Source: https://tsfresh.readthedocs.io/en/latest/_sources/text/quick_start.rst.txt
Install the base package or the version with Dask support for large datasets.
```shell
pip install tsfresh
```
```shell
pip install tsfresh[dask]
```
--------------------------------
### Build HTML documentation
Source: https://tsfresh.readthedocs.io/en/latest/_sources/text/how_to_contribute.rst.txt
Install documentation dependencies and build the HTML documentation locally. The output will be in the docs/_build/html folder.
```bash
pip install -e ".[docs]"
cd docs
make html
```
--------------------------------
### Install tsfresh on Windows via Anaconda
Source: https://tsfresh.readthedocs.io/en/latest/_sources/text/faq.rst.txt
Commands to set up a dedicated environment and install tsfresh dependencies using the Anaconda Prompt.
```Bash
conda create -n ENV_NAME python=VERSION
conda install -n ENV_NAME pip requests numpy pandas scipy statsmodels patsy scikit-learn tqdm
activate ENV_NAME
pip install tsfresh
```
--------------------------------
### Install tsfresh with testing dependencies
Source: https://tsfresh.readthedocs.io/en/latest/_sources/text/how_to_contribute.rst.txt
Install tsfresh in editable mode with all testing dependencies. This command also installs pre-commit hooks for automated code styling and checks.
```bash
cd /path/to/tsfresh
pip install -e ".[testing]"
pre-commit install
```
--------------------------------
### Start and End Profiling
Source: https://tsfresh.readthedocs.io/en/latest/api/tsfresh.utilities.html
Helper functions to start and stop the Python profiler. Use start_profiling to begin and end_profiling to save results to a file.
```python
profiler = start_profiling()
# Do something you want to profile
end_profiling(profiler, "out.txt", "cumulative")
```
```python
profiler = start_profiling()
# Do something you want to profile
end_profiling(profiler, "cumulative", "out.txt")
```
--------------------------------
### Use MinimalFCParameters for Quick Tests
Source: https://tsfresh.readthedocs.io/en/latest/api/tsfresh.feature_extraction.html
Instantiate MinimalFCParameters for rapid testing of your setup. This class calculates only a small subset of features, significantly reducing extraction time.
```python
from tsfresh.feature_extraction import extract_features, MinimalFCParameters
extract_features(df, default_fc_parameters=MinimalFCParameters())
```
--------------------------------
### Get Configuration from String
Source: https://tsfresh.readthedocs.io/en/latest/api/tsfresh.utilities.html
Extracts configuration parameters from a string, typically a column name, by splitting it into parts.
```python
tsfresh.utilities.string_manipulation.get_config_from_string(_parts_)
```
--------------------------------
### Profiling Utilities
Source: https://tsfresh.readthedocs.io/en/latest/api/tsfresh.utilities.html
Functions for starting, stopping, and managing the profiler to measure the runtime of feature calculators.
```APIDOC
## tsfresh.utilities.profiling module
Contains methods to start and stop the profiler that checks the runtime of the different feature calculators.
### `end_profiling(profiler, filename, sorting=None)`
#### Description
Helper function to stop the profiling process and write out the profiled data into the given filename. Before this, sort the stats by the passed sorting.
Parameters:
- **profiler** (cProfile.Profile) – An already started profiler (probably by start_profiling).
- **filename** (basestring) – The name of the output file to save the profile.
- **sorting** (basestring) – The sorting of the statistics passed to the sort_stats function.
Returns:
None
### `get_n_jobs()`
#### Description
Get the number of jobs to use for parallel processing.
Returns:
The number of jobs to use for parallel processing.
Return type:
int
### `set_n_jobs(n_jobs)`
#### Description
Set the number of jobs to use for parallel processing.
Parameters:
- **n_jobs** (int) – The number of jobs to use for parallel processing.
Returns:
None
### `start_profiling()`
#### Description
Helper function to start the profiling process and return the profiler (to close it later).
Returns:
a started profiler.
Return type:
cProfile.Profile
### Example Usage
```python
profiler = start_profiling()
# Do something you want to profile
end_profiling(profiler, "out.txt", "cumulative")
```
```
--------------------------------
### Run tests across multiple Python versions with tox
Source: https://tsfresh.readthedocs.io/en/latest/_sources/text/how_to_contribute.rst.txt
Use tox to run tests across different Python versions specified in setup.cfg. Ensure Python versions are installed locally.
```bash
tox -r -p auto
```
--------------------------------
### Local Multiprocessing Feature Extraction
Source: https://tsfresh.readthedocs.io/en/latest/text/tsfresh_on_a_cluster.html
This example demonstrates how to set up and use the MultiprocessingDistributor to distribute feature extraction tasks across multiple threads on a local machine. It includes downloading and loading sample data.
```python
from tsfresh.examples.robot_execution_failures import \
download_robot_execution_failures, \
load_robot_execution_failures
from tsfresh.feature_extraction import extract_features
from tsfresh.utilities.distribution import MultiprocessingDistributor
# download and load some time series data
download_robot_execution_failures()
df, y = load_robot_execution_failures()
# We construct a Distributor that will spawn the calculations
# over four threads on the local machine
Distributor = MultiprocessingDistributor(n_workers=4,
disable_progressbar=False,
progressbar_title="Feature Extraction")
# just to pass the Distributor object to
```
--------------------------------
### Define MultiprocessingDistributor for Local Calculations
Source: https://tsfresh.readthedocs.io/en/latest/_sources/text/tsfresh_on_a_cluster.rst.txt
This example demonstrates how to set up a MultiprocessingDistributor to distribute feature extraction calculations across a local pool of threads. It includes downloading and loading sample data.
```python
from tsfresh.examples.robot_execution_failures import \
download_robot_execution_failures, \
load_robot_execution_failures
from tsfresh.feature_extraction import extract_features
from tsfresh.utilities.distribution import MultiprocessingDistributor
# download and load some time series data
download_robot_execution_failures()
df, y = load_robot_execution_failures()
# We construct a Distributor that will spawn the calculations
```
--------------------------------
### Parallel Feature Calculation Setup
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/feature_selection/relevance.html
Sets up parallel processing for feature calculation using `multiprocessing.Pool`. It configures the `map_function` to use either the standard `map` or the pool's `map` with specified `chunksize` and `n_jobs`. Worker initialization includes handling warnings.
```python
if n_jobs == 0 or n_jobs == 1:
map_function = map
else:
pool = Pool(
processes=n_jobs,
initializer=initialize_warnings_in_workers,
initargs=(show_warnings,),
)
map_function = partial(pool.map, chunksize=chunksize)
```
--------------------------------
### Implement a simple feature calculator
Source: https://tsfresh.readthedocs.io/en/latest/_sources/text/how_to_add_custom_feature.rst.txt
Use the 'simple' fctype to return a single feature value. This example shows the basic structure without parameters.
```python
from tsfresh.feature_extraction.feature_calculators import set_property
@set_property("fctype", "simple")
def your_feature_calculator(x):
"""
The description of your feature
:param x: the time series to calculate the feature of
:type x: pandas.Series
:return: the value of this feature
:return type: bool, int or float
"""
# Calculation of feature as float, int or bool
result = f(x)
return result
```
--------------------------------
### FeatureAugmenter Usage Example
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/transformers/feature_augmenter.html
Demonstrates how to use the FeatureAugmenter to add time series features to a DataFrame. It requires setting the time series container before transforming the input DataFrame.
```python
>>> df = pandas.DataFrame(index=["AAA", "BBB", ...])
>>> # Fill in the information of the stocks
>>> df["started_since_days"] = ... # add a feature
>>> time_series = read_in_timeseries() # get the development of the shares
>>> from tsfresh.transformers import FeatureAugmenter
>>> augmenter = FeatureAugmenter(column_id="id")
>>> augmenter.set_timeseries_container(time_series)
>>> df_with_time_series_features = augmenter.transform(df)
```
--------------------------------
### Initialize ComprehensiveFCParameters
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/feature_extraction/settings.html
Demonstrates how to import and use the ComprehensiveFCParameters class to extract all default features.
```python
>>> from tsfresh.feature_extraction import extract_features, ComprehensiveFCParameters
>>> extract_features(df, default_fc_parameters=ComprehensiveFCParameters())
```
--------------------------------
### Initialize stock data structures
Source: https://tsfresh.readthedocs.io/en/latest/api/tsfresh.transformers.html
Prepare empty dataframes and series for stock information and target variables.
```python
>>> # Fill in the information of the stocks and the target
>>> X_train, X_test, y_train = pd.DataFrame(), pd.DataFrame(), pd.Series()
```
--------------------------------
### Profile code execution
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/utilities/profiling.html
Use start_profiling to initialize a profiler and end_profiling to stop it and write the statistics to a file.
```python
>>> profiler = start_profiling()
>>> # Do something you want to profile
>>> end_profiling(profiler, "cumulative", "out.txt")
```
```python
>>> profiler = start_profiling()
>>> # Do something you want to profile
>>> end_profiling(profiler, "out.txt", "cumulative")
```
--------------------------------
### GET /features/maximum
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/feature_extraction/feature_calculators.html
Calculates the maximum value in a time series.
```APIDOC
## GET /features/maximum
### Description
Calculates the highest value of the time series x.
### Method
GET
### Endpoint
/features/maximum
### Parameters
#### Query Parameters
- **x** (numpy.ndarray) - Required - The time series to calculate the feature of
### Response
#### Success Response (200)
- **value** (float) - The maximum value
```
--------------------------------
### Initialize and use RelevantFeatureAugmenter
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/transformers/relevant_feature_augmenter.html
Demonstrates the workflow of setting the time series container, fitting the transformer on training data, and transforming test data to include relevant features.
```python
>>> # Fill in the information of the stocks and the target
>>> X_train, X_test, y_train = pd.DataFrame(), pd.DataFrame(), pd.Series()
>>> train_time_series, test_time_series = read_in_timeseries() # get the development of the shares
>>> from tsfresh.transformers import RelevantFeatureAugmenter
>>> augmenter = RelevantFeatureAugmenter()
>>> augmenter.set_timeseries_container(train_time_series)
>>> augmenter.fit(X_train, y_train)
>>> augmenter.set_timeseries_container(test_time_series)
>>> X_test_with_features = augmenter.transform(X_test)
```
--------------------------------
### GET /features/quantile
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/feature_extraction/feature_calculators.html
Calculates the q-th quantile of a time series.
```APIDOC
## GET /features/quantile
### Description
Calculates the q quantile of x, representing the value greater than q% of the ordered values in the series.
### Method
GET
### Endpoint
/features/quantile
### Parameters
#### Query Parameters
- **x** (numpy.ndarray) - Required - The time series to calculate the feature of
- **q** (float) - Required - The quantile to calculate
### Response
#### Success Response (200)
- **value** (float) - The quantile value
```
--------------------------------
### Initialize input DataFrame
Source: https://tsfresh.readthedocs.io/en/latest/api/tsfresh.transformers.html
Create a pandas DataFrame with an index representing entities like stock names to hold initial features.
```python
>>> df = pandas.DataFrame(index=["AAA", "BBB", ...])
>>> # Fill in the information of the stocks
>>> df["started_since_days"] = ... # add a feature
```
--------------------------------
### GET /features/autocorrelation
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/feature_extraction/feature_calculators.html
Calculates the autocorrelation of a time series for a specified lag.
```APIDOC
## GET /features/autocorrelation
### Description
Calculates the autocorrelation of the specified lag based on the variance and mean of the time series.
### Method
GET
### Endpoint
/features/autocorrelation
### Parameters
#### Query Parameters
- **x** (numpy.ndarray) - Required - The time series to calculate the feature of
- **lag** (int) - Required - The lag value
### Response
#### Success Response (200)
- **value** (float) - The autocorrelation value
```
--------------------------------
### Initialize Dissipative Soliton Velocity Simulation
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/examples/driftbif_simulation.html
Initializes a dissipative soliton velocity simulation with specified parameters. Use this to set up the simulation environment before generating time series data.
```python
ds = velocity(tau=3.5) # Dissipative soliton with equilibrium velocity 1.5e-3
```
--------------------------------
### Get Number of Parallel Jobs
Source: https://tsfresh.readthedocs.io/en/latest/api/tsfresh.utilities.html
Retrieves the number of jobs configured for parallel processing in tsfresh.
```python
tsfresh.utilities.profiling.get_n_jobs()
```
--------------------------------
### Run unit tests
Source: https://tsfresh.readthedocs.io/en/latest/text/how_to_contribute.html
Execute the test suite using pytest or tox for multi-version testing.
```bash
pytest
```
```bash
tox -r -p auto
```
--------------------------------
### Get IDs
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/utilities/dataframe_functions.html
Aggregates all unique IDs from a specified ID column in a DataFrame or a dictionary of DataFrames.
```APIDOC
## Get IDs
### Description
Aggregates all unique IDs from the `column_id` in the time series container (`df_or_dict`). The `column_id` must be present and not contain NaN values.
### Method
`get_ids(df_or_dict, column_id)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **df_or_dict** (pandas.DataFrame or dict) - The DataFrame or dictionary of DataFrames to extract IDs from.
- **column_id** (str) - The name of the column containing the IDs.
### Request Example
```python
# Assuming df is a pandas DataFrame and column_id is 'id'
get_ids(df, 'id')
# Assuming data_dict is a dictionary of DataFrames and column_id is 'id'
get_ids(data_dict, 'id')
```
### Response
#### Success Response (200)
- **set**: A set containing all unique IDs found in the specified column.
#### Response Example
```json
{
"example": "{'id1', 'id2', 'id3'}"
}
```
```
--------------------------------
### GET /features/number_crossing_m
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/feature_extraction/feature_calculators.html
Calculates the number of times a time series crosses a specific threshold value m.
```APIDOC
## GET /features/number_crossing_m
### Description
Calculates the number of crossings of x on m, where a crossing is defined as two sequential values where the first is lower than m and the next is greater, or vice-versa.
### Method
GET
### Endpoint
/features/number_crossing_m
### Parameters
#### Query Parameters
- **x** (numpy.ndarray) - Required - The time series to calculate the feature of
- **m** (float) - Required - The threshold for the crossing
### Response
#### Success Response (200)
- **value** (int) - The number of crossings
```
--------------------------------
### Initialize custom feature extraction settings
Source: https://tsfresh.readthedocs.io/en/latest/_sources/text/feature_extraction_settings.rst.txt
Use ComprehensiveFCParameters to create a base object for customizing feature extraction parameters.
```python
>>> from tsfresh.feature_extraction import ComprehensiveFCParameters
>>> settings = ComprehensiveFCParameters()
>>> # Set here the options of the settings object as shown in the paragraphs below
>>> # ...
>>> from tsfresh.feature_extraction import extract_features
>>> extract_features(df, default_fc_parameters=settings)
```
--------------------------------
### Parallel Processing Configuration API
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/utilities/profiling.html
Functions to get and set the number of jobs for parallel processing in tsfresh.
```APIDOC
## get_n_jobs
### Description
Get the number of jobs to use for parallel processing.
### Method
N/A (Python function)
### Endpoint
N/A
### Parameters
None
### Request Example
```python
n_jobs = get_n_jobs()
print(f"Number of jobs: {n_jobs}")
```
### Response
#### Success Response
- **n_jobs** (int) - The number of jobs to use for parallel processing.
#### Response Example
```python
4
```
## set_n_jobs
### Description
Set the number of jobs to use for parallel processing.
### Method
N/A (Python function)
### Endpoint
N/A
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Parameters
- **n_jobs** (int) - Required - The number of jobs to use for parallel processing.
### Request Example
```python
set_n_jobs(8)
```
### Response
#### Success Response (None)
- None
#### Response Example
None
```
--------------------------------
### Simple Feature Calculator (With Parameters)
Source: https://tsfresh.readthedocs.io/en/latest/text/how_to_add_custom_feature.html
Create a simple feature calculator that accepts parameters. The `@set_property` decorator should be set to 'simple'. Parameters are passed directly to the function.
```python
@set_property("fctype", "simple"")
def your_feature_calculator(x, p1, p2, ...):
"""
Description of your feature
:param x: the time series to calculate the feature of
:type x: pandas.Series
:param p1: description of your parameter p1
:type p1: type of your parameter p1
:param p2: description of your parameter p2
:type p2: type of your parameter p2
...
:return: the value of this feature
:return type: bool, int or float
"""
# Calculation of feature as float, int or bool
f = f(x)
return f
```
--------------------------------
### GET /include_function
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/feature_extraction/settings.html
Determines if a specific feature calculator function should be included based on exclusion attributes and dependency availability.
```APIDOC
## GET /include_function
### Description
Checks if a function meets the criteria for inclusion in the feature extraction process, specifically checking for the 'fctype' attribute and dependency availability.
### Method
GET
### Endpoint
/include_function
### Parameters
#### Query Parameters
- **func** (object) - Required - The function to test.
- **exclusion_attr** (str) - Optional - The attribute name to use as an exclusion criterion (default: 'input_type').
### Response
#### Success Response (200)
- **included** (bool) - True if the function matches inclusion criteria, False otherwise.
```
--------------------------------
### DaskTsAdapter Initialization
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/feature_extraction/data.html
Initializes the DaskTsAdapter to prepare Dask DataFrames for time series processing.
```APIDOC
## __init__
### Description
Initializes the adapter, handles column identification, and performs melting if the data is in wide format.
### Parameters
#### Request Body
- **df** (DataFrame) - Required - The Dask DataFrame containing the time series data.
- **column_id** (str) - Required - The name of the column identifying the time series.
- **column_kind** (str) - Optional - The name of the column identifying the kind of time series.
- **column_value** (str) - Optional - The name of the column containing the values.
- **column_sort** (str) - Optional - The name of the column to sort on.
```
--------------------------------
### Feature Extraction Functions
Source: https://tsfresh.readthedocs.io/en/latest/genindex.html
This section lists various feature extraction functions available in tsfresh, categorized by their starting letter.
```APIDOC
## Feature Extraction Functions (F)
### Description
Provides access to feature calculation functions and related classes.
### Functions
- `fft_aggregated()`
- `fft_coefficient()`
- `first_location_of_maximum()`
- `first_location_of_minimum()`
- `fourier_entropy()`
- `friedrich_coefficients()`
### Classes
- `FeatureAugmenter`
- `FeatureSelector`
- `FullTimingTask`
### Methods
- `fit()` (available in `FeatureAugmenter`, `FeatureSelector`, `PerColumnImputer`, `RelevantFeatureAugmenter`)
- `fit_transform()` (available in `RelevantFeatureAugmenter`)
### Other
- `feature_parameter` (attribute of `TimingTask`)
- `from_columns()` (in `tsfresh.feature_extraction.settings`)
```
```APIDOC
## Utility Functions (G)
### Description
Contains utility functions for configuration, data handling, and profiling.
### Functions
- `get_config_from_string()`
- `get_feature_type()`
- `get_ids()`
- `get_n_jobs()`
- `get_range_values_per_column()`
```
```APIDOC
## Duplicate Checking Functions (H)
### Description
Functions to check for duplicate values within time series data.
### Functions
- `has_duplicate()`
- `has_duplicate_max()`
- `has_duplicate_min()`
```
```APIDOC
## Imputation and Initialization Functions (I)
### Description
Provides functions for data imputation and initialization of warnings.
### Functions
- `impute()`
- `impute_dataframe_range()`
- `impute_dataframe_zero()`
- `include_function()`
- `initialize_warnings_in_workers()`
### Classes
- `IndexBasedFCParameters`
- `IterableDistributorBaseClass`
### Other
- `index_mass_quantile()`
- `infer_ml_task()`
```
```APIDOC
## Kurtosis Calculation (K)
### Description
Calculates the kurtosis of a time series.
### Function
- `kurtosis()`
```
```APIDOC
## Time Series Analysis Functions (L)
### Description
Includes functions for analyzing time series data, such as trend, strike, and complexity calculations, as well as data loading utilities.
### Functions
- `large_standard_deviation()`
- `last_location_of_maximum()`
- `last_location_of_minimum()`
- `lempel_ziv_complexity()`
- `length()`
- `linear_trend()`
- `linear_trend_timewise()`
- `longest_strike_above_mean()`
- `longest_strike_below_mean()`
### Data Loading Functions
- `load_driftbif()`
- `load_har_classes()`
- `load_har_dataset()`
- `load_robot_execution_failures()`
### Classes
- `LocalDaskDistributor`
- `LongTsFrameAdapter`
```
--------------------------------
### GET /features/permutation_entropy
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/feature_extraction/feature_calculators.html
Calculates the permutation entropy of a time series, which measures the complexity of the data based on ordinal rankings of sub-windows.
```APIDOC
## GET /features/permutation_entropy
### Description
Calculates the permutation entropy of a time series by chunking data into sub-windows, determining ordinal rankings, and calculating the entropy of the resulting permutation frequencies.
### Method
GET
### Endpoint
/features/permutation_entropy
### Parameters
#### Query Parameters
- **x** (numpy.ndarray) - Required - The time series to calculate the feature of
- **tau** (int) - Required - The time delay between sub-windows
- **dimension** (int) - Required - The length of the sub-windows (D)
### Response
#### Success Response (200)
- **value** (float) - The calculated permutation entropy
```
--------------------------------
### Get Range Values Per Column
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/utilities/dataframe_functions.html
Retrieves the finite max, min, and median values per column in a DataFrame.
```APIDOC
## Get Range Values Per Column
### Description
Retrieves the finite max, min, and median values per column in the DataFrame `df` and stores them in three dictionaries. If a column does not contain any finite values, a 0 is stored instead.
### Method
`get_range_values_per_column(df)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **df** (pandas.DataFrame) - The DataFrame to get columnswise max, min, and median from.
### Request Example
```python
# Assuming df is a pandas DataFrame
get_range_values_per_column(df)
```
### Response
#### Success Response (200)
- **tuple**: A tuple containing three dictionaries: `col_to_max`, `col_to_min`, `col_to_median`.
#### Response Example
```json
{
"example": "(col_to_max_dict, col_to_min_dict, col_to_median_dict)"
}
```
```
--------------------------------
### tsfresh.examples.driftbif_simulation.load_driftbif
Source: https://tsfresh.readthedocs.io/en/latest/api/tsfresh.examples.html
Simulates time-series data for the drift-bifurcation simulation, with options for classification or regression targets.
```APIDOC
## tsfresh.examples.driftbif_simulation.load_driftbif
### Description
Simulates n time-series with length time steps each for the m-dimensional velocity of a dissipative soliton.
- classification=True: target 0 means tau<=1/0.3, Dissipative Soliton with Brownian motion (purely noise driven) target 1 means tau> 1/0.3, Dissipative Soliton with Active Brownian motion (intrinsiv velocity with overlaid noise)
- classification=False: target is bifurcation parameter tau
### Method
N/A (Function)
### Endpoint
N/A (Function)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
- **X** (pandas.DataFrame) - Time series container
- **y** (pandas.DataFrame) - Target vector
#### Response Example
None
```
--------------------------------
### FeatureSelector Fit Example
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/transformers/feature_selector.html
Fit the FeatureSelector on training data to identify relevant features. The relevant_features attribute will be populated after fitting.
```python
>>> import pandas as pd
>>> X_train, y_train = pd.DataFrame(), pd.Series() # fill in with your features and target
>>> from tsfresh.transformers import FeatureSelector
>>> selector = FeatureSelector()
>>> selector.fit(X_train, y_train)
```
--------------------------------
### Convert Dask DataFrame to TsData
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/feature_extraction/data.html
Adapts a Dask DataFrame to the TsData format using DaskTsAdapter. Requires Dask to be installed and imported.
```python
elif dd and isinstance(df, dd.DataFrame):
return DaskTsAdapter(df, column_id, column_kind, column_value, column_sort)
```
--------------------------------
### Run all tests in a Dockerized environment
Source: https://tsfresh.readthedocs.io/en/latest/_sources/text/how_to_contribute.rst.txt
Execute all tests within a clean and consistent Dockerized environment. This command may take longer on the first run.
```bash
make test-all-testenv
```
--------------------------------
### Initialize TimeBasedFCParameters
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/feature_extraction/settings.html
Initializes TimeBasedFCParameters, a child class of ComprehensiveFCParameters. It includes only features requiring a DatetimeIndex and drops computationally expensive ones.
```python
class TimeBasedFCParameters(ComprehensiveFCParameters):
"""
This class is a child class of the ComprehensiveFCParameters class
and has the same functionality as its base class.
The only difference is, that only the features that require a DatetimeIndex are included. Those
have an attribute "index_type" with value pd.DatetimeIndex.
"""
def __init__(self):
ComprehensiveFCParameters.__init__(self)
# drop all features with high computational costs
for fname, f in feature_calculators.__dict__.items():
if fname in self and getattr(f, "index_type", False) != pd.DatetimeIndex:
del self[fname]
```
--------------------------------
### Get Dissipative Soliton Label
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/examples/driftbif_simulation.html
Retrieves the label indicating whether the dissipative soliton is before or beyond the drift bifurcation. This is determined by the 'tau' parameter relative to 'kappa_3'.
```python
print(ds.label) # Discriminating before or beyond Drift-Bifurcation
```
--------------------------------
### FeatureSelector Initialization Parameters
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/transformers/feature_selector.html
Initialize the FeatureSelector with various parameters controlling statistical tests, FDR level, parallel processing, and machine learning task type.
```python
def __init__(
self,
test_for_binary_target_binary_feature=defaults.TEST_FOR_BINARY_TARGET_BINARY_FEATURE,
test_for_binary_target_real_feature=defaults.TEST_FOR_BINARY_TARGET_REAL_FEATURE,
test_for_real_target_binary_feature=defaults.TEST_FOR_REAL_TARGET_BINARY_FEATURE,
test_for_real_target_real_feature=defaults.TEST_FOR_REAL_TARGET_REAL_FEATURE,
fdr_level=defaults.FDR_LEVEL,
hypotheses_independent=defaults.HYPOTHESES_INDEPENDENT,
n_jobs=defaults.N_PROCESSES,
chunksize=defaults.CHUNKSIZE,
ml_task="auto",
multiclass=False,
n_significant=1,
multiclass_p_values="min",
):
```
--------------------------------
### Configure Minimal Feature Extraction
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/feature_extraction/settings.html
Use MinimalFCParameters for quick testing by calculating only a small subset of features.
```python
>>> from tsfresh.feature_extraction import extract_features, MinimalFCParameters
>>> extract_features(df, default_fc_parameters=MinimalFCParameters())
```
--------------------------------
### Sum of Reoccurring Values
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/feature_extraction/feature_calculators.html
Calculates the sum of all values that appear more than once in the time series. For example, sum_of_reoccurring_values([2, 2, 2, 2, 1]) returns 2.
```python
import numpy as np
def sum_of_reoccurring_values(x):
"""
Returns the sum of all values, that are present in the time series
more than once.
For example
sum_of_reoccurring_values([2, 2, 2, 2, 1]) = 2
as 2 is a reoccurring value, so it is summed up with all
```
--------------------------------
### Implement a simple feature calculator with parameters
Source: https://tsfresh.readthedocs.io/en/latest/_sources/text/how_to_add_custom_feature.rst.txt
Define a simple feature calculator that accepts additional parameters for calculation.
```python
@set_property("fctype", "simple"")
def your_feature_calculator(x, p1, p2, ...):
"""
Description of your feature
:param x: the time series to calculate the feature of
:type x: pandas.Series
:param p1: description of your parameter p1
:type p1: type of your parameter p1
:param p2: description of your parameter p2
:type p2: type of your parameter p2
...
:return: the value of this feature
:return type: bool, int or float
"""
# Calculation of feature as float, int or bool
f = f(x)
return f
```
--------------------------------
### Generate Sample DataFrame
Source: https://tsfresh.readthedocs.io/en/latest/text/forecasting.html
Use this code to create a sample DataFrame in the tsfresh suitable format for demonstrating the rolling mechanism.
```python
import pandas as pd
df = pd.DataFrame({
"id": [1, 1, 1, 1, 2, 2],
"time": [1, 2, 3, 4, 8, 9],
"x": [1, 2, 3, 4, 10, 11],
"y": [5, 6, 7, 8, 12, 13],
})
```
--------------------------------
### FeatureSelector Transform Example
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/transformers/feature_selector.html
Transform test data using a fitted FeatureSelector to remove irrelevant features. The output X_selected will only contain features identified as relevant during the fit step.
```python
>>> X_test = pd.DataFrame()
>>> X_selected = selector.transform(X_test)
```
--------------------------------
### tsfresh.examples.driftbif_simulation.sample_tau
Source: https://tsfresh.readthedocs.io/en/latest/api/tsfresh.examples.html
Generates a list of control parameters (tau) for sampling around the drift-bifurcation point.
```APIDOC
## tsfresh.examples.driftbif_simulation.sample_tau
### Description
Return list of control parameters.
### Method
N/A (Function)
### Endpoint
N/A (Function)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
- **tau** (list) - List of sampled bifurcation parameter
#### Response Example
None
```
--------------------------------
### PickableSettings
Source: https://tsfresh.readthedocs.io/en/latest/api/tsfresh.feature_extraction.html
Base object for all settings, which is a pickable dictionary that uses cloudpickle for enhanced pickling capabilities.
```APIDOC
## Class PickableSettings
### Description
This is the base class for all settings objects in tsfresh. It extends Python's `UserDict` and provides enhanced pickling capabilities using `cloudpickle`. This allows for easier transportation of settings, especially when they include functions, across different processes or environments.
### Initialization
```python
from tsfresh.feature_extraction.settings import PickableSettings
settings_obj = PickableSettings({'feature_name': [{'param': 'value'}]})
```
### Parameters
- `_dict` (dict, optional): Initial dictionary to populate the settings object.
- `**kwargs`: Keyword arguments to initialize the dictionary.
```
--------------------------------
### tsfresh.examples.har_dataset.download_har_dataset
Source: https://tsfresh.readthedocs.io/en/latest/api/tsfresh.examples.html
Downloads the Human Activity Recognition dataset from the UCI ML Repository.
```APIDOC
## tsfresh.examples.har_dataset.download_har_dataset
### Description
Download human activity recognition dataset from UCI ML Repository and store it at /tsfresh/notebooks/data.
### Method
N/A (Function)
### Endpoint
N/A (Function)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```python
from tsfresh.examples import har_dataset
har_dataset.download_har_dataset()
```
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### FeatureAugmenter Initialization
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/transformers/feature_augmenter.html
Initializes the FeatureAugmenter with various parameters to control feature calculation, column identification, and processing options. Defaults are used if parameters are not specified.
```python
def __init__(
self,
default_fc_parameters=None,
kind_to_fc_parameters=None,
column_id=None,
column_sort=None,
column_kind=None,
column_value=None,
timeseries_container=None,
chunksize=tsfresh.defaults.CHUNKSIZE,
n_jobs=tsfresh.defaults.N_PROCESSES,
show_warnings=tsfresh.defaults.SHOW_WARNINGS,
disable_progressbar=tsfresh.defaults.DISABLE_PROGRESSBAR,
impute_function=tsfresh.defaults.IMPUTE_FUNCTION,
profile=tsfresh.defaults.PROFILING,
profiling_filename=tsfresh.defaults.PROFILING_FILENAME,
profiling_sorting=tsfresh.defaults.PROFILING_SORTING,
):
"""
Create a new FeatureAugmenter instance.
:param default_fc_parameters: mapping from feature calculator names to parameters. Only those names
which are keys in this dict will be calculated. See the class:`ComprehensiveFCParameters` for
more information.
:type default_fc_parameters: dict
:param kind_to_fc_parameters: mapping from kind names to objects of the same type as the ones for
default_fc_parameters. If you put a kind as a key here, the fc_parameters
object (which is the value), will be used instead of the default_fc_parameters. This means that kinds,
for which kind_of_fc_parameters doe not have any entries, will be ignored by the feature selection.
:type kind_to_fc_parameters: dict
:param column_id: The column with the id. See :mod:`~tsfresh.feature_extraction.extraction`.
```
--------------------------------
### Plot Feature Extraction Timing Results
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/scripts/test_timing.html
This function plots the results of feature extraction timing tests. It reads timing data from .dat files, calculates mean durations, and plots the results and speedup against a baseline. Requires matplotlib to be installed.
```python
def plot_results():
from matplotlib import pyplot as plt
plt.figure(figsize=(7, 7))
baseline = (
pd.read_csv("a57a09fe62a62fe0d2564a056f7fd99f58822312.dat")
.groupby("length")
.duration.mean()
)
for file_name in glob("*.dat"):
df = pd.read_csv(file_name).groupby("length").duration.mean()
plt.subplot(211)
df.plot(label=file_name.replace(".dat", ""))
plt.subplot(212)
(baseline / df).plot(label=file_name.replace(".dat", ""))
plt.subplot(211)
plt.xlabel("DataFrame Length")
plt.ylabel("Extract Features Mean Duration")
plt.legend()
plt.subplot(212)
plt.xlabel("DataFrame Length")
plt.ylabel("Speedup")
plt.gca().axhline(1, color="black", ls="--")
plt.legend()
plt.savefig("timing.png")
```
--------------------------------
### Measure Temporal Complexity of Feature Extraction
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/scripts/test_timing.html
This function measures the temporal complexity of tsfresh's feature extraction. It downloads robot execution failure data, extracts features for various DataFrame lengths, and saves the timing results to a .dat file named after the current git commit hash. Ensure git is installed and accessible.
```python
def measure_temporal_complexity():
from tsfresh.examples.robot_execution_failures import (
download_robot_execution_failures,
load_robot_execution_failures,
)
download_robot_execution_failures()
df, y = load_robot_execution_failures()
commit_hash = (
check_output(["git", "log", '--format="%H"', "-1"])
.decode("ascii")
.strip()
.replace('"', "")
)
lengths_to_test = [1, 5, 10, 60, 100, 400, 600, 1000, 2000]
results = []
for length in lengths_to_test:
results.append(simulate_with_length(length, df))
results.append(simulate_with_length(length, df))
results.append(simulate_with_length(length, df))
results = pd.DataFrame(results)
results.to_csv("{hash}.dat".format(hash=commit_hash))
```
--------------------------------
### tsfresh.feature_extraction.settings Module
Source: https://tsfresh.readthedocs.io/en/latest/_sources/api/tsfresh.feature_extraction.rst.txt
Documentation for the settings submodule, likely used for configuring feature extraction.
```APIDOC
## tsfresh.feature_extraction.settings Module
### Description
This submodule is used for managing and configuring the settings related to feature extraction in tsfresh.
### Members
- **settings** (module) - The settings submodule.
- **members**: Lists all members of the module.
- **undoc-members**: Includes undocumented members.
- **show-inheritance**: Shows inheritance information.
```
--------------------------------
### from_columns
Source: https://tsfresh.readthedocs.io/en/latest/api/tsfresh.feature_extraction.html
Creates a feature settings mapping from a list of column names.
```APIDOC
## Function from_columns
### Description
This utility function creates a feature settings dictionary (mapping feature names to parameters) based on a provided list of column names. It parses the column names to identify the feature calculator and its parameters, allowing you to extract only the features present in the specified columns.
### Parameters
- **columns** (*list* of *str*) – A list of strings, where each string is a feature name (potentially with parameters) extracted by tsfresh.
- **columns_to_ignore** (*list* of *str*, optional) – A list of column names that should be ignored and not parsed for feature settings.
### Returns
A dictionary mapping feature calculator names to their respective parameter settings, suitable for use with `extract_features`.
```
--------------------------------
### Initialize DaskTsAdapter
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/feature_extraction/data.html
Initializes the adapter with a Dask DataFrame, specifying ID, kind, value, and sort columns. Handles both long and wide format data by melting wide data if necessary.
```python
class DaskTsAdapter(TsData):
def __init__(
self, df, column_id, column_kind=None, column_value=None, column_sort=None
):
if column_id is None:
raise ValueError("column_id must be set")
if column_id not in df.columns:
raise ValueError(f"Column not found: {column_id}")
# Get all columns, which are not id, kind or sort
possible_value_columns = _get_value_columns(
df, column_id, column_sort, column_kind
)
# The user has already a kind column. That means we just need to group by id (and additionally by id)
if column_kind is not None:
if column_kind not in df.columns:
raise ValueError(f"Column not found: {column_kind}")
self.df = df.groupby([column_id, column_kind])
# We assume the last remaining column is the value - but there needs to be one!
if column_value is None:
if len(possible_value_columns) != 1:
raise ValueError(
"Could not guess the value column! Please hand it to the function as an argument."
)
column_value = possible_value_columns[0]
else:
# Ok, the user has no kind, so it is in Wide format.
# That means we have do melt before we can group.
# TODO: here is some room for optimization!
# we could choose the same way as for the Wide and LongTsAdapter
# We first choose a name for our future kind column
column_kind = "kind"
# if the user has specified a value column, use it
# if not, just go with every remaining columns
if column_value is not None:
value_vars = [column_value]
else:
value_vars = possible_value_columns
column_value = "value"
# Make sure we are not reusing a column that already exists
while column_value in df.columns:
column_value += "_"
_check_colname(*value_vars)
id_vars = [column_id, column_sort] if column_sort else [column_id]
# Now melt and group
df_melted = df.melt(
id_vars=id_vars,
value_vars=value_vars,
var_name=column_kind,
value_name=column_value,
)
self.df = df_melted.groupby([column_id, column_kind])
self.column_id = column_id
self.column_kind = column_kind
self.column_value = column_value
self.column_sort = column_sort
```
--------------------------------
### String Manipulation Utilities
Source: https://tsfresh.readthedocs.io/en/latest/api/tsfresh.utilities.html
Helper functions for converting parameters to string formats suitable for column names and extracting configuration from column names.
```APIDOC
## tsfresh.utilities.string_manipulation module
### `convert_to_output_format(param)`
#### Description
Helper function to convert parameters to a valid string, that can be used in a column name. Does the opposite which is used in the from_columns function. The parameters are sorted by their name and written out in the form `______ …`. If a `` is a string, this method will wrap it with parenthesis `"`, so `""`.
Parameters:
- **param** (dict) – The dictionary of parameters to write out.
Returns:
The string of parsed parameters.
Return type:
str
### `get_config_from_string(parts)`
#### Description
Helper function to extract the configuration of a certain function from the column name. The column name parts (split by `__`) should be passed to this function. It will skip the kind name and the function name and only use the parameter parts. These parts will be split up on `_` into the parameter name and the parameter value. This value is transformed into a python object (for example is `"(1, 2, 3)"` transformed into a tuple consisting of the ints 1, 2 and 3).
Returns None of no parameters are in the column name.
Parameters:
- **parts** (list) – The column name split up on `__`.
Returns:
a dictionary with all parameters, which are encoded in the column name.
Return type:
dict
```
--------------------------------
### POST /from_columns
Source: https://tsfresh.readthedocs.io/en/latest/_modules/tsfresh/feature_extraction/settings.html
Creates a mapping from kind names to feature calculator parameters based on a list of column names.
```APIDOC
## POST /from_columns
### Description
Parses a list of column names to generate a dictionary of feature extraction parameters (kind_to_fc_parameters) used by the extract_features function.
### Method
POST
### Endpoint
/from_columns
### Parameters
#### Request Body
- **columns** (list of str) - Required - List of feature names to parse.
- **columns_to_ignore** (list of str) - Optional - List of column names to exclude from processing.
### Response
#### Success Response (200)
- **kind_to_fc_parameters** (dict) - A mapping of kind names to their respective feature calculator settings.
```