0
$\begingroup$

I have x signals each with 5000 rows. Each signal x has its own one output in range from 1 to 6 (categories). So for example signal x1 has output 2, signal x2 has output 1.

How can I build X and Y datasets which will work fine with ann classification model. I was thinking to stack those x signals vertically in one column and the other column would be output values (third table bellow) but I do not know if this is right way.

EDITED (added image of signal):

  • I have x signals from x sensors which are running simultaneously.
  • Each signal represents weight of the truck (sensors are putted under the bridge to measure weight of the truck) where peaks mean number of axles of the truck (number of axles is my output (1 - 6 axles)). See picture below (signal x1 has 2 peaks meaning 2 axles):

signal

Signals x:

x1 x2 x3 x4 ...
0.1 0.7 1.3 1.9 ...
0.2 0.8 1.4 2.0 ...
0.3 0.9 1.5 2.1 ...
0.4 1.0 1.6 2.2 ...
0.5 1.1 1.7 2.3 ...
0.6 1.2 1.8 2.4 ...
... ... ... ... ...

Outputs:

y
1
2
3
4
...

Potential dataset (I used only x1 and x2 for simplicity):

x y
0.1 1
0.2 1
0.3 1
0.4 1
0.5 1
0.6 1
... ...
0.7 2
0.8 2
0.9 2
1.0 2
1.1 2
1.2 2
... ...

ann classifier:

X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 0.3)

# Initialising ANN
ann = tf.keras.models.Sequential()

# Adding First Hidden Layer
ann.add(tf.keras.layers.Dense(units = 5000, activation = "relu"))

# Adding Second Hidden Layer
ann.add(tf.keras.layers.Dense(units = 256, activation = "relu"))

# Adding Output Layer
ann.add(tf.keras.layers.Dense(units = 5, activation = 'softmax'))

# Compiling ANN
ann.compile(optimizer = "adam", loss = 'categorical_crossentropy',  metrics = ['accuracy'])

# Fitting ANN
X_train = np.array(X_train)
Y_train = np.array(Y_train)

ann.fit(X_train, Y_train, batch_size = 32, epochs = 100)
$\endgroup$
2
  • $\begingroup$ Do you mean that you have time series with $5000$ variables (such as the closing prices of $5000$ stocks)? $\endgroup$
    – Dave
    Aug 3 at 21:12
  • $\begingroup$ @Dave I edited the question. $\endgroup$ Aug 9 at 22:27

1 Answer 1

1
$\begingroup$

Your question isn't well-defined because you say that every signal [column] corresponds to a particular output, but you never elaborated the nature of the source of the signal. Did one device (or whatever generated the signal) output all these signals at a specified time? Or do you have multiple devices (corresponding to each x1,...) capturing signals simultaneously?

In the latter case, you would have the data stacked horizontally (so x1, ..., x4 are all their own columns). Since x1,... would all be their own distinct features (different indicators that contribute to a certain outcome), you would need to give each signal source its own column.

However, if your signals x1,... are all the same reading (i.e. you have x devices but they each only activate once at a time, no overlap), then you should stack it vertically.

Another possibility (as Dave mentioned) is that this is actually a time series (so there's a timestamp for each signal), in which case, you need to be more clear.

What you should do in each case...

In the former case (horizontal stacking, every signal goes off simultaneously at a moment), you would need some criteria to make sure you know which label to choose. Since all 6 signals go off simultaneously, you would need some rule to choose which signal caused the output (for example, if signal x4 was the largest-valued signal in a row, then you would choose label 4, same for x3, etc.). Define this and put a label on the observation according to the rule that's applicable here.

In the second case (vertical stacking, every sensor goes off one at a time), you can just do exactly as you suggested and the ANN will train weights according to some patterns it finds in the values.

If this is a time series (there are time stamps associated to every signal and the order in which these signals went out are important), then you need a model which accounts for the sequentially-varying nature of your data, an ordinary dense ANN will not work as intended (it'll train and run but it won't capture what you would be trying to predict in a time series).

I laid out all of the possibilities of your situation. Please let me know if there's more context that I didn't know of. If you can specify the nature of your problem, I can also help write the code to format the data.

$\endgroup$
1
  • $\begingroup$ I edited the question. @AndrewJaeyoung $\endgroup$ Aug 9 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.