Are you ready to dive into the world of time series analysis with tsai, a state-of-the-art deep learning library? Whether you are working on classification, regression, forecasting, or imputation, tsai is here to simplify and enhance the process. In this article, we will guide you on how to install, start, and effectively utilize tsai for your time series projects.
What is tsai?
tsai is an open-source deep learning package built on top of PyTorch and fastai, specifically designed for handling time series tasks. With features like new models, datasets, and tutorials, tsai is continually evolving to support more accurate time series forecasts. Ready to unleash its potential? Let’s jump into the setup!
Installation Steps
There are two main ways to install tsai: via Pip or Conda.
Pip Installation
- To install the latest stable version, run:
python -m pip install tsai
python -m pip install tsai[dev]
Conda Installation
If you prefer Conda, you can install tsai by running:
conda install -c timeseriesai tsai
Basic Usage Overview
Once you have installed tsai, you can start using it in your Python scripts. To get familiar, we recommend the following introductory notebook:
01_Intro_to_Time_Series_Classification
Examples of tsai in Action
Let’s explore a few practical examples of how to leverage tsai for different tasks:
Binary, Univariate Classification
Training:
from tsai.basics import *
X, y, splits = get_classification_data(ECG200, split_data=False)
tfms = [None, TSClassification()]
batch_tfms = TSStandardize()
clf = TSClassifier(X, y, splits=splits, path='models', arch=InceptionTimePlus, tfms=tfms, batch_tfms=batch_tfms, metrics=accuracy, cbs=ShowGraph())
clf.fit_one_cycle(100, 3e-4)
clf.export('clf.pkl')
Inference:
from tsai.inference import load_learner
clf = load_learner('models/clf.pkl')
probas, target, preds = clf.get_X_preds(X[splits[1]], y[splits[1]])
Multivariate Regression
Training:
from tsai.basics import *
X, y, splits = get_regression_data(AppliancesEnergy, split_data=False)
tfms = [None, TSRegression()]
batch_tfms = TSStandardize(by_sample=True)
reg = TSRegressor(X, y, splits=splits, path='models', arch=TSTPlus, tfms=tfms, batch_tfms=batch_tfms, metrics=rmse, cbs=ShowGraph(), verbose=True)
reg.fit_one_cycle(100, 3e-4)
reg.export('reg.pkl')
Inference:
from tsai.inference import load_learner
reg = load_learner('models/reg.pkl')
raw_preds, target, preds = reg.get_X_preds(X[splits[1]], y[splits[1]])
Understanding the Code: An Analogy
Think of using tsai as being akin to cooking a gourmet dish in a kitchen. The ingredients are your data, the recipe represents the code, and the cooking process mirrors the execution of the model.
- The initial step (installing the package) is like gathering all your cookware and ingredients.
- Setting up your training model acts like preparing a cooking process where you mix ingredients (features and labels) carefully following the recipe (code).
- The fitting process is analogous to stirring your dish on a low flame, allowing the flavors to blend, much like your model learns from data.
- Finally, the inference stage is where you plate it (perform predictions) ready for tasting (evaluating the results)!
Troubleshooting Tips
If you encounter any issues while using tsai, here are some troubleshooting ideas:
- Installation Problems: Ensure that you have the latest version of Python installed and that you are using the appropriate pip or conda commands.
- Import Errors: Check your installation directory and ensure that tsai is installed in your active environment.
- Performance Issues: Make sure your datasets are appropriately pre-processed, as raw data can lead to inefficiencies.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.