detect_anomalies
method to identify anomalies. The method will automatically detect and utilize any exogenous features present in your DataFrame:
anomalies_df = nixtla_client.detect_anomalies(
df=df,
time_col='ds',
target_col='y'
)
Step 3: Add Date Features (Optional)Adding date features is a powerful way to enrich datasets for historical anomaly detection—especially when external exogenous variables are unavailable. By passing date components like ['month', 'year']
and enabling date_features_to_one_hot=True
, TimeGPT automatically encodes these as one-hot vectors. This allows the model to better detect seasonal patterns, calendar effects, and periodic anomalies.
anomalies_df = nixtla_client.detect_anomalies(
df=df,
time_col='ds',
target_col='y',
date_features=['month', 'year'],
date_features_to_one_hot=True
)
Step 4: Visualize AnomaliesUse the plot
method to visualize the detected anomalies in the time series data.
nixtla_client.plot(df, anomalies_df)
Detected anomalies in time series with exogenous variables
The plot shows the time series with detected anomalies marked in red. The blue line represents the actual values, while the shaded area indicates the confidence interval. Points that fall outside this interval are flagged as anomalies. Step 5: Inspect Model Weights (Optional)Use theweights_x
method to view the relative weights of the exogenous features to understand their impact:
nixtla_client.weights_x.plot.barh(
x='features',
y='weights'
)
Weights of exogenous date features
The horizontal bar plot shows the relative importance of each exogenous feature in the anomaly detection model. Features with larger weights have a stronger influence on the model’s predictions. This visualization helps identify which external factors are most significant in determining anomalies in your time series.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4