https://github.com/yutsuro/pytorch-time-series-classification
Simple model creation for time series classification in Pytorch
https://github.com/yutsuro/pytorch-time-series-classification
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (9.5%) to scientific vocabulary
Keywords
Repository
Simple model creation for time series classification in Pytorch
Basic Info
Statistics
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 3
- Releases: 3
Topics
Metadata Files
README.md
tisc: pytorch-time-series-classification
Simple model creation and training framework for time series classification in Pytorch.
What can you do with tisc?
tisc is a simple framework for time series classification in Pytorch.
- You can create a Pytorch model for time series classification with just one function.
- You can choose the model from many supported models.
- You can train the model with just one method.
- You can evaluate or predict with the trained model with just one method.
Setup
1. Install tisc
bash
pip install tisc
2. Install Pytorch
If Pytorch is not installed to your environment, you have to install Pytorch that matches your environment from the official website: https://pytorch.org/get-started/locally/
example (this command is for my environment):
bash
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
Usage
0. Prepare the dataset / dataloader
Time series data
The time series data should be a 3D tensor with the shape of (number_of_samples, timestep, dimentions).
For example, if you have a dataset with 1000 samples, each sample has 20 timesteps, and each timestep has 100 dimentions, the shape of the dataset should be (1000, 20, 100).
The label should be a 1D tensor with the shape of (number_of_samples,).
For example, if you have a dataset with 1000 samples, the shape of the label should be (1000,).
```python import torch
The shape of the time series data should be (numberofsamples, timestep, dimentions)
print(train_data.shape) # (1000, 20, 100)
The shape of the label should be (numberofsamples,)
print(train_label.shape) # (1000,) ```
Dataset
tisc supports the dataset that is a subclass of torch.utils.data.Dataset.
The dataset should return a tuple of (data, label) in the __getitem__ method.
You can use TensorDataset from torch.utils.data to create a dataset from the time series data and the label easily.
```python import torch from torch.utils.data import TensorDataset
Prepare the dataset with TensorDataset
traindataset = TensorDataset(traindata, trainlabel) valdataset = TensorDataset(valdata, vallabel) testdataset = TensorDataset(testdata, test_label)
Check the type of the dataset
print(type(train_dataset)) #
Dataloader
You have to use torch.utils.data.DataLoader to load the dataset.
```python import torch from torch.utils.data import DataLoader
Prepare the dataset
trainloader = DataLoader(traindataset, batchsize=512, shuffle=True) valloader = DataLoader(valdataset, batchsize=512, shuffle=False) testloader = DataLoader(testdataset, batch_size=512, shuffle=False)
Check the type of the dataloader
print(type(train_loader)) #
1. Create a classifier
You can create a classifier with the build_classifier function.
The build_classifier function returns a tisc.Classifier object.
A Classifier object contains the model, the optimizer, the loss function, and the training and evaluation methods.
When you create a classifier, you have to pass the following arguments:
model_name: The name of the model. The model should be one of the supported models. (e.g.,'LSTM','BiLSTM','Transformer')timestep: The number of timesteps in the time series data.dimentions: The number of dimentions in each timestep.num_classes: The number of classes in the dataset.
```python import tisc
Create a classifier
classifier = tisc.buildclassifier(modelname='LSTM', timestep=20, dimentions=100, num_classes=10)
Check the type of the classifier
print(type(classifier)) #
2. Train the classifier
You can train the classifier with the train method.
The train method requires the following arguments:
epochs: The number of epochs to train the classifier.train_loader: The dataloader for the training dataset.
you can pass val_loader to train the classifier with validation.
```python classifier.train(train_loader, epochs=100)
If the val_loader argument is passed, you can train the classifier with validation.
classifier.train(trainloader, valloader=val_loader, epochs=100) ```
3. Evaluate the classifier
You can evaluate the classifier with the evaluate method.
The evaluate method requires the following arguments:
test_loader: The dataloader for the test dataset.
The evaluate method can return the classification report and the confusion matrix if you pass the return_report and return_confusion_matrix arguments as True.
If with_best_model argument is True, the classifier will use the best model that marked the best result about the model saving strategy.
python
classifier.evaluate(test_loader,
return_report=True,
return_confusion_matrix=True,
with_best_model=True)
Supported models
The models that can be used in version 0.1.2:
- LSTM
- BiLSTM
- Transformer
and more! (More models will be added.)
Owner
- Name: Yuki Utsuro
- Login: Yutsuro
- Kind: user
- Website: https://yuki.utsu.ro
- Twitter: __yutsuro__
- Repositories: 2
- Profile: https://github.com/Yutsuro
GitHub Events
Total
- Issues event: 2
- Watch event: 4
- Issue comment event: 4
- Push event: 1
- Pull request event: 1
Last Year
- Issues event: 2
- Watch event: 4
- Issue comment event: 4
- Push event: 1
- Pull request event: 1
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 4
- Total pull requests: 2
- Average time to close issues: about 2 months
- Average time to close pull requests: less than a minute
- Total issue authors: 3
- Total pull request authors: 1
- Average comments per issue: 0.5
- Average comments per pull request: 0.0
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 2
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 1
- Pull request authors: 0
- Average comments per issue: 0.0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- chensohg (1)
- AsadKhanDigital (1)
- Yutsuro (1)
Pull Request Authors
- Yutsuro (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 32 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 3
- Total maintainers: 1
pypi.org: tisc
Simple model creation and training framework for time series classification in Pytorch
- Homepage: https://github.com/Yutsuro/pytorch-time-series-classification
- Documentation: https://tisc.readthedocs.io/
- License: Apache
-
Latest release: 0.1.2
published 6 months ago