### Install PyTorch and PyTorch Forecasting with Conda Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Installs PyTorch (CPU version) and PyTorch Forecasting using conda. This setup is suitable for systems without specific GPU requirements. ```bash conda install pytorch torchvision torchaudio cpuonly -c pytorch conda install pytorch-forecasting -c conda-forge ``` -------------------------------- ### Install PyTorch and Related Packages Source: https://github.com/winedarksea/autots/blob/master/extended_tutorial.md Installs PyTorch, torchvision, and torchaudio, along with the pytorch-forecasting library for time series models that utilize PyTorch. NeuralProphet is also installed separately. ```shell conda install pytorch torchvision torchaudio cpuonly -c pytorch conda install pytorch-forecasting -c conda-forge pip install neuralprophet ``` -------------------------------- ### Install Prophet with Pip Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Installs the Prophet library, a forecasting tool developed by Facebook. It also includes instructions for handling potential installation issues by using the '--no-deps' flag if the conda-forge option fails. ```bash python -m pip install pystan prophet --exists-action i # conda-forge option below works more easily, --no-deps to pip install prophet if this fails ``` -------------------------------- ### Install Autots Package with Pip Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Installs the Autots package itself using pip. The '--exists-action i' flag ensures that if Autots is already installed, pip will simply ignore it. ```bash python -m pip install autots --exists-action i ``` -------------------------------- ### Setup GPU Environment for autots (Linux) Source: https://github.com/winedarksea/autots/blob/master/extended_tutorial.md Configures a Linux environment for GPU acceleration with autots. This involves installing specific CUDA and cuDNN versions, setting environment variables, and installing GPU-compatible versions of libraries like PyTorch and MXNet. ```shell nvidia-smi mamba activate base mamba install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0 nccl # install in conda base export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_PREFIX/lib/ # NOT PERMANENT unless add to ./bashrc make sure is for base env, mine /home/colin/mambaforge/lib mamba create -n gpu python=3.8 scikit-learn pandas statsmodels prophet numexpr bottleneck tqdm holidays lightgbm matplotlib requests -c conda-forge mamba activate gpu pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113 pip install mxnet-cu112 --no-deps pip install gluonts tensorflow neuralprophet pytorch-lightning pytorch-forecasting mamba install spyder ``` -------------------------------- ### GPU Environment Setup: Install CUDA and cuDNN Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Installs specific versions of CUDA Toolkit, cuDNN, and NCCL using mamba in the 'base' conda environment. These are critical components for enabling GPU acceleration for deep learning frameworks on Linux. ```bash mamba install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0 nccl # install in conda base ``` -------------------------------- ### Install Neural Prophet with Pip Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Installs the Neural Prophet library, a time series forecasting model, using pip. ```bash pip install neuralprophet ``` -------------------------------- ### Install MXNet and Other Libraries with Mamba/Pip Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Installs specific versions or variants of mxnet and other libraries like yfinance, gluonts, and arch. It uses '--no-deps' for mxnet to manage dependencies manually. ```bash pip install mxnet --no-deps pip install yfinance pytrends fredapi gluonts arch ``` -------------------------------- ### Install Additional Autots Dependencies with Pip Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Installs holiday-ext, pmdarima, dill, and greykite. The '--exists-action i' flag skips already installed packages, and '--no-deps' prevents pip from installing dependencies that might conflict. ```bash python -m pip install holidays-ext pmdarima dill greykite --exists-action i --no-deps ``` -------------------------------- ### Install GPU Deep Learning and Other Packages Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Installs GPU-accelerated versions of GluonTS, TensorFlow, Neural Prophet, PyTorch Lightning, and PyTorch Forecasting. These packages leverage the CUDA toolkit for faster computation. ```bash pip install gluonts tensorflow neuralprophet pytorch-lightning pytorch-forecasting ``` -------------------------------- ### Install AutoTS using pip Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/_sources/index.rst.txt This command installs the AutoTS package using pip, the Python package installer. Ensure you have Python 3.9+ and pip installed. ```sh pip install autots ``` -------------------------------- ### Install Deep Learning and Other Packages with Pip Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Installs TensorFlow, mxnet, gluonts, and arch. It notes that mxnet may require specific installation options and checks the mxnet documentation for further details. ```bash python -m pip install tensorflow python -m pip install mxnet --no-deps # check the mxnet documentation for more install options, also try pip install mxnet --no-deps python -m pip install gluonts arch ``` -------------------------------- ### Install GPU-Versioned PyTorch and MXNet Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Installs the GPU-enabled versions of PyTorch and MXNet. PyTorch uses an extra index URL to fetch CUDA-specific wheels, while mxnet uses the '--no-deps' flag. ```bash pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113 pip install mxnet-cu112 --no-deps ``` -------------------------------- ### Event Risk Forecasting Setup and Prediction Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Sets up and uses the EventRiskForecast model from AutoTS. It demonstrates fitting the model, predicting future risk scores, and plotting results. ```python import numpy as np from autots import ( load_daily, EventRiskForecast, ) from sklearn.metrics import multilabel_confusion_matrix, classification_report forecast_length = 6 df_full = load_daily(long=False) df = df_full[0: (df_full.shape[0] - forecast_length)] df_test = df[(df.shape[0] - forecast_length):] upper_limit = 0.95 # --> 95% quantile of historic data # if using manual array limits, historic limit must be defined separately (if used) lower_limit = np.ones((forecast_length, df.shape[1])) historic_lower_limit = np.ones(df.shape) model = EventRiskForecast( df, forecast_length=forecast_length, upper_limit=upper_limit, lower_limit=lower_limit, ) # .fit() is optional if model_name, model_param_dict, model_transform_dict are already defined (overwrites) model.fit() risk_df_upper, risk_df_lower = model.predict() historic_upper_risk_df, historic_lower_risk_df = model.predict_historic(lower_limit=historic_lower_limit) model.plot(0) ``` -------------------------------- ### Install AutoTS with Intel Conda Channel Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html This snippet demonstrates how to create a Python environment with specific versions and packages using mamba, including AutoTS and its dependencies. It also shows how to add conda channels and install additional Python packages via pip. ```bash mamba create -n aikit37 python=3.7 intel-aikit-modin pandas statsmodels prophet numexpr bottleneck tqdm holidays lightgbm matplotlib requests tensorflow dpctl -c intel conda config --env --add channels conda-forge conda config --env --add channels intel conda config --env --get channels python -m pip install mxnet --no-deps python -m pip install gluonts yfinance pytrends fredapi mamba update -c intel intel-aikit-modin python -m pip install autots ``` -------------------------------- ### Install autots with Intel AI Analytics Toolkit Source: https://github.com/winedarksea/autots/blob/master/extended_tutorial.md Installs autots and its dependencies using Intel's optimized libraries via the 'intel-aikit-modin' package. This can offer performance improvements on Intel hardware. Environment variables for optimization are also noted. ```shell # create the environment mamba create -n aikit37 python=3.7 intel-aikit-modin pandas statsmodels prophet numexpr bottleneck tqdm holidays lightgbm matplotlib requests tensorflow dpctl -c intel conda config --env --add channels conda-forge conda config --env --add channels intel conda config --env --get channels # install additional packages as desired python -m pip install mxnet --no-deps python -m pip install gluonts yfinance pytrends fredapi mamba update -c intel intel-aikit-modin python -m pip install autots # OMP_NUM_THREADS, USE_DAAL4PY_SKLEARN=1 ``` -------------------------------- ### Install Core Python Packages with Pip Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Installs essential Python packages including numpy, scipy, scikit-learn, statsmodels, and others using pip. The '--exists-action i' flag ensures that if a package is already installed, pip will ignore it instead of raising an error. ```bash python -m pip install numpy scipy scikit-learn statsmodels lightgbm xgboost numexpr bottleneck yfinance pytrends fredapi --exists-action i ``` -------------------------------- ### Install Core autots Dependencies with Pip Source: https://github.com/winedarksea/autots/blob/master/extended_tutorial.md Installs critical and recommended packages for autots using pip, ensuring specific versions for compatibility with various autots features. This includes data manipulation, modeling, and forecasting libraries. ```shell # create a conda or venv environment conda create -n timeseries python=3.9 conda activate timeseries python -m pip install numpy scipy scikit-learn statsmodels lightgbm xgboost numexpr bottleneck yfinance pytrends fredapi --exists-action i python -m pip install pystan prophet --exists-action i # conda-forge option below works more easily, --no-deps to pip install prophet if this fails python -m pip install tensorflow python -m pip install mxnet --no-deps # check the mxnet documentation for more install options, also try pip install mxnet --no-deps python -m pip install gluonts arch python -m pip install holidays-ext pmdarima dill greykite --exists-action i --no-deps # install pytorch python -m pip install --upgrade numpy pandas --exists-action i # mxnet likes to (pointlessly seeming) install old versions of numpy python -m pip install autots --exists-action i ``` -------------------------------- ### Install Autots with Mamba Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Installs the Autots package using mamba, specifying the conda-forge channel. This is an alternative installation method to pip. ```bash mamba install autots -c conda-forge ``` -------------------------------- ### Install Intel Optimized TensorFlow and Mamba Spyder Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Installs Intel-optimized TensorFlow for enhanced performance on Intel hardware and the Spyder IDE using mamba. 'intel-tensorflow' is a specific build optimized for Intel CPUs. ```bash pip install intel-tensorflow scikit-learn-intelex mamba install spyder ``` -------------------------------- ### Anomaly Detection Setup Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Initializes the AnomalyDetector from AutoTS, loading live daily data for analysis. This can involve various data sources like Wikipedia pages for trend analysis. ```python from autots.evaluator.anomaly_detector import AnomalyDetector from autots.datasets import load_live_daily # internet connection required to load this df wiki_pages = [ "Standard_deviation", "Christmas", "Thanksgiving", "all", ] df = load_live_daily( long=False, fred_series=None, tickers=None, trends_list=None, earthquake_min_magnitude=None, weather_stations=None, london_air_stations=None, gov_domain_list=None, weather_event_types=None, ) ``` -------------------------------- ### Install Packages with Mamba (Conda-Forge) Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Installs a suite of data science and machine learning packages using mamba, specifying the conda-forge channel for broader compatibility. This command includes core libraries and optional ones like lightgbm and xgboost. ```bash mamba install scikit-learn pandas statsmodels prophet numexpr bottleneck tqdm holidays lightgbm matplotlib requests xgboost -c conda-forge ``` -------------------------------- ### Install autots Dependencies with Mamba (Conda Forge) Source: https://github.com/winedarksea/autots/blob/master/extended_tutorial.md Installs a comprehensive set of autots dependencies using mamba, leveraging the conda-forge channel for compatibility and ease of installation. This command includes many optional but useful packages. ```shell mamba install scikit-learn pandas statsmodels prophet numexpr bottleneck tqdm holidays lightgbm matplotlib requests xgboost -c conda-forge pip install mxnet --no-deps pip install yfinance pytrends fredapi gluonts arch pip install intel-tensorflow scikit-learn-intelex mamba install spyder mamba install autots -c conda-forge ``` -------------------------------- ### Install Spyder IDE in GPU Environment Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Installs the Spyder IDE within the 'gpu' conda environment, allowing for development and debugging of GPU-accelerated applications. ```bash mamba install spyder ``` -------------------------------- ### Python: Advanced Constraint Examples for Forecasting Source: https://github.com/winedarksea/autots/blob/master/extended_tutorial.md This Python code illustrates various advanced constraints used in AutoTS for forecasting. It includes examples for quantile, slope, last_window, stdev_min, stdev, historic_growth, historic_diff, and dampening constraints, each with specific parameters for controlling forecast behavior. ```python constraint = {"constraints": [ { # don't exceed historic max "constraint_method": "quantile", "constraint_value": 1.0, "constraint_direction": "upper", "constraint_regularization": 1.0, "bounds": True, }, { # don't exceed 2% growth by end of forecast horizon "constraint_method": "slope", "constraint_value": {"slope": 0.02, "window": 10, "window_agg": "max", "threshold": 0.01}, "constraint_direction": "upper", "constraint_regularization": 0.9, "bounds": False, }, { # don't go below the last 10 values - 10% "constraint_method": "last_window", "constraint_value": {"window": 10, "threshold": -0.1}, "constraint_direction": "lower", "constraint_regularization": 1.0, "bounds": False, }, { # don't go below historic min - 1 st dev "constraint_method": "stdev_min", "constraint_value": 1.0, "constraint_direction": "lower", "constraint_regularization": 1.0, "bounds": True, }, { # don't go above historic mean + 3 st devs, soft limit "constraint_method": "stdev", "constraint_value": 3.0, "constraint_direction": "upper", "constraint_regularization": 0.5, "bounds": True, }, { # use a log curve shaped by the historic min/max growth rate to limit "constraint_method": "historic_growth", "constraint_value": {'threshold': 2.0, 'window': 360}, "constraint_direction": "upper", "constraint_regularization": 1.0, "bounds": True, }, { # like slope but steps 'constraint_method': 'historic_diff', 'constraint_direction': 'upper', 'constraint_regularization': 1.0, 'constraint_value': 1.0, 'bounds_only': True, 'fillna': None }, { # flattens out series, regardless "constraint_method": "dampening", "constraint_value": 0.98, "bounds": True, }, ] } ``` -------------------------------- ### GET /load_daily Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.html Loads a daily sample dataset for testing or demonstration purposes. ```APIDOC ## GET /load_daily ### Description Loads daily sample data. This data is often chosen to showcase holidays or holiday-like patterns. ### Method GET ### Endpoint /load_daily ### Parameters #### Query Parameters - **long** (bool) - Optional - If True, returns data in long format; if False, returns data in wide format. Defaults to True. ### Request Example ```json { "long": false } ``` ### Response #### Success Response (200) - **data** (object) - The loaded daily sample data (DataFrame). #### Response Example ```json { "data": "... pandas DataFrame ..." } ``` ``` -------------------------------- ### Loading Built-in Datasets in AutoTS (Python) Source: https://context7.com/winedarksea/autots/llms.txt Provides examples of how to load various built-in sample datasets provided by the AutoTS package. It demonstrates loading daily, hourly, monthly, and yearly data in both wide and long formats. It also includes an example of loading live data from external sources using API keys. ```python from autots import ( load_daily, load_hourly, load_monthly, load_yearly, load_weekly, load_live_daily ) # Load various sample datasets df_daily = load_daily(long=False) df_hourly = load_hourly(long=True) df_monthly = load_monthly(long=False) df_yearly = load_yearly(long=False) # Load live data from various sources (requires API keys) df_live = load_live_daily( long=False, fred_key="your_fred_api_key", fred_series=["DGS10", "SP500", "DEXUSEU"], tickers=["MSFT", "AAPL"], wikipedia_pages=["United_States", "Python_(programming_language)"], weather_stations=["USW00014771"], sleep_seconds=15 ) ``` -------------------------------- ### Exporting and Importing AutoTS Model Templates Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html This example shows how to export the best performing models after training to a template file (CSV or JSON). It then demonstrates how to import this template on a new run to prioritize specific models, improving fault tolerance and model selection flexibility. Dependencies include the 'autots' library. ```python # after fitting an AutoTS model example_filename = "example_export.csv" # .csv/.json model.export_template(example_filename, models='best', n=15, max_per_model_class=3) # on new training model = AutoTS(forecast_length=forecast_length, frequency='infer', max_generations=0, num_validations=0, verbose=0) model = model.import_template(example_filename, method='only') # method='add on' print("Overwrite template is: {}".format(str(model.initial_template))) ``` -------------------------------- ### Create GPU-Enabled Conda Environment Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Creates a new conda environment named 'gpu' with Python 3.8 and installs core data science packages. This environment is intended for GPU-accelerated workloads. ```bash mamba create -n gpu python=3.8 scikit-learn pandas statsmodels prophet numexpr bottleneck tqdm holidays lightgbm matplotlib requests -c conda-forge mamba activate gpu ``` -------------------------------- ### Generate Predictions and Plot Results with AutoTS Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html This code shows how to generate forecasts using a fitted AutoTS model and then visualize the predictions against the original data. It also includes an example of plotting a pie chart breakdown of MAPE per series. ```python import matplotlib.pyplot as plt model = AutoTS().fit(df) prediction = model.predict() prediction.plot( model.df_wide_numeric, series=model.df_wide_numeric.columns[2], remove_zeroes=False, start_date="2018-09-26", ) plt.show() model.plot_per_series_mape(kind="pie") plt.show() ``` -------------------------------- ### Time Series Forecasting with External Variables using AutoTS Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html This example demonstrates forecasting traffic volume on Interstate 94 by including weather data as external variables. It shows how to assign weights to different time series and utilize AutoTS's model selection and forecasting capabilities. Dependencies include the 'autots' library and its datasets module. ```python from autots import AutoTS from autots.datasets import load_hourly df_wide = load_hourly(long=False) # here we care most about traffic volume, all other series assumed to be weight of 1 weights_hourly = {'traffic_volume': 20} model_list = [ 'LastValueNaive', 'GLS', 'ETS', 'AverageValueNaive', ] model = AutoTS( forecast_length=49, frequency='infer', prediction_interval=0.95, ensemble=['simple', 'horizontal-min'], max_generations=5, num_validations=2, validation_method='seasonal 168', model_list=model_list, transformer_list='all', models_to_validate=0.2, drop_most_recent=1, n_jobs='auto', ) model = model.fit( df_wide, weights=weights_hourly, ) prediction = model.predict() forecasts_df = prediction.forecast # prediction.long_form_results() upper_forecasts_df = prediction.upper_forecast lower_forecasts_df = prediction.lower_forecast ``` -------------------------------- ### Running a Single Forecasting Model with AutoTS Source: https://github.com/winedarksea/autots/blob/master/extended_tutorial.md This example demonstrates how to run a single, specified forecasting model using the `model_forecast` function in AutoTS. It requires the data to be in a 'wide' format and numeric. The function allows for detailed parameter configuration, including model name, parameters, transformations, and training data, returning the forecast results. ```python from autots import load_daily, model_forecast df = load_daily(long=False) # long or non-numeric data won't work with this function df_forecast = model_forecast( model_name="AverageValueNaive", model_param_dict={'method': 'Mean'}, model_transform_dict={ 'fillna': 'mean', 'transformations': {'0': 'DifferencedTransformer'}, 'transformation_params': {'0': {}} }, df_train=df, forecast_length=12, frequency='infer', prediction_interval=0.9, no_negatives=False, # future_regressor_train=future_regressor_train2d, # future_regressor_forecast=future_regressor_forecast2d, random_seed=321, verbose=0, n_jobs="auto", ) df_forecast.forecast.head(5) ``` -------------------------------- ### AutoTS Simple Forecasting Example in Python Source: https://github.com/winedarksea/autots/blob/master/extended_tutorial.md This Python code snippet illustrates a basic time series forecasting task using the AutoTS library. It loads monthly data, initializes the AutoTS model with specific parameters like forecast length and ensemble type, fits the model to the data, and prints the description of the best performing model. Dependencies include the 'autots' and 'pandas' libraries. The input data is expected in a long format DataFrame with columns for date, value, and series ID. ```python # also: _hourly, _daily, _weekly, or _yearly from autots.datasets import load_monthly df_long = load_monthly(long=True) from autots import AutoTS model = AutoTS( forecast_length=3, frequency='infer', ensemble='simple', max_generations=5, num_validations=2, ) model = model.fit(df_long, date_col='datetime', value_col='value', id_col='series_id') # Print the description of the best model print(model) ``` -------------------------------- ### Anomaly Detection with AutoTS Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html This snippet demonstrates how to initialize and use the AnomalyDetector from the AutoTS library. It shows how to get new parameters, create an AnomalyDetector instance, detect anomalies in a DataFrame, and visualize the results. The meaning of the 'scores' attribute varies depending on the detection method used. ```python params = AnomalyDetector.get_new_params() mod = AnomalyDetector(output='multivariate', **params) mod.detect(df) mod.plot() mod.scores # meaning of scores varies by method ``` -------------------------------- ### AutoTS Model Prediction Example Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.evaluator.html Demonstrates how to generate forecasts using the AutoTS model. It shows how to use an existing model for high-speed forecasting without retraining, and how to force retraining if needed. This is useful for scenarios where immediate forecasts are required. ```python model = AutoTS(model_list='update_fit') model.fit(df) model.predict() # for new data without retraining model.fit_data(df) model.predict() # to force retrain of best model (but not full model search) model.model = None model.fit_data(df) model.predict() ``` -------------------------------- ### Forecasting Traffic with External Variables and Model Lists in AutoTS Source: https://github.com/winedarksea/autots/blob/master/extended_tutorial.md This example demonstrates forecasting traffic volume using AutoTS, incorporating external variables like weather data with specific weights. It also shows how to define a custom model list for the forecasting process. The output includes the main forecast and probabilistic upper and lower bounds. ```python from autots import AutoTS from autots.datasets import load_hourly df_wide = load_hourly(long=False) # here we care most about traffic volume, all other series assumed to be weight of 1 weights_hourly = {'traffic_volume': 20} model_list = [ 'LastValueNaive', 'GLS', 'ETS', 'AverageValueNaive', ] model = AutoTS( forecast_length=49, frequency='infer', prediction_interval=0.95, ensemble=['simple', 'horizontal-min'], max_generations=5, num_validations=2, validation_method='seasonal 168', model_list=model_list, t transformer_list='all', models_to_validate=0.2, drop_most_recent=1, n_jobs='auto', ) model = model.fit( df_wide, weights=weights_hourly, ) prediction = model.predict() forecasts_df = prediction.forecast # prediction.long_form_results() upper_forecasts_df = prediction.upper_forecast lower_forecasts_df = prediction.lower_forecast ``` -------------------------------- ### AutoTS Basic Model Fitting and Prediction (Python) Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Demonstrates how to load monthly data, initialize the AutoTS model with specified parameters, fit the model to the data, and print the best model's description. It handles data in a long format with datetime, value, and series ID columns. ```Python from autots.datasets import load_monthly df_long = load_monthly(long=True) from autots import AutoTS model = AutoTS( forecast_length=3, frequency='infer', ensemble='simple', max_generations=5, num_validations=2, ) model = model.fit(df_long, date_col='datetime', value_col='value', id_col='series_id') # Print the description of the best model print(model) ``` -------------------------------- ### Run AutoTS Speed Benchmark Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html This Python code snippet shows how to initialize and run the Benchmark class from AutoTS to measure performance. It allows specifying the number of parallel jobs and the number of times to run the benchmark. ```python from autots.evaluator.benchmark import Benchmark bench = Benchmark() bench.run(n_jobs="auto", times=3) print(bench.results) ``` -------------------------------- ### Create and Activate Conda Environment Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Creates a new conda environment named 'timeseries' with Python 3.9 and activates it. This is a foundational step for managing project dependencies. ```bash conda create -n timeseries python=3.9 conda activate timeseries ``` -------------------------------- ### GET /load_artificial Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.html Loads artificially generated time series data from random distributions. ```APIDOC ## GET /load_artificial ### Description Load artificially generated series from random distributions. ### Method GET ### Endpoint /load_artificial ### Parameters #### Query Parameters - **long** (bool) - Optional - If True, returns data in long format; if False, returns data in wide format. Defaults to False. - **date_start** (str or datetime.datetime) - Optional - The start date for the generated series. - **date_end** (str or datetime.datetime) - Optional - The end date for the generated series. ### Request Example ```json { "long": true, "date_start": "2023-01-01", "date_end": "2023-12-31" } ``` ### Response #### Success Response (200) - **data** (object) - The loaded artificial time series data (DataFrame). #### Response Example ```json { "data": "... pandas DataFrame ..." } ``` ``` -------------------------------- ### AutoTS Anomaly Detection with Holiday Detection Source: https://github.com/winedarksea/autots/blob/master/extended_tutorial.md Shows how to use AutoTS for anomaly detection, including holiday detection. It loads sample data, initializes AnomalyDetector and HolidayDetector, performs detection, and visualizes results. Requires an internet connection for data loading. ```python from autots.evaluator.anomaly_detector import AnomalyDetector, HolidayDetector from autots.datasets import load_live_daily import pandas as pd # internet connection required to load this df wiki_pages = [ "Standard_deviation", "Christmas", "Thanksgiving", "all", ] df = load_live_daily( long=False, fred_series=None, tickers=None, trends_list=None, earthquake_min_magnitude=None, weather_stations=None, london_air_stations=None, gov_domain_list=None, weather_event_types=None, wikipedia_pages=wiki_pages, sleep_seconds=5, ) params = AnomalyDetector.get_new_params() mod = AnomalyDetector(output='multivariate', **params) mod.detect(df) mod.plot() # holiday detection, random parameters holiday_params = HolidayDetector.get_new_params() mod = HolidayDetector(**holiday_params) mod.detect(df) full_dates = pd.date_range("2014-01-01", "2024-01-01", freq='D') prophet_holidays = mod.dates_to_holidays(full_dates, style="prophet") mod.plot() ``` -------------------------------- ### GET /infer_frequency Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.html Infers the frequency of a time series dataset in a more robust manner than standard pandas methods. ```APIDOC ## GET /infer_frequency ### Description Infers the frequency in a slightly more robust way than `pd.infer_freq`. ### Method GET ### Endpoint /infer_frequency ### Parameters #### Query Parameters - **df_wide** (pd.DataFrame or pd.DatetimeIndex) - Required - Input to pull frequency from. - **warn** (bool) - Optional - Unused, here to make swappable with `pd.infer_freq`. Defaults to True. ### Request Example ```json { "df_wide": "... pandas DataFrame or DatetimeIndex ...", "warn": false } ``` ### Response #### Success Response (200) - **frequency** (str) - The inferred frequency of the time series. #### Response Example ```json { "frequency": "D" } ``` ``` -------------------------------- ### Accessing Available Transformers in AutoTS Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Shows how to import and access the dictionary of available transformers from AutoTS. This allows users to see which transformations can be applied and to potentially use them independently. ```python from autots.tools.transform import transformer_dict, DifferencedTransformer from autots import load_monthly print(f"Available transformers are: {transformer_dict.keys()}") ``` -------------------------------- ### Get Current Parameters of NeuralProphet Model Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.models.html Returns a dictionary representing the current set of parameters configured for the NeuralProphet model. ```python get_params() ``` -------------------------------- ### Get Current Parameters (Python) Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.models.html Returns a dictionary representing the current parameters of the model object. This is useful for inspecting the active configuration. ```python def get_params(): """Return dict of current parameters.""" pass ``` -------------------------------- ### Run Autots Speed Benchmark Source: https://github.com/winedarksea/autots/blob/master/extended_tutorial.md This snippet demonstrates how to initialize and run the Benchmark class from autots.evaluator.benchmark to measure the speed of the AutoTS model. It specifies the number of parallel jobs and the number of times to run the benchmark. The results are then accessible via the 'results' attribute. ```python from autots.evaluator.benchmark import Benchmark bench = Benchmark() bench.run(n_jobs="auto", times=3) bench.results ``` -------------------------------- ### Initialize and Fit AutoTS Model with Custom Weights Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html This code snippet demonstrates initializing the AutoTS model with a specified forecast length, frequency inference, and custom metric weights. It then fits the model to the provided dataframe (df). ```python model = AutoTS( forecast_length=forecast_length, frequency='infer', metric_weighting=metric_weighting, ) model.fit(df) ``` -------------------------------- ### Get Total Runtime Information (Python) Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.models.html Calculates and returns the total runtime for all components of the model prediction in seconds. This helps in performance analysis. ```python def total_runtime(): """return runtime for all model components in seconds""" pass ``` -------------------------------- ### Plotting Backforecast (Python) Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Generates a backforecast plot for a specified number of splits and a start date. This function is marked as potentially slow and is conditionally executed. ```python if False: # slow model.plot_backforecast(n_splits="auto", start_date="2019-01-01") ``` -------------------------------- ### Get Current Parameters for UnobservedComponents Model Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.models.html Retrieves a dictionary of the current parameters for the UnobservedComponents model. This function allows users to inspect the model's configuration. ```python unobserved_components_model.get_params() ``` -------------------------------- ### Get Static Time Information (Python) Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.models.html Retrieves static time-related information. This method is part of the base ModelObject and might be used for timing or scheduling operations. ```python def time(): """_static_ time()""" pass ``` -------------------------------- ### Data Transformation Example: DifferencedTransformer in autots Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.templates.html Configuration for the DifferencedTransformer, used for differencing time series data. It includes parameters for clipping outliers and transforming the output distribution. ```python { "0": {"method": "clip", "std_threshold": 3, "fillna": null}, "1": {"output_distribution": "uniform", "n_quantiles": 1000}, "2": {} } ``` -------------------------------- ### PreprocessingRegression Model Template Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.templates.html Configuration for the PreprocessingRegression model. This includes parameters for window size, history, and normalization, along with a detailed transformation dictionary. The transformation dictionary specifies fill methods, various transformations like DifferencedTransformer and QuantileTransformer, and their respective parameters. ```json { "Ensemble": 0, "Model": "PreprocessingRegression", "ModelParameters": "{\"window_size\": 28, \"max_history\": null, \"one_step\": true, \"normalize_window\": false, \"processed_y\": true, \"transformation_dict\": {\"fillna\": \"fake_date\", \"transformations\": {\"0\": \"DifferencedTransformer\", \"1\": \"QuantileTransformer\", \"2\": \"SeasonalDifference\", \"3\": \"Discretize\"}, \"transformation_params\": {\"0\": {\"lag\": 1, \"fill\": \"bfill\"}, \"1\": {\"output_distribution\": \"uniform\", \"n_quantiles\": 268}, \"2\": {\"lag_1\": 2, \"method\": \"LastValue\"}, \"3\": {\"discretization\": \"upper\", \"n_bins\": 10}}}, \"datepart_method\": \"simple\", \"regression_type\": null, \"regression_model\": {\"model\": \"LightGBM\", \"model_params\": {\"colsample_bytree\": 0.1645, \"learning_rate\": 0.0203, \"max_bin\": 1023, \"min_child_samples\": 16, \"n_estimators\": 1794, \"num_leaves\": 15, \"reg_alpha\": 0.00098, \"reg_lambda\": 0.686}}}", "TransformationParameters": "{\"fillna\": \"fake_date\", \"transformations\": {\"0\": \"DifferencedTransformer\", \"1\": \"QuantileTransformer\", \"2\": \"SeasonalDifference\", \"3\": \"Discretize\"}, \"transformation_params\": {\"0\": {\"lag\": 1, \"fill\": \"bfill\"}, \"1\": {\"output_distribution\": \"uniform\", \"n_quantiles\": 268}, \"2\": {\"lag_1\": 2, \"method\": \"LastValue\"}, \"3\": {\"discretization\": \"upper\", \"n_bins\": 10}}}" } ``` -------------------------------- ### AutoTS Prediction and Forecasting Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Demonstrates how to make predictions using a trained AutoTS model and extract forecasted values. It also shows how to print the model details. ```python forecasts_df = prediction.forecast # then with another prediction_2 = model.predict(future_regressor=future_regressor_forecast_2, verbose=0) forecasts_df_2 = prediction_2.forecast print(model) ``` -------------------------------- ### Get Current Parameters for GLS Model Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.models.html Retrieves a dictionary containing the current parameter settings for the GLS model. This is useful for understanding the model's configuration before or after training. ```python gls_model.get_params() ``` -------------------------------- ### Get New Parameters for NeuralProphet Tuning Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.models.html Retrieves a dictionary containing new parameters suitable for tuning the NeuralProphet model. The 'random' method is the default for parameter generation. ```python get_new_params(_method: str = 'random'_) ``` -------------------------------- ### Get Complete Results in Long Form (Python) Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.models.html Returns the complete forecast results formatted in a long (tabular) format. This is useful for detailed analysis and reporting. ```python def long_form_results(): """return complete results in long form""" pass ``` -------------------------------- ### Get Last Window from DataFrame (Python) Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.tools.html A pandas-based function to extract the last window of data from a DataFrame. Allows for specifying window size, input dimension, and normalization. ```python import pandas as pd def last_window(_df_, _window_size: int = 10_, _input_dim: str = 'univariate'_, _normalize_window: bool = False_): """Pandas based function to provide the last window of window_maker. """ # Implementation details would go here pass # Example usage: # df = pd.DataFrame({'col1': range(50)}) # last_win = last_window(df, window_size=5) ``` -------------------------------- ### AutoTS Model Fitting and Prediction Source: https://github.com/winedarksea/autots/blob/master/extended_tutorial.md Demonstrates fitting an AutoTS model, making predictions, and generating historic forecasts. It also shows how to evaluate predictions against actual data and plot results. Dependencies include numpy and scikit-learn. ```python model.fit() risk_df_upper, risk_df_lower = model.predict() historic_upper_risk_df, historic_lower_risk_df = model.predict_historic(lower_limit=historic_lower_limit) model.plot(0) threshold = 0.1 eval_lower = EventRiskForecast.generate_historic_risk_array(df_test, model.lower_limit_2d, direction="lower") eval_upper = EventRiskForecast.generate_historic_risk_array(df_test, model.upper_limit_2d, direction="upper") pred_lower = np.where(model.lower_risk_array > threshold, 1, 0) pred_upper = np.where(model.upper_risk_array > threshold, 1, 0) model.plot_eval(df_test, 0) multilabel_confusion_matrix(eval_upper, pred_upper).sum(axis=0) print(classification_report(eval_upper, pred_upper, zero_division=1)) ``` -------------------------------- ### Exporting and Importing AutoTS Model Templates for Deployment Source: https://github.com/winedarksea/autots/blob/master/extended_tutorial.md This snippet illustrates how to export the best-performing model templates after training an AutoTS model, saving them to a file (CSV or JSON). It then shows how to import this template on a subsequent run to load only those specific models, aiding in deployment and fault tolerance. The imported template's configuration is printed. ```python # after fitting an AutoTS model example_filename = "example_export.csv" # .csv/.json model.export_template(example_filename, models='best', n=15, max_per_model_class=3) # on new training model = AutoTS(forecast_length=forecast_length, frequency='infer', max_generations=0, num_validations=0, verbose=0) model = model.import_template(example_filename, method='only') # method='add on' print("Overwrite template is: {}".format(str(model.initial_template))) ``` -------------------------------- ### AverageValueNaive Model - Get Parameters Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.models.html Retrieves the current parameters of the AverageValueNaive model. This is useful for inspecting the model's configuration before or after training. It does not take any arguments and returns a dictionary of parameters. ```python from autots.models.basics import AverageValueNaive model = AverageValueNaive() current_params = model.get_params() print(current_params) ``` -------------------------------- ### Get New Parameters for Tuning (Python) Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.models.html Retrieves a dictionary of new parameters suitable for further tuning. This function is part of the autots model object's parameter management capabilities. ```python def get_params(): """Return dict of new parameters for parameter tuning.""" pass ``` -------------------------------- ### Summarize Time Series Data Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.tools.html Summarizes time series data from a wide format DataFrame with a datetime index. This function is useful for getting a concise overview of the time series. ```python from autots.tools.profile import summarize_series # Assuming 'df' is a pandas DataFrame with datetime index and time series columns # summary = summarize_series(df) ``` -------------------------------- ### Get Current Parameters for Theta Model Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.models.html Retrieves a dictionary containing the current parameter settings for the Theta model. This method is essential for inspecting the model's configuration and current state. ```python theta_model.get_params() ``` -------------------------------- ### Various Constraint Methods in AutoTS Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/tutorial.html Illustrates a comprehensive set of constraints available in AutoTS, including quantile, slope, last_window, stdev_min, stdev, historic_growth, historic_diff, and dampening. Each constraint type has specific parameters for defining its behavior and application. ```python constraint = {"constraints": [ { # don't exceed historic max "constraint_method": "quantile", "constraint_value": 1.0, "constraint_direction": "upper", "constraint_regularization": 1.0, "bounds": True, }, { # don't exceed 2% growth by end of forecast horizon "constraint_method": "slope", "constraint_value": {"slope": 0.02, "window": 10, "window_agg": "max", "threshold": 0.01}, "constraint_direction": "upper", "constraint_regularization": 0.9, "bounds": False, }, { # don't go below the last 10 values - 10% "constraint_method": "last_window", "constraint_value": {"window": 10, "threshold": -0.1}, "constraint_direction": "lower", "constraint_regularization": 1.0, "bounds": False, }, { # don't go below historic min - 1 st dev "constraint_method": "stdev_min", "constraint_value": 1.0, "constraint_direction": "lower", "constraint_regularization": 1.0, "bounds": True, }, { # don't go above historic mean + 3 st devs, soft limit "constraint_method": "stdev", "constraint_value": 3.0, "constraint_direction": "upper", "constraint_regularization": 0.5, "bounds": True, }, { # use a log curve shaped by the historic min/max growth rate to limit "constraint_method": "historic_growth", "constraint_value": {'threshold': 2.0, 'window': 360}, "constraint_direction": "upper", "constraint_regularization": 1.0, "bounds": True, }, { # like slope but steps 'constraint_method': 'historic_diff', 'constraint_direction': 'upper', 'constraint_regularization': 1.0, 'constraint_value': 1.0, 'bounds_only': True, 'fillna': None }, { # flattens out series, regardless "constraint_method": "dampening", "constraint_value": 0.98, "bounds": True, }, ]} ``` -------------------------------- ### UnivariateMotif Model Configuration Source: https://github.com/winedarksea/autots/blob/master/docs/build/html/source/autots.templates.html Defines parameters for the UnivariateMotif model, including window size, distance metric, and transformation settings like imputation and scaling. Supports different parameter sets for varying window sizes and metrics. ```json { "window": 60, "point_method": "median", "distance_metric": "canberra", "k": 10, "max_windows": 10000 } ``` ```json { "window": 14, "point_method": "median", "distance_metric": "minkowski", "k": 5, "max_windows": 10000 } ```