Multivariate Time Series Classification Tutorial with LSTM in PyTorch, PyTorch Lightning and Python

Поділитися
Вставка
  • Опубліковано 3 сер 2024
  • 🎓 Prepare for the Machine Learning interview: mlexpert.io
    🔔 Subscribe: bit.ly/venelin-subscribe
    📖 Get SH*T Done with PyTorch Book: bit.ly/gtd-with-pytorch
    🗓️ 1:1 Consultation Session With Me: calendly.com/venelin-valkov/c...
    🔣 GitHub: github.com/curiousily/Getting...
    In this tutorial, you'll learn how to convert sequences of sensor data to classify the surface on which a robot currently is. We'll use PyTorch Lightning to build a data module and an LSTM model for sequence classification. How accurate will our model be?
    #TimeSeries #PyTorch #Python #LSTM #Classification #Tutorial
  • Наука та технологія

КОМЕНТАРІ • 64

  • @sayederfanarefin
    @sayederfanarefin Рік тому

    You explained each step very clearly. Thanks man!

  • @indisdelosvanyar
    @indisdelosvanyar 3 роки тому

    Thanks for the time spent, your video helped me getting me back into my project :]
    I modified it to add evidence measure and evidence losses, thought not completely sure I'm doing everything ok and using it properly for inference / establishing the right rules to discriminate unreliable inferences, would be great if you could issue a part 2 adding that too.

  • @alteshaus3149
    @alteshaus3149 3 роки тому

    Thank you for this great video!
    Pleeease make some more videos about Time Series Forecasting!!
    I would love to see them and to share them with friends.
    regards from Austria

  • @anatolykruglov7991
    @anatolykruglov7991 10 місяців тому

    благодаря) този урок е страхотен

  • @amineleking9898
    @amineleking9898 3 роки тому +23

    Great videos man, many thanks. Could you also provide the links for the source code.
    Thanks for your great work 👍🏼

  • @robertjesuraj
    @robertjesuraj 3 роки тому +1

    Nice tutorial, i like to see more such videos👍
    Is it possible to teach some pytorch lightning in depth video?

  • @gmcobrazt3370
    @gmcobrazt3370 3 роки тому +1

    Hi Venelin. I watched your forecasting and classification videos, both are useful and great. I wonder if I can do classification and forecast at the same time using the same dataset. Do you have any idea on this? thanks

  • @lalitalone706
    @lalitalone706 3 роки тому

    Nice tutorial!

  • @DTrackFinder
    @DTrackFinder 3 роки тому +10

    Thanks! can you share the notebook created here?

  • @RedShipsofSpainAgain
    @RedShipsofSpainAgain Рік тому +1

    15:41: Making the PTL LightningDataModule.
    20:04: Making the SequenceModel, which extends Pytorch nn.Module.
    23:40: Making the PTL LightningModule.

  • @mukeshnarendran1083
    @mukeshnarendran1083 2 роки тому +2

    Thanks for the great content. Why do you not normalize or standardize your data before feeding it into the LSTM?

  • @abdullahmuhammadmoosa4031
    @abdullahmuhammadmoosa4031 2 роки тому

    Hey! Thanks for the tutorial!
    What kind of techniques can we use for resampling time series classification data?
    Can you please share some ideas?

  • @anonproxy6235
    @anonproxy6235 2 роки тому +1

    Awesome video mate. Do you have one on timeseries classification with MLP?

  • @emyomar8814
    @emyomar8814 3 роки тому

    Amazing thank you so much. Could you use transformers to handle same dataset

  • @AakashGuptaCH
    @AakashGuptaCH 2 роки тому

    Thank you for the video. I have one question. Since you are using test_dataset for the validation loop. Will it not fit the model according to the test dataset? The model should not have any knowledge of the test dataset right.

  • @karthikr5884
    @karthikr5884 Рік тому

    Great video :)

  • @zhuocao7459
    @zhuocao7459 Рік тому

    ty!

  • @mertmermerci218
    @mertmermerci218 5 місяців тому

    Thank you for the insightful video! In this implementation we assume that all the instances in a sequence have the same label. What if the label of instances within a sequence are not the same and change within the sequence? How should we add the label information into the sequence?

  • @elizabethm.j139
    @elizabethm.j139 2 роки тому +2

    Could you pls explain it using tensorflow?

  • @banafsh4146
    @banafsh4146 Рік тому

    Thanks for this tutorial. Could you please make a video of how to work with multi dimensional arrays as training data for the mode?

    • @trueToastedCode
      @trueToastedCode Рік тому

      do u mean that each time series has e.g. 1 more dimension? how does this even make sense? which kind of time series has a shape like that ... and why would you not just instead make multiple time series from that one time series that has multiple dimensions?

  • @user-yw6wf3uu1o
    @user-yw6wf3uu1o 2 роки тому +1

    How is it common to apply padding when the data length does not match?

  • @traderrider09
    @traderrider09 6 місяців тому

    Hey, is it not necessary to temporally split the data while creating training and testing data sets?

  • @zakkyang6476
    @zakkyang6476 8 місяців тому

    Hi, do you do the normalization before the modeling?

  • @karlbooklover
    @karlbooklover 2 роки тому +1

    I'm getting this error:
    TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
    Would you mind sharing the source code? That would help a lot

  • @renukalra7537
    @renukalra7537 2 роки тому

    can we one-hot encode the categorical variables?

  • @sang-hunsim8627
    @sang-hunsim8627 2 роки тому

    I am getting an error that 'SequenceModel' object has no attribute 'classifier'. Does anyone know why nn.Module doesn't have 'classifier' attribute?

  • @ibadrather
    @ibadrather 2 роки тому +5

    Working Code:
    github.com/ibadrather/pytorch_learn/blob/main/Part%2015%20-%20Multivariate_Time_%20Series_Classification_PyTorch_Lightning/Part%2015%20-%20Multivariate_Time_%20Series_Classification_Robot.ipynb

    • @asifsvirtualfootprint7370
      @asifsvirtualfootprint7370 2 роки тому +1

      Thank you so much for the link. Unfortunately in your code, I guess there is an error. That's why in classification, All have been classified into concrete.

    • @asifsvirtualfootprint7370
      @asifsvirtualfootprint7370 2 роки тому +1

      I have solved the problem. if you need it you can reply here.

    • @ibadrather
      @ibadrather 2 роки тому

      @@asifsvirtualfootprint7370 Yes please share. I was thinking about this

    • @ibadrather
      @ibadrather 2 роки тому

      @@asifsvirtualfootprint7370 Waiting for your reply :)

    • @asifsvirtualfootprint7370
      @asifsvirtualfootprint7370 2 роки тому +1

      can we connect anyhow? I am doing a project with this code.

  • @A7Reece
    @A7Reece 3 роки тому +1

    I followed your approach, took notes and am getting the following error when I try to initialize the SurfacePredictor
    ---------------------------------------------------------------------------
    TypeError Traceback (most recent call last)
    in
    ----> 1 model = SurfacePredictor(
    2 n_features = len(FEATURE_COLUMNS),
    3 n_classes = len(label_encoder.classes_)
    4 )
    in __init__(self, n_features, n_classes)
    5 def __init__(self, n_features: int, n_classes: int): # our constructor (int specifies featurs to integers)
    6 super().__init__()
    ----> 7 self.model = SequenceModel(n_features, n_classes) # initialize the model by taking the number of features and classes
    8 self.criterion = nn.CrossEntropyLoss() # criteria for classification
    9
    TypeError: __init__() takes 1 positional argument but 3 were given
    Any thoughts on what I may be doing wrong?

  • @talha_anwar
    @talha_anwar 2 роки тому

    In lstm don't we need to pass timestamp, n_features??

  • @Deepakkumar-sn6tr
    @Deepakkumar-sn6tr 3 роки тому

    Superb work!
    Looking forward to fine-tune Transformer BST/ BERT4REC

  • @aliyaqoob8779
    @aliyaqoob8779 3 роки тому +4

    What happens when the sequence lengths are not the same? Say, for example, one was 128 and another was 130. What would you do in this case?

    • @amineleking9898
      @amineleking9898 3 роки тому

      Undersample or oversample

    • @user-yw6wf3uu1o
      @user-yw6wf3uu1o 2 роки тому

      @@amineleking9898 exactly?

    • @amineleking9898
      @amineleking9898 2 роки тому

      @@user-yw6wf3uu1o for example add more points to the shortest sequence length to have same length as the other, using some technique. For example you can pad zeroes, or use linear interpolation....etc

    • @ibadrather
      @ibadrather 2 роки тому

      You can interpolate them to a uniform frequency

  • @trueToastedCode
    @trueToastedCode Рік тому

    I achieved loss=0.4251 and sparse_categorical_accuracy: 0.8596 for my 20% splitted testing data. Used tensorflow convolution network instead - it also works much better on Apple Silico. It only trained for 5 minutes or so then EarlyStopping kicked in. Btw there is like 10% of the code needed to do to with keras compared to torch.

    • @danielbalint8034
      @danielbalint8034 10 місяців тому +1

      Can you provide code please? :D

    • @trueToastedCode
      @trueToastedCode 10 місяців тому

      @@danielbalint8034 Think I've lost it. Just follow the official Tensorflow guide "Timeseries classification from scratch" instead. Btw i would be interested what results you've achieved :) I am wondering what transformers could do for this problem

  • @countrylifemoments4939
    @countrylifemoments4939 Рік тому +1

    Hi, are you planning to share the code with Github?

  • @jeromeanthonyalvarez4241
    @jeromeanthonyalvarez4241 3 роки тому +2

    Hello, Venelin! Thank you for this! I followed all your code step-by-step, but I get this error:
    RuntimeError: stack expects each tensor to be equal size, but got [0] at entry 0 and [1] at entry 3
    What needs to be done to fix this?

    • @johnmathew3580
      @johnmathew3580 3 роки тому +1

      Hi, I am facing same issue. Were you able to solve it?

    • @AlistairWalsh
      @AlistairWalsh 3 роки тому

      same error here

    • @dariopasquali9496
      @dariopasquali9496 2 роки тому

      same issue here, any fix?

    • @jackziad
      @jackziad 2 роки тому

      same issue on my side as well

    • @pierpaolosavina8085
      @pierpaolosavina8085 2 роки тому +6

      I had the same problem, I hope this will be helpful to others. The problem is in the __getitem__ function of the Dataset class, specifically in:
      return dict(
      sequence = torch.Tensor(sequence.to_numpy()),
      label=torch.tensor(label).long()
      )
      where you have to be careful and see that for the label, tensor is with lowercase t

  • @ProjectOfTheWeek
    @ProjectOfTheWeek Рік тому

    Don't work with CUDA 11.2 in google colab. Can update the code? thanks!

  • @ErfanKhodabakhsh
    @ErfanKhodabakhsh Рік тому +1

    please update the video code. many part of the code have bugs now

  • @lalitalone706
    @lalitalone706 3 роки тому

    Why you don't use one-hot encoding for preprocessing data?

  • @joshuabonet
    @joshuabonet 2 роки тому +1

    I tried to install pytorch-lighting in Google Colab with no luck...Unfortunately your video is outdated

    • @stanley_george
      @stanley_george 2 роки тому

      what error did you face ? You just need to run "!pip install pytorch-lightning"

  • @Artista1010
    @Artista1010 10 місяців тому

    you can't shuffle time series :)

  • @user-oz3lm2ky5x
    @user-oz3lm2ky5x 11 місяців тому

    А по-русски не проще было рассказать?

  • @johnmathew3580
    @johnmathew3580 3 роки тому +5

    Thanks! can you share the notebook created here?