TransWikia.com

Binary classification of multiple Sequences using Keras

Data Science Asked by ShadowEagle on December 10, 2020

I am trying to classify multiple independent sequences using Keras. My data looks like this (example with different stocks and their values).

  _stock     2010   2011   2012   2013   2014
----------- ------ ------ ------ ------ ------
 foo          100    200    250    300    400
 bar           50    100    100     50     25
 pear         100    250    250    300    400
 raspberry    100    200    300    400    500
 banana        50     20     10     10      5

I would like to classify the data like shown in the following structure. The labels are already pre-defined for each stock (supervised learning).

  _stock          label
----------- -----------------
 foo         0 (not falling)
 bar         1 (falling)
 pear        0 (not falling)
 raspberry   0 (not falling)
 banana      1 (falling)

Finally, I would also like to predict the next timestep, if possible.

  _stock     2015
----------- ------
 foo          450
 bar           10
 pear         500
 raspberry    600
 banana         1

Currently I’m just using a bunch of Dense Layers which is working fine, but I don’t think that I’m not utilizing the relationship between each column in the right way with this setup. Furthermore I don’t think that a prediction is possible with this setup.

# current network
from keras.models import Sequential
n_timesteps = len(data.columns)

model = Sequential()
model.add(Dense(100, activation="relu", input_dim=n_timesteps))
model.add(Dense(100, activation="relu"))
model.add(Dense(1, activation="sigmoid"))
model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"])

model.fit(x_train, y_train, epochs=100, validation_data=(x_test, y_test))

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP