Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new features to existing MinimalExtractionParameters settings #924

Open
utkarshtri1997 opened this issue Jan 20, 2022 Discussed in #923 · 1 comment
Open

Adding new features to existing MinimalExtractionParameters settings #924

utkarshtri1997 opened this issue Jan 20, 2022 Discussed in #923 · 1 comment

Comments

@utkarshtri1997
Copy link

Discussed in #923

Originally posted by utkarshtri1997 January 20, 2022
Hi, Firstly Thank you for building this good application for time-series calculation. Can you please help me in adding new features to MinimalExtractionParameters? Please reply ASAP.`@set_property("fctype", "simple")
def flor_ratio(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

u=np.max(x)
v=np.min(x)
#flor_ratio = (u-v)/v
return (u-v)/v
fc_parameters = {
'median': None,
'mean': None,
'standard_deviation': None,
'root_mean_square': None,
'maximum': None,
'minimum': None,'flor_ratio':None
from sktime.transformations.panel.tsfresh import TSFreshRelevantFeatureExtractor
from tsfresh.feature_extraction import extract_features
transformer = TSFreshRelevantFeatureExtractor(kind_to_fc_parameters= fc_parameters)
extracted_features = transformer.fit_transform(X_train,y_train)
extracted_features
}` But this doesn't calculate the features I gave it to calculate.

@nils-braun
Copy link
Collaborator

Hi @utkarshtri1997
sorry for the late answer. I know it can be frustrating waiting for an answer when you desperately need it. Please note however, that every contributor and maintainer of tsfresh does this in its free time and without compensation :) We always try to answer "ASAP" ;)

To your question:
There are a few small inconsistencies in your code example (by the way, you can help readability of the code by using the code formatting of GitHub markdown), where I am not sure if this was not just a copy-paste error from your original code, but I will point them out anyways:

  • You are using kind_to_fc_parameters with a dictionary without column names - so it looks like you actually wanted to use it with default_fc_parameters.
  • You included your new function flor_ratio into the dictionary as string literal, but in the documentation we describe it should be added as plain function (see here). Just remove the ' around it.

I do not have experience with sktime and it might be that the problem only occurs when using this package. But for me, this works correctly (using sktime's example dataset):

import numpy as np

def flor_ratio(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
    u=np.max(x)
    v=np.min(x)
    return (u-v)/v

fc_parameters = {
    'median': None,
    'mean': None,
    'standard_deviation': None,
    'root_mean_square': None,
    'maximum': None,
    'minimum': None, flor_ratio:None
}

if __name__ == "__main__":
    from sktime.transformations.panel.tsfresh import TSFreshRelevantFeatureExtractor
    from sktime.datasets import load_arrow_head
    X, y = load_arrow_head(return_X_y=True)

    transformer = TSFreshRelevantFeatureExtractor(default_fc_parameters=fc_parameters)
    extracted_features = transformer.fit_transform(X, y)
    print(extracted_features)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants