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

[bug] sparsity returning incorrect values #42

Closed
ngupta23 opened this issue Nov 19, 2024 · 2 comments
Closed

[bug] sparsity returning incorrect values #42

ngupta23 opened this issue Nov 19, 2024 · 2 comments
Labels

Comments

@ngupta23
Copy link
Member

What happened + What you expected to happen

Sparsity is not being calculated correctly in the code. See below. The data clearly has 0 values and the expected sparsity is 0.5, but the code is returning a value of 0.

image

Versions / Dependencies

Name: tsfeatures Version: 0.4.5

Reproduction script

import pandas as pd
data = {'y': [0, 23, 0, 45, 0, 19, 0, 7, 34, 0]}
df = pd.DataFrame(data)
df["unique_id"] = "A"
from datetime import datetime, timedelta
start_date = datetime(2024, 1, 1)
df['ds'] = [start_date + timedelta(weeks=i) for i in range(len(df))]
df

# Extract features
from tsfeatures import sparsity
tsfeatures(df, freq=52, features=[sparsity])

# Expected result
np.mean(df["y"] == 0)  # 0.5

Issue Severity

Medium: It is a significant difficulty but I can work around it.

@ngupta23 ngupta23 added the bug label Nov 19, 2024
@ngupta23 ngupta23 changed the title [bug] sparcity returning incorrect values [bug] sparsity returning incorrect values Nov 19, 2024
@ngupta23
Copy link
Member Author

This is because the scale argument is set to True by default. To calculate the correct value, set scale to False

tsfeatures(df, freq=52, features=[sparsity], scale=False)

@ngupta23
Copy link
Member Author

Looks like an enhancement request is already in place: #40

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

No branches or pull requests

1 participant