Bitcoin Forum

Economy => Speculation => Topic started by: Accardo on February 22, 2022, 12:19:14 PM



Title: How to build a forecasting model using LSTM
Post by: Accardo on February 22, 2022, 12:19:14 PM
A forecasting model helps in the forecasting of prices or even sales in an organization or company. But, it can also be used to forecast bitcoin prices with the help of RNN (Recurrent Neural Network) if you follow the steps in this post  (https://www.analyticsvidhya.com/blog/2021/05/bitcoin-price-prediction-using-recurrent-neural-networks-and-lstm/)you will gain the source code for predicting bitcoin Price which can then be implemented on the forecasting model.

But, this Model is general and not specifically meant for bitcoin price but the process is poison and the underlying process can be the prediction of the bitcoin price. So the aim is to be able to forecast values in poison process that has cyclic fluctuation in the underlying process. Poison process can be used to solve many mathematical problems in the blockchain Network. Since forecasting is based on determining DATA the model used by the Author (https://github.com/ColinShaw) is ARIMA (https://github.com/ColinShaw/cyclic-poisson-forecasting-models/blob/master/ARIMA.ipynb) and LTSM model which will help to forecast next actual data point.

Poison Modeling Using LSTM (Long Short Term Memory)

Code:
import math
import numpy
import matplotlib.pyplot as plt
from src.poisson import Poisson
from src.lstm import LSTM
from sklearn.metrics import mean_squared_error
%matplotlib inline
%autosave False

Example Of Poison Process

Code:
p = Poisson()
example, _ = p.generate(6)

plt.figure(figsize=(20,7))
plt.plot(example)

Result: [<matplotlib.lines.Line2D at 0x7feed62121d0>]

https://i.imgur.com/nSRhFnQ.png


Train LSTM Model on a Larger Data set


Code:
t1, _ = p.generate(10000)
t2, _ = p.generate(10000,2)
train = t1 + t2
l = LSTM()
l.train(train, 6)


Apply the LSTM model to a new data set that is more varied


Code:
a1, _ = p.generate(4)
a2, _ = p.generate(2,2)
a3, _ = p.generate(4)
a4, _ = p.generate(1,2)
actual = numpy.concatenate((a1,a2,a3,a4))

pred = l.predict(actual)
#pred = [x-8.5 for x in pred]

Plot The Prediction

Code:
actual = actual[72:-1]
error = math.sqrt(mean_squared_error(pred, actual))

plt.figure(figsize=(20,7))
plt.title('RMSE: {:.2f}'.format(error))
plt.plot(actual)
plt.plot(pred)

Result: [<matplotlib.lines.Line2D at 0x7fef3f1acf50>]

https://i.imgur.com/lZI4s61.png

Evaluate The Residual (The remaining values)
Code:
residual = []
for i in range(len(actual)):
    val = actual[i] - pred[i]
    residual.append(val)

plt.figure(figsize=(20,7))
plt.plot(residual)

Result: [<matplotlib.lines.Line2D at 0x7feed003f410>]
https://i.imgur.com/sGndKHb.png


It's important to know that LSTM cannot function in all cases without a problem but, can be implemented on a less constrained data and it'll have lesser problems. While the ARIMA model performs better in forecasting data provided it remains compatible with the underlying process.

Source: https://github.com/ColinShaw/cyclic-poisson-forecasting-models/blob/master/LSTM.ipynb


Title: Re: How to build a forecasting model using LTSM
Post by: ABCbits on February 22, 2022, 12:29:56 PM
But, it can also be used to forecast bitcoin prices with the help of RNN (Recurrent Neural Network) if you follow the steps in this post  (https://www.analyticsvidhya.com/blog/2021/05/bitcoin-price-prediction-using-recurrent-neural-networks-and-lstm/)you will gain the source code for predicting bitcoin Price which can then be implemented on the forecasting model.

No matter what model/algorithm you use, it's not reliable enough if all data you have is only past Bitcoin price. Without external data (such as sentiment about Bitcoin on twitter or latest news about Bitcoin), i expect people who use that model/algorithm could go bankrupt when something big happen (such as an exchange hacked and most funds stolen).


Title: Re: How to build a forecasting model using LTSM
Post by: Accardo on February 22, 2022, 12:38:11 PM
But, it can also be used to forecast bitcoin prices with the help of RNN (Recurrent Neural Network) if you follow the steps in this post  (https://www.analyticsvidhya.com/blog/2021/05/bitcoin-price-prediction-using-recurrent-neural-networks-and-lstm/)you will gain the source code for predicting bitcoin Price which can then be implemented on the forecasting model.

No matter what model/algorithm you use, it's not reliable enough if all data you have is only past Bitcoin price. Without external data (such as sentiment about Bitcoin on twitter or latest news about Bitcoin), i expect people who use that model/algorithm could go bankrupt when something big happen (such as an exchange hacked and most funds stolen).

With the help of RNN the network can be predicted but it doesn't mean that the outcome will be correct at all time. The previous bitcoin price performance is the external data that will be used. However, RNN is compatible with speech and language or any sequential input. The bitcoin price can now be determined using the LSTM to keep track of the already saved prices inside the memory.