🧠 Discussion: Fixing Conv1D Model Input Shape for BTC Price Prediction #692
Sreeram0303
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
📌 Context:
I'm building a Conv1D model using TensorFlow to predict the next day's Bitcoin price based on the past 7 days' prices. Below is a summary of the original approach and what needed to be updated for the model to work correctly.
❌ Original Issues:
Incorrect Input Shape for Conv1D:
The model was getting input with shape (7,) (i.e., just a sequence of 7 values).
But Conv1D layers require 3D input: (batch_size, timesteps, input_dim).
The Lambda layer was used, but incorrectly as expand_dims(x, axis=1) which reshaped (7,) into (1, 7) — wrong for time series modeling.
(in the course it was implemented on 1D thats why it showed (7,1) but when dealing with 2D like (2,7) the implemented lambda layer will give smtng like (2,1,7) which is not ideal as there are 7 timestpes and all are single feature (prices) )
The expected input shape is (batch_size,timesteps/steps,features/channels) - (N,7,1)
Output Dimensionality Confusion:
The model used Conv1D followed by Dense(HORIZON), assuming multi-step output, but our use case is single-step (next-day) prediction.
Final corrected code i cam up with
model = tf.keras.Sequential([
layers.Lambda(lambda x: tf.expand_dims(x, axis=-1)),
layers.Conv1D(filters=128, kernel_size=3, padding="causal", activation="relu"),
layers.GlobalMaxPooling1D(),
layers.Dense(64, activation='relu'),
layers.Dense(1)
])
Training this updated model on (7,1) windows resulted in a working setup that accurately forecasts the next BTC price. Feel free to correct me
Beta Was this translation helpful? Give feedback.
All reactions