Icon

LSTM - Time Series Forecasting

<p><strong>Supervised Learning Problem</strong></p><p>This is a simple example workflow for <strong>multivariant time series</strong> analysis using an <strong>LSTM </strong>based recurrent neural network and implemented via the KNIME Deep Learning - Keras Integration. It is based on the<strong> bike demand prediction</strong> dataset from Kaggle and trains a model to predict the demand in the <strong>next hour</strong> based on the demand and the other features in the l<strong>ast 10 hours</strong>.</p><ul><li><p>RNN architecture type = many-to-one</p></li><li><p>target column = "cnt'</p></li><li><p>features column = all column (except "timestamp"</p></li><li><p>timestamp column = "timestamp"</p></li></ul><p><em>notes</em>:</p><p>this workflow is expanded version of "<strong>Multivariate Time Series Analysis with an RNN" </strong>from Community Hub with these environment specification:</p><ul><li><p>rewrite on: May 2025</p></li><li><p>KNIME version: 5.4</p></li></ul><p></p><p><strong>The Dataset</strong></p><p>London Bike Sharing dataset have purpose is to try predict the future bike shares.</p><p><br><em>Metadata:</em></p><p>"timestamp" -&nbsp;<em>timestamp field for grouping the data</em><br>"cnt" -&nbsp;<em>the count of a new bike shares</em><br>"t1" -&nbsp;<em>real temperature in C</em><br>"t2" -&nbsp;<em>temperature in C "feels like"</em><br>"hum" -&nbsp;<em>humidity in percentage</em><br>"wind_speed" -&nbsp;<em>wind speed in km/h</em><br>"weather_code" -&nbsp;<em>category of the weather</em><br>"is_holiday" -&nbsp;<em>boolean field - 1 holiday / 0 non holiday</em><br>"is_weekend" -&nbsp;<em>boolean field - 1 if the day is weekend</em><br>"season" -&nbsp;<em>category field meteorological seasons:</em></p><p><em>&nbsp;</em></p><p><em>“Season” category description:</em></p><p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>0 = &nbsp;spring ;</em></p><p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>1 = summer;</em></p><p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>2 = fall;</em></p><p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>3 = winter.</em></p><p>"weather_code" category description:</p><p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>1 = Clear ; mostly clear but have some values with haze/fog/patches of fog/ fog in vicinity</em></p><p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>2 = scattered clouds / few clouds</em></p><p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>3 = Broken clouds</em></p><p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>4 = Cloudy</em></p><p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>7 = Rain/ light Rain shower/ Light rain</em></p><p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>10 = rain with thunderstorm</em></p><p>·&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <em>26 = snowfall</em></p><p><em>94 = Freezing Fog</em></p>

URL: Multivariate Time Series Analysis: LSTMs & Codeless https://www.knime.com/blog/multivariate-time-series-analysis-lstm-codeless
URL: Understanding LSTM Networks https://colah.github.io/posts/2015-08-Understanding-LSTMs/
URL: Multivariate Time Series Analysis with an RNN - Training https://hub.knime.com/s/B45XEOAuWeQBzO9b
URL: London Bike Sharing Dataset https://www.kaggle.com/datasets/hmavrodiev/london-bike-sharing-dataset

Data Preprocessing
Build The Model
Restructure Training Set
Extract Date Fields
Resort Columns
Define Network
Restructure Testing & Validation Set
Resort Columns
Extract Prediction & Evaluate Preformance
prediction
Evaluation

Multivariate Time Series Forecasing using LSTM

this workflow include:

  1. data inport

  2. data preprocessing

  3. build the model (define network & train the model)

  4. predict & evaluate model

Data Visualization
Data Import
only 'cnt' column(as target value)
Column Filter
colum append into structure: cnt, Input
Column Appender
input shape:10,13(10 = number of steps;13= dimension per step)
Keras Input Layer
Normalizer (Apply)
config:activation function=ReLU;Units=1
Keras Dense Layer
config:activation function=tanh;Units=100;
Keras LSTM Layer
Lag Column
Column Name Extractor
Column List Loop Start
Loop End (Column Append)
Counter Generation
Sorter
Table Transposer
Create Collection Column
Column Filter
Reference Column Resorter
Column Splitter
train the modelconfig:epoch=75;loss metric=MSE;training batch=32;validation batch=32;optimizer=Adam;learning rate=1.0E-4
Keras Network Learner
Column Appender
training set=50%validation set=50%
Partitioning
read London Bike Shareing dataset(london_merged.csv)notes:data already ascending by timestamp
CSV Reader
convert timestamp data type
String to Date&Time
extract timestamp into:month, day of month, day of week, hourconfig (example):Germany (Belgium) - en_GB
Date&Time Part Extractor
remove column: timestamp
Column Filter
training set=80% (from the top)testing & validation set=20%
Partitioning
normalize all columnusing min-max scaling (0,1)
Normalizer
save the normalizer model(overwrite)
Model Writer
Column Renamer
Denormalizer
save the model
Keras Network Writer
denormalize validation set
Denormalizer
append column:prediction andvalidation set
Column Appender
Model Reader
create column 'cnt_pred'= round('cnt') then change the type as integer
Math Formula
plot: original (validation set) vs preddiction
Line Plot (Plotly)
preformance metrics result(R2, MAE, MSE, RMSE, MAPE, MSD, adjusted R2)
Numeric Scorer
distibution plot of demand unique value (cnt)
Generic ECharts View
lag =10config:column name overwritten by flow variable
Lag Column
line chart cnt over timestamp (all data)
Generic ECharts View
create column: 'Counter'
Counter Generation
one column per iteration
Column List Loop Start
sorting by column: 'Counter' (descending)
Sorter
get(extract):column nameconfig:uncheck generate new column name
Column Name Extractor
sum demand for each dates
plot daily demand
Table Transposer
split into:1) table contain column data at t2) table contain column data at t-10, t-9 .. t-1
Column Splitter
create 'Input' colum as data list (sequence) of aggregated columnconfig:remove aggregated column
Create Collection Column
Reference Column Resorter
for each iteration: do column append
Loop End (Column Append)
Keras Network Executor

Nodes

Extensions

Links