Skip to content

tcapelle/timeseries_fastai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timeseries_fastai

This repository aims to implement TimeSeries classification/regression algorithms. It makes extensive use of fastai V2!

I recommend to use Ignacio's tsai for a more complete and robust timeseries fastai based library. It is well documented and implemetns way more models that me here.

Installation

You will need to install fastai V2 from here and then you can do from within the environment where you installed fastai V2:

pip install timeseries_fastai

and you are good to go.

TL;DR

git clone https://github.com/fastai/fastai
cd fastai
conda env create -f environment.yml
source activate fastai
pip install fastai timeseries_fastai

Time Series Classification from Scratch with Deep Neural Networks: A Strong Baseline

The original paper repo is here is implemented in Keras/Tf.

InceptionTime: Finding AlexNet for Time SeriesClassification

The original paper repo is here

Results

You can run the benchmark using:

$python ucr.py --arch='inception' --tasks='all' --filename='inception.csv' --mixup=0.2

Default Values:

  • lr = 1e-3
  • opt = 'ranger'
  • epochs = 40
  • fp16 = True
results_inception = pd.read_csv(Path.cwd().parent/'inception.csv', index_col=0)
display_df(results_inception)
acc acc_max train_loss val_loss
task
ACSF1 0.82 0.85 0.77 0.62
Adiac 0.77 0.77 0.81 0.89
ArrowHead 0.70 0.76 0.28 1.21
BME 0.85 0.88 0.21 0.79
Beef 0.77 0.83 0.50 0.53
BeetleFly 0.70 0.85 0.14 0.79
BirdChicken 0.95 0.95 0.14 0.20
CBF 0.95 0.97 0.22 0.24
Car 0.60 0.68 0.33 1.23
Chinatown 0.95 0.96 0.05 0.27
ChlorineConcentration 0.82 0.82 0.28 0.48
CinCECGTorso 0.58 0.60 0.42 1.60
Coffee 0.71 0.82 0.16 0.71
Computers 0.66 0.72 0.24 0.72
CricketX 0.72 0.73 0.49 0.88
CricketY 0.71 0.72 0.53 0.84
CricketZ 0.77 0.78 0.52 0.79
Crop 0.78 0.78 0.56 0.76
DiatomSizeReduction 0.93 0.96 0.22 0.22
DistalPhalanxOutlineAgeGroup 0.71 0.75 0.18 0.80
DistalPhalanxOutlineCorrect 0.74 0.78 0.16 0.57
DistalPhalanxTW 0.62 0.68 0.27 1.22
ECG200 0.87 0.91 0.15 0.30
ECG5000 0.94 0.94 0.17 0.27
ECGFiveDays 0.92 0.94 0.14 0.21
EOGHorizontalSignal 0.36 0.40 0.63 2.05
EOGVerticalSignal 0.37 0.39 0.79 2.00
Earthquakes 0.75 0.75 0.12 0.89
ElectricDevices 0.71 0.72 0.36 1.20
EthanolLevel 0.32 0.36 0.61 1.81
FaceAll 0.77 0.78 0.46 0.84
FaceFour 0.83 0.89 0.29 0.57
FacesUCR 0.83 0.83 0.51 0.73
FiftyWords 0.67 0.69 0.70 1.27
Fish 0.83 0.83 0.45 1.69
FordA 0.95 0.95 0.18 0.13
FordB 0.83 0.85 0.16 0.38
FreezerRegularTrain 0.98 0.99 0.20 0.10
FreezerSmallTrain 0.71 0.81 0.21 1.54
Fungi 0.77 0.85 0.31 0.68
GunPoint 0.95 0.97 0.17 0.14
GunPointAgeSpan 0.97 0.98 0.25 0.08
GunPointMaleVersusFemale 1.00 1.00 0.17 0.02
GunPointOldVersusYoung 1.00 1.00 0.13 0.01
Ham 0.55 0.66 0.21 1.12
HandOutlines 0.89 0.91 0.25 0.29
Haptics 0.38 0.43 0.44 1.94
Herring 0.61 0.70 0.19 0.82
HouseTwenty 0.85 0.88 0.18 0.39
InlineSkate 0.30 0.31 0.95 2.05
InsectEPGRegularTrain 1.00 1.00 0.28 0.08
InsectEPGSmallTrain 0.80 1.00 0.49 0.48
InsectWingbeatSound 0.55 0.56 0.65 1.27
ItalyPowerDemand 0.96 0.96 0.14 0.16
LargeKitchenAppliances 0.85 0.86 0.28 0.69
Lightning2 0.70 0.77 0.18 0.73
Lightning7 0.71 0.73 0.46 1.10
Mallat 0.65 0.66 0.43 1.37
Meat 0.93 0.95 0.25 0.26
MedicalImages 0.72 0.75 0.40 0.85
MelbournePedestrian 0.10 0.10 nan nan
MiddlePhalanxOutlineAgeGroup 0.53 0.60 0.20 1.28
MiddlePhalanxOutlineCorrect 0.77 0.81 0.17 0.46
MiddlePhalanxTW 0.49 0.59 0.34 1.37
MixedShapesRegularTrain 0.93 0.93 0.35 0.25
MixedShapesSmallTrain 0.80 0.81 0.42 0.64
MoteStrain 0.75 0.76 0.09 0.52
NonInvasiveFetalECGThorax1 0.92 0.93 0.66 0.32
NonInvasiveFetalECGThorax2 0.93 0.93 0.59 0.27
OSULeaf 0.82 0.84 0.43 0.58
OliveOil 0.77 0.80 0.27 0.74
PhalangesOutlinesCorrect 0.81 0.83 0.17 0.46
Phoneme 0.22 0.22 0.79 3.25
PigAirwayPressure 0.12 0.14 2.33 4.06
PigArtPressure 0.47 0.47 1.25 2.25
PigCVP 0.30 0.33 1.69 2.97
Plane 1.00 1.00 0.35 0.07
PowerCons 0.98 0.98 0.17 0.10
ProximalPhalanxOutlineAgeGroup 0.83 0.87 0.22 0.53
ProximalPhalanxOutlineCorrect 0.88 0.89 0.17 0.34
ProximalPhalanxTW 0.78 0.80 0.28 0.78
RefrigerationDevices 0.50 0.56 0.27 1.35
Rock 0.58 0.78 0.29 1.43
ScreenType 0.42 0.43 0.33 1.41
SemgHandGenderCh2 0.73 0.79 0.21 0.52
SemgHandMovementCh2 0.35 0.40 0.43 1.56
SemgHandSubjectCh2 0.52 0.52 0.39 1.13
ShapeletSim 0.99 1.00 0.14 0.12
ShapesAll 0.80 0.80 0.89 0.83
SmallKitchenAppliances 0.65 0.66 0.43 1.60
SmoothSubspace 0.96 0.97 0.23 0.15
SonyAIBORobotSurface1 0.87 0.90 0.08 0.29
SonyAIBORobotSurface2 0.75 0.79 0.15 0.54
StarLightCurves 0.98 0.98 0.22 0.09
Strawberry 0.97 0.98 0.15 0.09
SwedishLeaf 0.94 0.94 0.52 0.27
Symbols 0.83 0.87 0.39 0.61
SyntheticControl 1.00 1.00 0.31 0.04
ToeSegmentation1 0.93 0.97 0.16 0.17
ToeSegmentation2 0.88 0.91 0.15 0.27
Trace 1.00 1.00 0.29 0.02
TwoLeadECG 0.91 0.92 0.10 0.26
TwoPatterns 1.00 1.00 0.25 0.01
UMD 0.92 0.94 0.25 0.26
UWaveGestureLibraryAll 0.91 0.91 0.41 0.31
UWaveGestureLibraryX 0.82 0.82 0.46 0.56
UWaveGestureLibraryY 0.73 0.73 0.50 0.78
UWaveGestureLibraryZ 0.74 0.74 0.48 0.72
Wafer 1.00 1.00 0.05 0.01
Wine 0.48 0.63 0.19 1.07
WordSynonyms 0.62 0.62 0.61 1.60
Worms 0.77 0.78 0.41 0.70
WormsTwoClass 0.73 0.81 0.22 0.56
Yoga 0.86 0.86 0.24 0.33

Getting Started

from timeseries_fastai.imports import *
from timeseries_fastai.core import *
from timeseries_fastai.data import *
from timeseries_fastai.models import *
PATH = Path.cwd().parent
df_train, df_test = load_df_ucr(PATH, 'Adiac')
Loading files from: /home/tcapelle/SteadySun/timeseries_fastai/Adiac
x_cols = df_train.columns[0:-2].to_list()
dls = TSDataLoaders.from_dfs(df_train, df_test, x_cols=x_cols, label_col='target', bs=16)
dls.show_batch()

png

inception = create_inception(1, len(dls.vocab))
learn = Learner(dls, inception, metrics=[accuracy])
learn.fit_one_cycle(1, 1e-3)
epoch     train_loss  valid_loss  accuracy  time    
0         3.934007    3.640701    0.043478  00:03