Skip to content

Hasan-Basri-Akcay/akrule

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AKRULE

GitHub Workflow Status (with event) GitHub Workflow Status (with event) Docs PyPI Python License

Akrule stands out as a powerful rule-based time series forecasting machine learning model designed for optimal performance in both real-time training and prediction scenarios. Its notable feature lies in its swift training capabilities, enabling efficient and timely predictions. Akrule goes beyond standard forecasting models by providing insightful upper and lower boundaries through the integration of confidence intervals and bootstrapping techniques. This unique attribute makes it particularly valuable for anomaly detection, as it empowers users to identify deviations from expected patterns.

Akrule's effectiveness is underscored by its keen sensitivity to seasonality and trend analysis, making it well-suited for applications where these factors play a crucial role in influencing time series data. By harnessing the power of Akrule, users can not only achieve accurate predictions but also gain a comprehensive understanding of the potential variations and uncertainties associated with their data, enhancing the model's utility across diverse domains.

Detailed Medium post on using akrule.

Installation

pip install akrule

Dependencies

akrule requires:

  • Python (>= 3.9)
  • NumPy (>= 1.24.4)
  • Pandas (>= 2.1.2)

Time-Series Forecasting and Anomaly Detection

from akrule.time_series import get_weekly_daily_hourly_data
from akrule.time_series import plot_pred

df_daily = get_weekly_daily_data(N=10, max_value=10, noise_std=3, anomaly_percentage=20)
split_time = str(datetime.now().date() - timedelta(days=7*3))
X_train_daily = df_daily[df_daily["time"]<split_time].copy()
X_test_daily = df_daily[df_daily["time"]>=split_time].copy()

tag_features = ["Country"]
model = AKRuleBasedTS(freqs=["weekly", "dayofweek"], tag_features=tag_features, average_num=3, trend_level=1, fillna=True,
                      metric_ci=0.90, inplace=False)
X_val = model.fit_predict(X_train_daily)
X_pred = model.predict(X_test_daily.drop(["y"], axis=1))

plot_pred(X_val=X_val, X_pred=X_pred, tag_features=tag_features, figsize=(16,4))

tag_features = ["Country"]
model = AKRuleBasedTS(freqs=["weekly", "dayofweek"], tag_features=tag_features, average_num=3, trend_level=1, fillna=True,
                      metric_ci=0.70, inplace=False)
X_val = model.fit_predict(X_train_daily)
X_pred = model.predict(X_test_daily.drop(["y"], axis=1))

plot_pred(X_val=X_val, X_pred=X_pred, tag_features=tag_features, figsize=(16,4))