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

Why doesn't Ruptures give the changepoints I expect? #336

Open
markaoliver opened this issue Jan 2, 2025 · 0 comments
Open

Why doesn't Ruptures give the changepoints I expect? #336

markaoliver opened this issue Jan 2, 2025 · 0 comments

Comments

@markaoliver
Copy link

I'm using the Ruptures package and not getting the changepoints I'd expected. I got this result:

image

Take a look at 2024-05-26. You can see that, to a human eye, this is clearly a major changepoint. The line has been in a downward trend and, at that date, has suddenly shifted into an upward climb. However, Ruptures is identifying the changepoint as 2024-06-09, a few days after the obvious change, instead.

What's going on here? Why is Ruptures picking this date and how can I improve the model?

Here is my code:

import numpy as np
import ruptures as rpt
import matplotlib.pyplot as plt

# Data Import
data = pd.read_csv('my_data.csv')

# Model calibration
algo = rpt.Pelt(model='l2', min_size=20, jump=1).fit(data) 
change_points = algo.predict(pen=statistics.variance(data['effect']))  # Using the variance in the key metric as the penality.

# List change points:
print("Change points detected at indices:", data.index[change_points[:-1]])

# Visualize data:
rpt.display(data, change_points, figsize=(10, 6))
plt.xlabel('Date') 
plt.ylabel('Cumulative Effect') 
plt.xticks(ticks=range(0, len(data), len(data)//10), labels=data.index[::len(data)//10]) 
plt.grid(True)
plt.show()
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

1 participant