Tangent API Python Package
The TangentWorks library serves as a central interface for advanced time-series forecasting, anomaly detection, and insights extraction. It simplifies complex data operations, enabling users to build models, make predictions, detect anomalies, and gain insights efficiently.
Class Overview
The tangent_works package acts as the main entry point to the library, exposing APIs for:
Forecasting
Anomaly Detection
Each of these APIs comes with specialized methods to perform their respective operations.
Installation
Visit https://pypi.org/project/tangent-works/ for more details about the Python package.
To install with pip, execute the following command.
pip install tangent-works
Dependencies: requests, pandas, numpy, plotly
Quick Start
A minimal example to quickly get started.
import tangent_works
import pandas as pd
tw = tangent_works.API(token=TANGENT_LICENSE_TOKEN)
configuration = {}
data = pd.read_csv("input.csv")
auto_forecast_response = tw.auto_forecast.run(
configuration=configuration,
dataset=dataset
)
results = auto_forecast_response['results']
print(result)
Initialization
To start using the tangent_works library, initialize the API class by providing a valid Tangent License token.
import tangent_works
tw = tangent_works.API(token=TANGENT_LICENSE_TOKEN)
This initializes the following components:
forecast: A high level controller for time-series forecasting tasks.anomaly_detection: A high level controller for identifying and analyzing anomalies.auto_forecast: A High-level controller for the auto-forecast workflow.processing: Post-processing utilities for transforming API responses into DataFrames.visualization: Static Plotly visualization helpers.endpoints: Low-level HTTP wrappers for direct endpoint access.
Attributes and Methods
The package is designed to allow two ways of using it. Directly accessing the API through the endpoint methods or use the controllers for a more user friendly and interactive experience in Python.
1. Endpoints
The endpoint class follows the design of the Tangent API which can be found here:
https://api.tangent.works/swagger-ui.html. A method exists for each endpoint in the API.
It contains 3 subclasses following the sections of the API:
Forecast
Provides a robust set of tools for building forecasting models, making predictions, performing root cause analysis (RCA), and automating the forecasting process.
Navigate to: tw.endpoints.forecast
Available Methods:
build_model: Creates a forecasting model job using a configuration and dataset.status: Collects the status of a forecasting job.model: Collects a forecasting model object.predict: Creates a predict job which generates forecasts using a pre-built model.results: Collects forecast results containing the predictions.rca: Creates a root cause analysis job for forecasting.rca_table: Collects the RCA results.delete: Deletes all information from the API related to a forecast job.
Anomaly Detection
Facilitates the detection of anomalies in datasets through model building, anomaly detection, and root cause analysis (RCA).
Navigate to: tw.endpoints.anomaly_detection
Available Methods:
build_model: Creates an anomaly detection model job using a configuration and dataset.status: Collects the status of an anomaly detection job.model: Collects an anomaly detection model object.detect: Creates a detect job which generates detections using a pre-built model.results: Collects detection results containing the anomalies.rca: Creates a root cause analysis job for anomaly detection.rca_table: Collects the RCA results.delete: Deletes all information from the API related to an anomaly detection job.
Auto Forecast
Combines the power of model building and prediction in forecasting into 1 step allowing for a quick and dynamic forecasting process.
Navigate to: tw.endpoints.auto_forecast
Available Methods:
post: Creates an auto forecast job.status: Collects the status of an auto forecast job.model: Collects a forecasting model object.results: Collects auto forecast results containing the predictions.delete: Deletes all information from the API related to a auto forecast job.
2. Controllers
The controller classes leverage and combine the endpoint methods in higher level methods to facilitate the forecasting, anomaly detection and auto forecasting.
Forecast
Automatically create forecasting jobs and collect the results.
Navigate to: tw.forecast
Available Methods:
build_model: Creates a forecasting model job using a configuration and dataset.predict: Creates a predict job which generates forecasts using a pre-built model.rca: Creates a root cause analysis job for forecasting.
Anomaly Detection
Automatically create anomaly detection jobs and collect the results.
Navigate to: tw.anomaly_detection
Available Methods:
build_model: Creates an anomaly detection model job and collects the results.detect: Creates a detect job which generates detections using a pre-built model and collects the results.rca: Creates a root cause analysis job for anomaly detection and collects the results.
Auto Forecast
Automatically create auto forecasting jobs and collect the results.
Navigate to: tw.auto_forecast
Available Methods:
run: Creates an auto forecast job and collects the results.
3. Processing
Provides tools for extracting and interpreting variable properties and features from models.
Navigate to: tw.processing
Available Methods:
properties: Retrieves and processes the variable properties of a given model, ranked by importance.features: Extracts features used in the given model for interpretation and analysis.
4. Visualization
Helper methods to visualize the various outputs from Tangent.
Navigate to: tw.visualization
Available Methods:
data: Two-panel line chart: target on the top panel, predictors on the bottom panel. Useful for exploring raw input data before modelling.predictions: Line chart of actual target vs. forecast, color-coded by prediction type: training (green), testing (red), production (goldenrod).detections: Two-panel anomaly-detection chart. Top panel: target and normal-behavior estimate, with anomaly events marked as red dots. Bottom panel: the anomaly indicator signal with a threshold line at 1.predictor_importance: Bar chart of the relative contribution of predictive value from individual columns.feature_importance: Treemap of model feature importances, grouped by model and feature.rca_terms: Line chart of RCA term contributions over time.rca_timestamp: Interactive slider chart for root-cause analysis at a specific timestamp. Each slider step shows a different model term's contribution at the selected timestamp in context.
Key Benefits
Centralized Interface: Access all functionalities via a single class.
Scalability: Perform advanced operations on large-scale datasets.
Flexibility: Tailor configurations for specific use cases.