Input Data for Time Series Classification (Need Help)

username: jj77
cooked: <p>Hello,</p>
<p>Full disclosure upfront, I am new to machine learning and PyTorch.</p>
<p>I would like to create a neural network using PyTorch that takes time series data as input and classifies the wave shape as output. I am not sure, but I think this would be referred to as Time Series Classification.</p>
<p>Anyways, suppose that there are only three such possible wave shapes possible, either a,</p>
<ul>
<li>Sine wave</li>
<li>Triangle wave</li>
<li>Square wave</li>
</ul>
<p>More specifically, the time series data input to the neural network would consist of three individual waveforms, all with the same wave shape but with varying phases.</p>
<p>To make things clearer, it might be helpful if we consider an example input in which the sine wave wave shape is used. In that case, the times series data input to the neural network would look like this,</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/e/3/e3304ac51430a013985bae5b6c809e66df4ca0f2.png" data-download-href="https://discuss.pytorch.org/uploads/default/e3304ac51430a013985bae5b6c809e66df4ca0f2" title="SineWavePic"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/e/3/e3304ac51430a013985bae5b6c809e66df4ca0f2_2_690x335.png" alt="SineWavePic" data-base62-sha1="wpNQLwMf2IGcJbbm3tdjAWvYvh8" width="690" height="335" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/e/3/e3304ac51430a013985bae5b6c809e66df4ca0f2_2_690x335.png, https://discuss.pytorch.org/uploads/default/original/3X/e/3/e3304ac51430a013985bae5b6c809e66df4ca0f2.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/e/3/e3304ac51430a013985bae5b6c809e66df4ca0f2.png 2x" data-dominant-color="F0F2F0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">SineWavePic</span><span class="informations">762×371 40.9 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Note that the time series data for each of the waveforms will all contain the same number of samples. In the example shown above, there are 100 data points for each waveform, for a total of 300 data points for this single time series data input.</p>
<p>I’ve generated several of sets of time series data using the three waveform shapes mentioned previously and concatenated them together into one large pandas data frame which I’ve called X_train. I also have another file called y_train which contains a table with the associated series id and label for each set of time series data contained in X_train.</p>
<p>Just to use some numbers, suppose I have 10 sets of time series data, where each set has a total of 300 data points as mentioned previously.</p>
<p>My question is, how should I structure the X and y training data so that I can use them to train my neural network in PyTorch? My guess is that I would need to convert the data into tensors, but I am not sure how to go about doing that or what dimension tensor I need to use. Is there a function to convert pandas data frames into tensors for PyTorch? Do I need to make any modifications to the dataframe before conversion?</p>
<p>Thanks for all your help!</p>

username: ptrblck
cooked: <p>Since <code>pandas.DataFrame</code> uses <code>numpy</code> internally, you could create PyTorch tensors via <code>tensor = torch.from_numpy(df[...])</code> (and call <code>.clone()</code> additionally if you don’t want to share the underlying numpy array).<br>
The input shape depends on the used module and the majority of modules expect an input in the shape <code>[batch_size, *]</code>, where <code>*</code> denotes additional dimensions. You can check the docs to see the expected shape input. In case you want to use RNNs, make sure to check the shapes, as the default setup is to use the sequential dimension in <code>dim0</code>.</p>