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

0.6.16 #251

Merged
merged 162 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
408c651
Merge branch 'master' into dev
winedarksea Jul 22, 2024
e53cb55
0.6.16 a1
winedarksea Jul 26, 2024
b973c9f
0.6.16 a2
winedarksea Jul 26, 2024
0d2b14c
0.6.16 a3
winedarksea Aug 6, 2024
c0c7554
0.6.16 a4
winedarksea Aug 15, 2024
7cd999b
0.6.16 a5
winedarksea Aug 25, 2024
ebc1730
0.6.16 a6
winedarksea Aug 26, 2024
ec3cc92
0.6.16 a7
winedarksea Aug 27, 2024
9053214
0.6.16 a8
winedarksea Aug 27, 2024
e77ed35
0.6.16 a9
winedarksea Aug 27, 2024
e758e9a
0.6.16 a10
winedarksea Aug 27, 2024
d2bf401
0.6.16 a11
winedarksea Aug 27, 2024
73eebbd
0.6.16 a12
winedarksea Aug 28, 2024
fc9eb33
0.6.16 a13
winedarksea Aug 28, 2024
c4c1358
0.6.16 a14
winedarksea Aug 28, 2024
6c5f409
0.6.16 a15
winedarksea Aug 30, 2024
56e88a1
0.6.16 a16
winedarksea Sep 7, 2024
0546e38
0.6.16 a17
winedarksea Sep 7, 2024
7a71952
0.6.16 a18
winedarksea Sep 7, 2024
d5f30db
0.6.16 a19
winedarksea Sep 11, 2024
65f2a98
0.6.16 a20
winedarksea Sep 11, 2024
9bc7693
0.6.16 a21
winedarksea Sep 11, 2024
99ec9e9
0.6.16 a22
winedarksea Sep 11, 2024
47f110b
0.6.16 a23
winedarksea Sep 11, 2024
31964ae
0.6.16 a24
winedarksea Sep 12, 2024
a8bb545
0.6.16 a25
winedarksea Sep 12, 2024
1538f69
0.6.16 a26
winedarksea Sep 12, 2024
e331533
0.6.16 a27
winedarksea Sep 18, 2024
ab02c38
0.6.16 a28
winedarksea Sep 20, 2024
2919183
0.6.16 a29
winedarksea Sep 26, 2024
c885b5f
0.6.16 a30
winedarksea Sep 26, 2024
7770279
0.6.16 a31
winedarksea Sep 27, 2024
aed940a
0.16.16 a32
winedarksea Sep 30, 2024
8279201
0.6.16 a33
winedarksea Sep 30, 2024
ada01b8
0.6.16 a34
winedarksea Sep 30, 2024
82a67a9
0.6.16 a35
winedarksea Sep 30, 2024
663b2b1
0.6.16 s36
winedarksea Oct 1, 2024
0ddb852
0.6.16 a37
winedarksea Oct 1, 2024
e9ae16b
0.6.16 a38
winedarksea Oct 1, 2024
aa68094
0.6.16 a39
winedarksea Oct 2, 2024
29fe2e9
0.6.16 a40
winedarksea Oct 3, 2024
00e2139
0.6.16 a41
winedarksea Oct 3, 2024
ed11c32
0.6.16 a42
winedarksea Oct 3, 2024
d9d5e5e
0.6.16 a43
winedarksea Oct 3, 2024
638f08c
0.6.16 a44
winedarksea Oct 3, 2024
f4ad7a2
0.6.16 a45
winedarksea Oct 3, 2024
028daa3
0.6.16 a46
winedarksea Oct 3, 2024
bf9ec1b
0.6.16 a47
winedarksea Oct 3, 2024
5b54f9b
0.6.16 a48
winedarksea Oct 4, 2024
4b2d88f
0.6.16 a49
winedarksea Oct 4, 2024
b69e596
0.6.16 a50
winedarksea Oct 4, 2024
485f79f
0.6.16 a51
winedarksea Oct 4, 2024
b0665b9
0.6.16 a52
winedarksea Oct 4, 2024
3444b7f
0.6.16 a53
winedarksea Oct 4, 2024
e10b51e
0.6.16 a54
winedarksea Oct 4, 2024
9195d03
0.6.16 a55
winedarksea Oct 5, 2024
ba1309f
0.6.16 a56
winedarksea Oct 5, 2024
a495a73
0.6.16 a57
winedarksea Oct 5, 2024
aca39df
0.6.16 a58
winedarksea Oct 5, 2024
ec90bb2
0.6.16 a59
winedarksea Oct 5, 2024
84ce7b8
0.6.16 a60
winedarksea Oct 5, 2024
af14435
0.6.16 a61
winedarksea Oct 5, 2024
8da5774
0.6.16 a62
winedarksea Oct 5, 2024
cc06077
0.6.16 a63
winedarksea Oct 6, 2024
d044299
0.6.16 a64
winedarksea Oct 6, 2024
eeb30cd
0.6.16 a65
winedarksea Oct 6, 2024
67bae2e
0.6.16 a65
winedarksea Oct 6, 2024
faab856
Merge branch 'dev' of https://github.com/winedarksea/AutoTS into dev
winedarksea Oct 6, 2024
2469506
0.6.16 a66
winedarksea Oct 6, 2024
0da8728
0.6.16 a67
winedarksea Oct 7, 2024
c11f588
0.6.16 a68
winedarksea Oct 7, 2024
c1764f3
0.6.16 a69
winedarksea Oct 7, 2024
49c05b3
0.6.16 a70
winedarksea Oct 7, 2024
315a60e
0.6.16 a71
winedarksea Oct 7, 2024
c126e87
0.6.16 a72
winedarksea Oct 7, 2024
c09e750
0.6.16 a73
winedarksea Oct 7, 2024
d22d9dc
0.6.16 a74
winedarksea Oct 7, 2024
9bcaea2
0.6.16 a75
winedarksea Oct 7, 2024
6d91ccd
0.6.16 a76
winedarksea Oct 8, 2024
9ec4f64
0.6.16 a77
winedarksea Oct 8, 2024
a488d2b
0.6.16 a78
winedarksea Oct 9, 2024
5829eba
0.6.16 a79
winedarksea Oct 9, 2024
8bd846b
0.6.16 a80
winedarksea Oct 9, 2024
9aa755a
0.6.16 a81
winedarksea Oct 10, 2024
25ef9d5
0.6.16 a82
winedarksea Oct 11, 2024
1e36d33
0.6.16 a83
winedarksea Oct 11, 2024
7bfc85f
0.6.16 a84
winedarksea Oct 11, 2024
0c2165f
0.6.16 a85
winedarksea Oct 11, 2024
ba2f12f
0.6.16 a86
winedarksea Oct 12, 2024
315962c
0.6.16 a87
winedarksea Oct 12, 2024
b1f3667
0.6.16 a88
winedarksea Oct 12, 2024
17033e7
0.6.16 b1
winedarksea Oct 15, 2024
348e60c
0.6.16 a89
winedarksea Oct 16, 2024
b7b25b1
0.6.16 a90
winedarksea Oct 21, 2024
cf8b544
0.6.16 a91
winedarksea Oct 23, 2024
4e160e4
0.6.16 a92
winedarksea Oct 25, 2024
837d842
0.6.16 a93
winedarksea Oct 25, 2024
a0b6e3e
0.6.16 a94
winedarksea Oct 25, 2024
c4c3cf5
0.6.16 a95
winedarksea Oct 26, 2024
9ab902a
0.6.16 a96
winedarksea Oct 26, 2024
794e30b
0.6.16 a96
winedarksea Oct 26, 2024
64951e6
Merge branch 'dev' of https://github.com/winedarksea/AutoTS into dev
winedarksea Oct 26, 2024
0d7297a
0.6.16 a97
winedarksea Oct 26, 2024
61a1dfc
0.6.16 a98
winedarksea Oct 28, 2024
1a77b7a
0.6.16 a99
winedarksea Oct 29, 2024
6d4be7a
0.6.16 a100
winedarksea Oct 30, 2024
412dd8d
0.6.16 a101
winedarksea Oct 31, 2024
3a0c6f2
0.6.16 a102
winedarksea Oct 31, 2024
ebdc73a
0.6.16 a103
winedarksea Oct 31, 2024
52ed51b
0.6.16 a104
winedarksea Oct 31, 2024
c7ec3d5
0.6.16 a105
winedarksea Nov 1, 2024
560921c
0.6.16 a106
winedarksea Nov 1, 2024
eb8aae5
0.6.16 a107
winedarksea Nov 1, 2024
593c3b0
0.6.16 a108
winedarksea Nov 4, 2024
d69a3e6
0.6.16 a109
winedarksea Nov 4, 2024
ba5537b
0.6.16 a110
winedarksea Nov 5, 2024
6c51b1d
0.6.16 a111
winedarksea Nov 6, 2024
b159ec9
0.6.16 a112
winedarksea Nov 6, 2024
5792f5d
0.6.16 a113
winedarksea Nov 6, 2024
284f216
0.6.16 a114
winedarksea Nov 7, 2024
19d5870
0.6.16 a115
winedarksea Nov 8, 2024
3148013
0.6.16 a116
winedarksea Nov 8, 2024
d8f4074
0.6.16 a117
winedarksea Nov 8, 2024
3f469b9
0.6.16 a118
winedarksea Nov 8, 2024
5398fd7
0.6.16 a119
winedarksea Nov 8, 2024
a5ce5f0
0.6.16 a120
winedarksea Nov 9, 2024
a56a51a
0.6.16 a121
winedarksea Nov 9, 2024
8947fe9
0.6.16 a122
winedarksea Nov 10, 2024
b198f6a
0.6.16 a123
winedarksea Nov 10, 2024
aa47c57
0.6.16 a124
winedarksea Nov 10, 2024
b9921de
0.6.16 a125
winedarksea Nov 10, 2024
c4ac8ef
0.6.16 a126
winedarksea Nov 11, 2024
6ee9c2c
0.6.16 a127
winedarksea Nov 11, 2024
2f71870
0.6.16 a128
winedarksea Nov 12, 2024
bf826a5
0.6.16 a129
winedarksea Nov 12, 2024
0f6d053
0.6.16 a130
winedarksea Nov 13, 2024
b2441ce
0.6.16 a131
winedarksea Nov 13, 2024
971892f
0.6.16 a132
winedarksea Nov 13, 2024
6629756
0.6.16 a133
winedarksea Nov 13, 2024
70f0c34
0.6.16 a134
winedarksea Nov 14, 2024
fe3f176
0.6.16 a135
winedarksea Nov 14, 2024
be0d53c
0.6.16 a136
winedarksea Nov 15, 2024
0e72314
0.6.16 a137
winedarksea Nov 15, 2024
813332d
0.6.16 a138
winedarksea Nov 15, 2024
6ab06af
0.6.16 a139
winedarksea Nov 15, 2024
11ead42
0.6.16 a140
winedarksea Nov 15, 2024
63aae6a
0.6.16 a141
winedarksea Nov 15, 2024
ebe8aa2
0.6.16 a142
winedarksea Nov 16, 2024
cb68bb1
0.6.16 a143
winedarksea Nov 16, 2024
71eb492
0.6.16 a144
winedarksea Nov 16, 2024
4b7fae5
0.6.16 a145
winedarksea Nov 16, 2024
1d456fb
0.6.16 a146
winedarksea Nov 16, 2024
0d0add5
0.6.16 a147
winedarksea Nov 17, 2024
140976f
Merge branch 'master' into dev
winedarksea Nov 17, 2024
2a62c7b
0.6.16 a148
winedarksea Nov 17, 2024
bee5e97
0.6.16 a149
winedarksea Nov 17, 2024
20e2d04
0.6.16 a150
winedarksea Nov 18, 2024
55bff6c
0.6.16 a151
winedarksea Nov 18, 2024
022af65
0.6.16 a152
winedarksea Nov 18, 2024
570053b
0.6.16 a153
winedarksea Nov 18, 2024
c441378
0.6.16 a154
winedarksea Nov 18, 2024
7e97114
0.6.16
winedarksea Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ A combination of metrics and cross-validation options, the ability to apply subs
* [Installation](https://github.com/winedarksea/AutoTS#installation)
* [Basic Use](https://github.com/winedarksea/AutoTS#basic-use)
* [Tips for Speed and Large Data](https://github.com/winedarksea/AutoTS#tips-for-speed-and-large-data)
* [Flowchart](https://github.com/winedarksea/AutoTS#autots-process)
* Extended Tutorial [GitHub](https://github.com/winedarksea/AutoTS/blob/master/extended_tutorial.md) or [Docs](https://winedarksea.github.io/AutoTS/build/html/source/tutorial.html)
* [Production Example](https://github.com/winedarksea/AutoTS/blob/master/production_example.py)

Expand Down Expand Up @@ -59,10 +60,10 @@ df = load_daily(long=long)

model = AutoTS(
forecast_length=21,
frequency='infer',
frequency="infer",
prediction_interval=0.9,
ensemble='auto',
model_list="fast", # "superfast", "default", "fast_parallel"
ensemble=None,
model_list="superfast", # "fast", "default", "fast_parallel"
transformer_list="fast", # "superfast",
drop_most_recent=1,
max_generations=4,
Expand Down Expand Up @@ -133,4 +134,37 @@ Also take a look at the [production_example.py](https://github.com/winedarksea/A
* And, of course, contributing to the codebase directly on GitHub.


## AutoTS Process
```mermaid
flowchart TD
A[Initiate AutoTS Model] --> B[Import Template]
B --> C[Load Data]
C --> D[Split Data Into Initial Train/Test Holdout]
D --> E[Run Initial Template Models]
E --> F[Evaluate Accuracy Metrics on Results]
F --> G[Generate Score from Accuracy Metrics]
G --> H{Max Generations Reached or Timeout?}

H -->|No| I[Evaluate All Previous Templates]
I --> J[Genetic Algorithm Combines Best Results and New Random Parameters into New Template]
J --> K[Run New Template Models and Evaluate]
K --> G

H -->|Yes| L[Select Best Models by Score for Validation Template]
L --> M[Run Validation Template on Additional Holdouts]
M --> N[Evaluate and Score Validation Results]
N --> O{Create Ensembles?}

O -->|Yes| P[Generate Ensembles from Validation Results]
P --> Q[Run Ensembles Through Validation]
Q --> N

O -->|No| R[Export Best Models Template]
R --> S[Select Single Best Model]
S --> T[Generate Future Time Forecast]
T --> U[Visualize Results]

R --> B[Import Best Models Template]
```

*Also known as Project CATS (Catlin's Automated Time Series) hence the logo.*
39 changes: 28 additions & 11 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,34 @@
* Forecasts are desired for the future immediately following the most recent data.
* trimmed_mean to AverageValueNaive

# 0.6.15 🇺🇦 🇺🇦 🇺🇦
* Constraint transformer added
* historical_growth constraint method added
* fft as multivariate_feature for Cassandra
* None trend_window now searched as part of Cassandra
* "quarterlydayofweek" method added for datepart
* threshold_method arg to AlignLastValue
* general tempate updated
* slight change to MATSE metric, now only abs values for scaling
* additional args to DatepartRegression
* bug fixes
# 0.6.16 🇺🇦 🇺🇦 🇺🇦
* export_template added focus_models option
* added OneClassSVM and GaussianMixture anomaly model options
* added plot_unpredictability_score
* added a few more NeuralForecast search options
* bounds_only to Constraint transformer
* updates for deprecated upstream args
* FIRFilter transformer added
* mle and imle downscaled to reduce score imbalance issues with these two in generate score
* SectionalMotif now more robust to forecast lengths longer than history
* new transformer and metric options for SectionalMotif
* NaN robustness to matse
* 'round' option to Constraint
* minor change to mosaic min style ensembles to remove edge case errors
* 'mosaic-profile', 'filtered', 'unpredictability_adjusted' and 'median' style mosaics added
* updated profiler, and improved feature generation for horizontal generalization
* changepoint style trend as an option to GLM and GLS
* added ShiftFirstValue which is only a minor nuance on PositiveShift transformer
* added BasicLinearModel model
* datepart_method, scale, and fourier encodig to WindowRegression
* trimmed_mean and more date part options to SeasonalityMotif
* some additional options to MultivariateRegression
* added ThetaTransformer
* added TVVAR model (time varying VAR)
* added ChangepointDetrend transformer
* added MeanPercentSplitter transformer
* updated load_daily with more recent history
* added support for passing a custom metric

### Unstable Upstream Pacakges (those that are frequently broken by maintainers)
* Pytorch-Forecasting
Expand Down
2 changes: 1 addition & 1 deletion autots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from autots.models.cassandra import Cassandra


__version__ = '0.6.15'
__version__ = '0.6.16'

TransformTS = GeneralTransformer

Expand Down
96 changes: 85 additions & 11 deletions autots/datasets/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,54 @@
def load_daily(long: bool = True):
"""Daily sample data.

```
# most of the wiki data was chosen to show holidays or holiday-like patterns
wiki = [
"Germany", "Thanksgiving", 'all', 'Microsoft',
"Procter_%26_Gamble", "YouTube", "United_States", "Elizabeth_II",
"William_Shakespeare", "Cleopatra", "George_Washington",
"Chinese_New_Year", "Standard_deviation", "Christmas",
"List_of_highest-grossing_films",
"List_of_countries_that_have_gained_independence_from_the_United_Kingdom",
"Periodic_table"
'United_States',
'Germany',
'List_of_highest-grossing_films',
'Jesus',
'Michael_Jackson',
'List_of_United_States_cities_by_population',
'Microsoft_Office',
'Google_Chrome',
'Periodic_table',
'Standard_deviation',
'Easter',
'Christmas',
'Chinese_New_Year',
'Thanksgiving',
'List_of_countries_that_have_gained_independence_from_the_United_Kingdom',
'History_of_the_hamburger',
'Elizabeth_II',
'William_Shakespeare',
'George_Washington',
'Cleopatra',
'all'
]

df2 = load_live_daily(
observation_start="2017-01-01", weather_years=7, trends_list=None,
gov_domain_list=None, wikipedia_pages=wiki,
fred_series=['DGS10', 'T5YIE', 'SP500','DEXUSEU'], sleep_seconds=10,
fred_key = "93873d40f10c20fe6f6e75b1ad0aed4d",
weather_data_types = ["WSF2", "PRCP"],
weather_stations = ["USW00014771"], # looking for intermittent
tickers=None, london_air_stations=None,
weather_event_types=None, earthquake_min_magnitude=None,
)
data_file_name = join("autots", "datasets", 'data', 'holidays.zip')
df2.to_csv(
data_file_name,
index=True,
compression={
'method': 'zip',
'archive_name': 'holidays.csv',
'compresslevel': 9 # Maximum compression level (0-9)
}
)
```

Sources: Wikimedia Foundation

Args:
Expand Down Expand Up @@ -224,8 +262,8 @@ def load_live_daily(
tickers: list = ["MSFT"],
trends_list: list = ["forecasting", "cycling", "microsoft"],
trends_geo: str = "US",
weather_data_types: list = ["AWND", "WSF2", "TAVG"],
weather_stations: list = ["USW00094846", "USW00014925"],
weather_data_types: list = ["AWND", "WSF2", "TAVG", "PRCP"],
weather_stations: list = ["USW00094846", "USW00014925", "USW00014771"],
weather_years: int = 5,
london_air_stations: list = ['CT3', 'SK8'],
london_air_species: str = "PM25",
Expand Down Expand Up @@ -769,14 +807,42 @@ def load_artificial(long=False, date_start=None, date_end=None):
date_end = date_end.date()
if date_start is None:
if isinstance(date_end, datetime.date):
date_start = date_end - datetime.timedelta(days=720)
date_start = date_end - datetime.timedelta(days=740)
else:
date_start = datetime.datetime.now().date() - datetime.timedelta(days=720)
date_start = datetime.datetime.now().date() - datetime.timedelta(days=740)
if isinstance(date_start, datetime.datetime):
date_start = date_start.date()
dates = pd.date_range(date_start, date_end)
size = dates.size
new_size = int(size / 10)
rng = np.random.default_rng()
holiday = pd.Series(
np.arange(size) * 0.025
+ rng.normal(0, 0.2, size)
+ (np.sin((np.pi / 7) * np.arange(size)) * 0.5),
index=dates,
name='holiday',
)
# January 1st
holiday[holiday.index.month == 1 & (holiday.index.day == 1)] += 10
# December 25th
holiday[(holiday.index.month == 12) & (holiday.index.day == 25)] += -4
# Second Tuesday of April
# Find all Tuesdays in April
second_tuesday_of_april = (
(holiday.index.month == 4)
& (holiday.index.weekday == 1)
& (holiday.index.day >= 8)
& (holiday.index.day <= 14)
)
holiday[second_tuesday_of_april] += 10
# Last Monday of August
last_monday_of_august = (
(holiday.index.month == 8)
& (holiday.index.weekday == 0)
& ((holiday.index + pd.Timedelta(7, unit='D')).month == 9)
)
holiday[last_monday_of_august] += 12

df_wide = pd.DataFrame(
{
Expand Down Expand Up @@ -810,6 +876,13 @@ def load_artificial(long=False, date_start=None, date_end=None):
/ 2,
),
"linear": np.arange(size) * 0.025,
"flat": 1,
"new_product": np.concatenate(
[
np.zeros(int(size - new_size)),
np.random.choice(a=[-0.8, 0, 0.8], size=new_size).cumsum(),
]
),
"sine_wave": np.sin(np.arange(size)),
"sine_seasonality_monthweek": (
(np.sin((np.pi / 7) * np.arange(size)) * 0.25 + 0.25)
Expand Down Expand Up @@ -902,6 +975,7 @@ def load_artificial(long=False, date_start=None, date_end=None):
},
index=dates,
)
df_wide = df_wide.merge(holiday, left_index=True, right_index=True)

if not long:
return df_wide
Expand Down
Binary file modified autots/datasets/data/holidays.zip
Binary file not shown.
39 changes: 31 additions & 8 deletions autots/evaluator/anomaly_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def detect(self, df):
self.anomalies[mask_replace] = 1
return self.anomalies, self.scores

def plot(self, series_name=None, title=None, plot_kwargs={}):
def plot(self, series_name=None, title=None, marker_size=None, plot_kwargs={}):
import matplotlib.pyplot as plt

if series_name is None:
Expand All @@ -162,7 +162,14 @@ def plot(self, series_name=None, title=None, plot_kwargs={}):
series_anom = self.anomalies[series_name]
i_anom = series_anom[series_anom == -1].index
if len(i_anom) > 0:
ax.scatter(i_anom.tolist(), self.df.loc[i_anom, :][series_name], c="red")
if marker_size is None:
marker_size = max(20, fig.dpi * 0.45)
ax.scatter(
i_anom.tolist(),
self.df.loc[i_anom, :][series_name],
c="red",
s=marker_size,
)

def fit(self, df):
return self.detect(df)
Expand Down Expand Up @@ -230,8 +237,8 @@ def get_new_params(method="random"):

if preforecast or method_choice == "prediction_interval":
forecast_params = random_model(
model_list=['LastValueNaive', 'GLS', 'RRVAR'],
model_prob=[0.8, 0.1, 0.1],
model_list=['LastValueNaive', 'GLS', 'RRVAR', "SeasonalityMotif"],
model_prob=[0.8, 0.1, 0.05, 0.05],
transformer_max_depth=5,
transformer_list="superfast",
keyword_format=True,
Expand All @@ -256,8 +263,9 @@ def __init__(
use_wkdeom_holidays=True,
use_lunar_holidays=True,
use_lunar_weekday=False,
use_islamic_holidays=True,
use_hebrew_holidays=True,
use_islamic_holidays=False,
use_hebrew_holidays=False,
use_hindu_holidays=False,
output: str = "multivariate",
n_jobs: int = 1,
):
Expand Down Expand Up @@ -292,6 +300,7 @@ def __init__(
self.use_lunar_weekday = use_lunar_weekday
self.use_islamic_holidays = use_islamic_holidays
self.use_hebrew_holidays = use_hebrew_holidays
self.use_hindu_holidays = use_hindu_holidays
self.n_jobs = n_jobs
self.output = output
self.anomaly_model = AnomalyDetector(
Expand All @@ -313,6 +322,7 @@ def detect(self, df):
self.lunar_weekday,
self.islamic_holidays,
self.hebrew_holidays,
self.hindu_holidays,
) = anomaly_df_to_holidays(
self.anomaly_model.anomalies,
splash_threshold=self.splash_threshold,
Expand All @@ -328,6 +338,7 @@ def detect(self, df):
use_lunar_weekday=self.use_lunar_weekday,
use_islamic_holidays=self.use_islamic_holidays,
use_hebrew_holidays=self.use_hebrew_holidays,
use_hindu_holidays=self.use_hindu_holidays,
)

def plot_anomaly(self, kwargs={}):
Expand All @@ -338,6 +349,7 @@ def plot(
series_name=None,
include_anomalies=True,
title=None,
marker_size=None,
plot_kwargs={},
series=None,
):
Expand All @@ -355,6 +367,8 @@ def plot(
)
fig, ax = plt.subplots()
self.df[series_name].plot(ax=ax, title=title, **plot_kwargs)
if marker_size is None:
marker_size = max(20, fig.dpi * 0.45)
if include_anomalies:
# directly copied from above
if self.anomaly_model.output == "univariate":
Expand All @@ -366,13 +380,21 @@ def plot(
i_anom = series_anom[series_anom == -1].index
if len(i_anom) > 0:
ax.scatter(
i_anom.tolist(), self.df.loc[i_anom, :][series_name], c="red"
i_anom.tolist(),
self.df.loc[i_anom, :][series_name],
c="red",
s=marker_size,
)
# now the actual holidays
i_anom = self.dates_to_holidays(self.df.index, style="series_flag")[series_name]
i_anom = i_anom.index[i_anom == 1]
if len(i_anom) > 0:
ax.scatter(i_anom.tolist(), self.df.loc[i_anom, :][series_name], c="green")
ax.scatter(
i_anom.tolist(),
self.df.loc[i_anom, :][series_name],
c="green",
s=marker_size,
)

def dates_to_holidays(self, dates, style="flag", holiday_impacts=False):
"""Populate date information for a given pd.DatetimeIndex.
Expand Down Expand Up @@ -400,6 +422,7 @@ def dates_to_holidays(self, dates, style="flag", holiday_impacts=False):
lunar_weekday=self.lunar_weekday,
islamic_holidays=self.islamic_holidays,
hebrew_holidays=self.hebrew_holidays,
hindu_holidays=self.hindu_holidays,
)

def fit(self, df):
Expand Down
Loading
Loading