dmbee / seglearn

Python module for machine learning time series:
https://dmbee.github.io/seglearn/
BSD 3-Clause "New" or "Revised" License
570 stars 63 forks source link

Using multiple features for neural network model #47

Closed fairread closed 4 years ago

fairread commented 4 years ago

Hi I tried to implement multiple features from seglearn example namely Classifying Segments Directly with a Neural Network . Specifically I just add up the FeatureRep() into the pipe definition as below:


pipe = Pype([('seg', Segment(width=100, overlap=0.5, order='C')),
             ('features', FeatureRep()),
             ('crnn', KerasClassifier(build_fn=crnn_model, epochs=1, batch_size=256, verbose=0))])

But then I encountered an error as below:

ValueError: Input 0 of layer sequential_14 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: [None, 66]

I'd imagine that I need to modify the input_shape definition of the crnn_model but am not quite sure how to do that. Appreciate any pointers for it, thanks.

dmbee commented 4 years ago

Have a look at the User Guide.

The FeatureRep transformer transforms a 3D tensor (n_segments, segment_length, n_channels) to a 2D feature representation (n_segments, n_features) to use with a non-neural model eg SVM, KNN, etc.

A CRNN or CNN is expecting the 3D tensor data as input. I'm not sure why you are using FeatureRep + CRNN. I suggest you take the FeatureRep transformer out of your pipeline.

Good luck. David

fairread commented 4 years ago

Hi David

Many thanks for your response. My intention was to have a set of multi-channel raw EMG signals, extract features (FeatureRep()) say root_mean_square and use such feature for the CRNN input instead of the raw signal. In this case how could I amend the CRNN input or pype parameters?

dmbee commented 4 years ago

The main advantage of a a neural network is it can learn arbitrary feature representations - so I would encourage you not to use that approach.

In any case, seglearn is not really setup for what you want since the FeatureRep collapses the time dimension in the segment. You would need to then reconstitute the feature vectors into time series and then segment the time series of features. You can look at Pype.predict_series to see how you can get predictions as a time series and maybe that will provide some inspiration. You will need to implement this capability yourself if you wish to try it. Sorry.