0% found this document useful (0 votes)
11 views14 pages

An optimal deep learning-based LSTM for stock price prediction using twitter sentiment analysis

This research presents a novel Teaching and Learning Based Optimization (TLBO) model integrated with Long Short-Term Memory (LSTM) for predicting stock prices using Twitter sentiment analysis. The TLBO-LSTM model demonstrated superior predictive performance with a maximum precision of 95.33% and an accuracy of 94.73%, outperforming existing methods. The study emphasizes the importance of sentiment analysis from social media in forecasting stock market trends.

Uploaded by

Kangana W. M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views14 pages

An optimal deep learning-based LSTM for stock price prediction using twitter sentiment analysis

This research presents a novel Teaching and Learning Based Optimization (TLBO) model integrated with Long Short-Term Memory (LSTM) for predicting stock prices using Twitter sentiment analysis. The TLBO-LSTM model demonstrated superior predictive performance with a maximum precision of 95.33% and an accuracy of 94.73%, outperforming existing methods. The study emphasizes the importance of sentiment analysis from social media in forecasting stock market trends.

Uploaded by

Kangana W. M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Applied Intelligence (2022) 52:13675–13688

https://doi.org/10.1007/s10489-022-03175-2

An optimal deep learning-based LSTM for stock price prediction


using twitter sentiment analysis
T. Swathi 1 & N. Kasiviswanath 2 & A. Ananda Rao 3

Accepted: 2 January 2022 / Published online: 8 March 2022


# The Author(s), under exclusive licence to Springer Science+Business Media, LLC, part of Springer Nature 2022

Abstract
Stock Price Prediction is one of the hot research topics in financial engineering, influenced by economic, social, and
political factors. In the present stock market, the positive and negative opinions are the important indicators for the
forthcoming stock prices. At the same time, the growth of the internet and social network enables the clients to express
their opinions and shares their views on future stock processes. Therefore, sentiment analysis of the social media data
of stock prices helps to predict future stock prices effectively. With this motivation, this research presents a new novel
Teaching and Learning Based Optimization (TLBO) model with Long Short-Term Memory (LSTM) based sentiment
analysis for stock price prediction using Twitter data. The tweets are generally short, having unusual grammatical
structures, and hence the data pre-processing is essential to remove the unwanted data and transform it into a mean-
ingful format. Besides, the LSTM model is applied to classify tweets into positive and negative sentiments related to
stock prices. They help investigate how the tweets correlate with the nature of the stock market prices. To improve the
predictive outcome of the LSTM model, the Adam optimizer is used to determine the learning rate. Furthermore, the
TLBO model is applied to tune the output unit of the LSTM model optimally. Experiments are carried out on the
Twitter data to ensure the better stock price predictive performance of the TLBO-LSTM model. The experimental
findings of the TLBO-LSTM model show promising results over the state of art methods in terms of diverse aspects.
The TLBO-LSTM model produced a superior outcome, with a maximum precision of 95.33%, a recall of 85.28%, and
an F-score of 90%. By achieving a greater accuracy of 94.73%, the TLBO-LSTM model surpassed the other
techniques.

Keywords Sentiment analysis . Long short-term memory (LSTM) . Teaching and learning-based optimization (TLBO) . Twitter
data . Stock price prediction . Deep learning . Adam optimizer

1 Introduction

With the recent advancements in the internet and social


network, people started to express their opinions on social
media. The social network serves as a perfect platform to
* T. Swathi reflect public emotions on a certain topic. Twitter is a
[email protected] social media application enabling users to comment and
follow other clients’ opinions and share their thoughts in
N. Kasiviswanath
[email protected]
the real world [1, 2]. Over millions of clients post around
one hundred and forty million tweets daily. This makes
A. Ananda Rao Twitter corpus useful information for the research com-
[email protected]
munities. The data used from tweets are highly beneficial
1
Department of CSE, Jawaharlal Nehru Technological University
for predictions purpose [3, 4]. However, predicting stock
Anantapur (JNTUA), Ananthapuramu 515002, India market closing prices is virtually impossible. Long Short-
2
Department of CSE, G Pulla Reddy Engineering College Kurnool,
Term Memory (LSTM) is a highly effective approxima-
Kurnool 518001, India tion technique that has been widely applied in this sub-
3
Vice Chancellor Rayalaseema University, Kurnool 518001, India
ject. Numerous nature-inspired evolutionary optimization
13676 T. Swathi et al.

algorithms have been developed and applied in the litera- the output unit of the LSTM model optimally. Finally, an
ture to determine the optimal parameters for LSTM-based extensive set of simulations are carried out on Twitter data
forecasting models. However, the vast majority of them to ensure the better performance of the stock price prediction
require fine-tuning of a number of control and algorithm- of the TLBO-LSTM model.
specific parameters in order to function well. Inadequate The remainder of the document has been structured as fol-
tuning of these aspects results in increased computing lows. On the other hand, section 2 discussed the related works
costs or suboptimal local locations. Due to the develop- of the proposed model with its merits and demerits in compar-
ment in social networks, academicians’ attention turns to ison with existing models. The proposed TLBO-LSTM
this novel area [5–7]. Model and Adam optimizer process are outlined in section
Several companies have started to measure the effective- 3, and section 4 presents the suggested model performance
ness of their advertisement, the popularity of their brand, and evaluation and the simulation procedure, and research studies
the feedback of their customers at certain changes. Succeeding were concluded in section 5.
the novel empathies, the interest stimulated the implication of
social network sentiments in the financial market over several
countries. In the present stock markets, the moods of stock- 2 Related works
holders are the major sign of the forthcoming value of stock
[8]. Recently, the growth of the internet and social media have Stock markets create several transaction data that give Deep
been utilized by stockholders to express their ideas and delib- Neural Network (DNN) a huge quantity of data for training
erate the forthcoming stocks. Additionally, the sentiment data and enhancing their predictive capacity. Zhang et al. [17] em-
of historical prices can predict the forthcoming stock price. ployed historical price data for predicting stocks’ future return
The stock price is influenced by several aspects involving ranking with a new stock selection method based on the DNN
macroeconomics. But the research focuses on the individual method. Li et al. [18] developed a method that uses Deep
feeling of the clients (with their comments). Learning (DL) framework to enhance the feature depictions
To attain an optimal predictive method for stocks, the and applies Extreme Learning Machine (ELM) for predicting
whole data regarding company periodical reports have to be market factors. Chen et al. [19] utilized a DNN training meth-
aggregated. However, the objective of the presented model is od with price data for predicting the everyday volatility of
to attain an optimum accuracy with clients’ feedback and stocks in the Chinese A-share market. Ding et al. [20] present-
comments in the social network [9]. It is possible to extract ed an approach that utilizes a Neural Tensor Network for
sentiments from social media by performing opinion mining training the event embedded with news headings and
with a huge amount of data [10]. However, it is a difficult Convolutional Neural Network (CNN) for predicting volatil-
process as the text in social media is generally full of idioms ity of S&P 500 and its essential stocks. Akita et al. [21] pro-
and uncommon grammatical structure. Though several inves- posed a news article by vectors. They trained a DNN for
tigators have declared weak to strong prediction abilities, prior predicting the final price of 50 stocks in Tokyo Stock
investigators have determined that sentiment data in social Exchange correspondingly.
networks has no prediction power. Still, the commentaries On the basis of technical indicators and historical prices,
on social media have predicted that stock price remains chal- Nelson et al. [22] forecasted the future trajectory of equities on
lenging [11, 12]. the Brazilian Stock Exchange. The DNN outperforms other
The aim of this study is to improve the method by utilizing Machine Learning (ML) techniques in terms of stock forecast-
mood data in social networks for forecasting the stock market ing accuracy. In the Chinese A-share market, Li et al. [23]
variations in the future [13]. The primary goals of sentiment compared the learning potential of DL and traditional ML
analysis are to determine the polarity of a text at the level of techniques. Technical indicators of price data and classifica-
the information, the sentence, or the entity feature that is, to tion results show that DNN is more accurate. Hu et al. [24]
determine whether an expressed viewpoint in a sentence, the used price data and news vectors to train a bi-directional GRU
documents, or the entity feature is positive, negative, or neu- technique, which predicted daily stock volatility. Shi et al.
tral [14]. The assignment is made at the level of the document [25] developed the DeepClue approach for linking text-
itself. This research presents a new novel Teaching and based DNN with stock price prediction clients. According to
Learning Based Optimization (TLBO) model with Long the study on text mining applications in the financial area [26,
Short-Term Memory (LSTM) model-based sentiment analy- 27], around 70% of prior investigations in this domain have
sis for stock price prediction using Twitter data [15, 16]. The been done with standard approaches such as regression anal-
TLBO-LSTM model aims to forecast the stock market prices ysis, Support Vector Machine (SVM), and decision trees.
with the sentiments of users from the tweets related to stock Recently, with the development of DNNs, this research field
prices. Moreover, the Adam optimizer is used to determine the has increased dramatically. Reduced binary classification er-
learning rate. Furthermore, the TLBO model is applied to tune ror rates have been achieved by utilizing a Deep Belief
An optimal deep learning-based LSTM for stock price prediction using twitter sentiment analysis 13677

Network in conjunction with a Recurrent Neural Network Neural Network (CNN) for predicting volatility of S&P 500
(RNN) [28, 29]. and its essential stocks. They trained a DNN for predicting the
Recently, the majority of studies have projected the market final price of 50 stocks in Tokyo Stock Exchange correspond-
using ensemble learning to construct clusters and LSTMs, ingly. On the basis of technical indicators and historical prices.
respectively [30, 31]. Ding et al. [32] from October 2006 to A hidden Markov model is used in stock market trend analysis
November 2013, knowledge-driven event embedding for a specific time frame. The hidden state sequence and its
(KGEB) used the CNN model achieved 66.93% accuracy probabilities are discovered for a given observation series.
for the data source S&P 500 via Yahoo Finance, news items Probability is represented by the letter p. [Graphic representa-
from Reuter’s website. Vargas et al. [15] combined LSTM tion] of an artificial neuron 927, the stock price trend percent-
and CNN models to achieve 61% accuracy for word embed- age based on a stock market prediction survey; the decision-
ding and 62% accuracy for sentence embedding and technical makers make decisions in ambiguous situations.
indication. The data for the S&P 500 index series were ac-
quired from Yahoo Finance and news items from Reuter’s
website between 20 and 10-2006 and 2-11-2013. Chen et al.
[32] Tokyo Stock Price Index (TOPIX), Reuters financial 3 The proposed TLBO-LSTM model
news. By using the Structured Stock Prediction Model
(SSPM), Multi-Task Structured Stock Prediction Model The overall system architecture of the TLBO-LSTM pro-
(MSSPM) using BiLSTM, self-attention, and Conditional posed model is illustrated in Fig. 1. It predicts stock
Random Fields, we achieved SSPM Accuracy of 66.4% and prices via four major processes: pre-processing, classifi-
MSSPM Accuracy of 65.7% (CRF). Deng et al. [13] used cation, learning rate schedule, and output unit optimiza-
Dow Jones Industrial Average (DJIA) index from August 8, tion. In the first stage, the Twitter data is pre-processed to
2008, to January 1, 2016. Yahoo Finance stock price statistics, eradicate the unwanted details and make it compatible
Reddit news, headlines World News Channel used the with the prediction process. Secondly, the LSTM model
Knowledge-Driven Temporal Convolutional Network is applied to classify the Twitter data into negative and
(KDTCN) model to achieve 71.8% accuracy. positive sentiments regarding stock prices. Thirdly, the
Jin and Yang et al. [33] used EMD-LSTM with attention Adam optimization technique is used to determine the
layer to obtain 3.196534-RMSE, 1.65-MAPE, 2.396121- optimal learning rate of the LSTM model. For each pa-
MAE, and 0.977388 R2 on Apple stocks from Yahoo rameter in the method, the Adam optimizer computes
Finance and Stock comment dataset from Stock twits. adaptive learning rates, which are then stored as exponen-
Among the authors are Holt-Winters and others. Holt- tially declining average square gradations of the preceding
Winters is an appropriate model for time series with trend values.
and seasonal elements. The series was divided into trend, ba- Finally, the TLBO algorithm is used to compute the opti-
sis, and seasonality. Holt-Winters identifies smoothing param- mal output of the LSTM unit, thereby improving the overall
eters for trend, level, and season. There are two types of Holt- predictive performance of the LSTM model. The algorithmic
Winters Smoothing models: additive and multiple. There procedure of determining a word’s lemma based on its mean-
should be no seasonal fluctuations in the series. It outperforms ing is referred to as lemmatization. The morphological study
many other prediction models in terms of accuracy. of words with the purpose of deleting inflectional endings is
On frequently employs the Holt-Winters exponential referred to as lemmatization. It assists in lemmatization
smoothing method for short-term economic forecasting, (returning a word’s base or dictionary form). A memory net-
which incorporates trend and seasonal swings. Hidden work is a combination of machine learning algorithms and a
Markov Model HMM [12] was developed to predict stock read-write memory component. The model is trained to un-
market data in an address. An HMM is a stochastic model derstand how to use the memory component effectively.
based on a Markov chain. When compared to other models, There is a memory, m, which contains an array of items that
it is more accurate. HMM, parameters include A, B, and p. are indexed (e.g., vectors or arrays of strings).
Box and Jenkins created this ARIMA model in 1970 [34]. In
addition to identifying, estimating, and diagnosing ARIMA
models with time-series data, Box-Jenkins’s methodology in- 3.1 Data pre-processing
cludes other tasks. The mainstay of financial forecasting.
ARIMA models have been shown to produce good short- The presented technique utilizes the subsequent pre-
term forecasts. However, uncertainty is a function of past processing steps for enhancing the quality of the dataset, as
values and errors. the Twitter data contains several unwanted details. In addition,
However, applying Neural Tensor Network for training the this stage removes an unnecessary noise component from the
event embedded with news headings and Convolutional input dataset using subsequent steps.
13678 T. Swathi et al.

Fig. 1 Block diagram of TLBO-


LSTM model

& Remove the URLs using regular expression equivalent processes it and passes it on. The differences are in LSTM’s
such as textual pattern, which determines a search pattern internal procedures. The LSTM can save and forget data using
for text or string to search the email address, URL, etc. these processes. The memory cell is handled through the in-
& Handle negations by using full form of the text instead of put, output, and forget gate. Input gates activate the data input
short forms. For example, isn’t”: “is not”, “can’t”: “can- to memory cells, while the forget gates selectively delete some
not”, “couldn’t”: “could not”, “hasn’t”: “has not”, data from the memory cell and start to save it for the following
“hadn’t”: “had not”, “won’t”: “will not”, etc. input. At last, the output gate chooses the output data from the
& Remove the punctuation marks such as full stop (.), com- memory cell [29].
ma (,), hyphen (−), backward slash (\), parenthesis (), for- The LSTM network is shown in Fig. 2. All boxes signify
ward slash, etc. various information, and the arrow lines are the data flow
& Exchange “@Username” with “usr” by utilizing regular among them. In Fig. 2, it is realized that the LSTM saves
expression equivalent. memory for an extended duration.
& As “hashtag (#)” give beneficial data, thus eliminating #, The recognition process of LSTM starts with a group of
keep the word accordingly. Especially “#Lee” is replaced input sequences x = (x1, x2, …, xt) (xi is a vector) and finally,
with “Lee”. it generates an output y = (y1, y2, …, yt) (yi is also a vector)
& Remove the Twitter keywords from the input tweets that is computed using the subsequent formulas.
& Eliminate entire stop words like the, as, is, and so on from
the tweets.
& Replace the white spaces with individual white spaces.
& Remove numbers and convert the tweets into lower case
& Perform stemming and tokenization

3.2 LSTM model

At this stage, the pre-processed tweets are fed into the LSTM
model for the classification of sentiments as positive and neg-
ative. LSTM is the type of RNN with a memory cell to retain
memory for a certain duration. The LSTM’s control flow is
comparable to that of an RNN. As data propagates forward, it Fig. 2 Structure of LSTM
An optimal deep learning-based LSTM for stock price prediction using twitter sentiment analysis 13679

3.4 TLBO algorithm


it ¼ σðW ix xt þ W I mt1 þ bi Þ ð1Þ
ot ¼ σðW ox xt þ W om mt1 þ bo Þ ð2Þ Finally, the TLBO algorithm is executed to determine the
f t ¼ 1  it ð3Þ optimal output of the LSTM unit for the prediction of
stock price sentiments from the tweets. Deep learning fea-
tct ¼ g ðW cx xt þ W cm mt1 þ bc Þ ð4Þ ture extraction uses the pre-trained network as an arbitrary
ct ¼ f t  ct1 þ it  tct ð5Þ feature extractor, allowing the input image to propagate
forward until coming to a halt at a pre-specified layer and
mt ¼ ot  hct ð6Þ
  then using the results of that layer’s processing as our
yt ¼  W ym mt þ by ð7Þ features. TLBO is a population-based technique, and it
is inspired by the teaching-learning method in the class-
where i, o and f implies input, output, and forget gates, respec- room. It mainly depends on the control of teachers over
tively. tc is the data input to the memory cell, c represents the the output of learners in the classroom and the communi-
cell activation vectors and m signifies the data in the memory cation among learners. Instead of specific parameters, the
cell output. W denotes the weight matrices (for instance, Wix TLBO just requires general affecting parameters like pop-
indicates the weight matrix from input x to an input gate i). b ulation size and iteration count. The inclusion of a teach-
defines the bias (bi represents the input gate bias vector) while ing method in the TLBO algorithm is intended to raise the
g and h are the activation functions of the cell input and out- class’s average grade. Figure 3 illustrates the flowchart of
put, respectively. ⊙ implies the point multiplication in the the TLBO technique. This technique has 2 stages, namely
matrix. ϕ refers to the activation function of NN output, and the teacher and learner stages. A detailed explanation of
it is utilized as sigmoid. the technique is given below.

3.3 Adam optimizer


3.4.1 Teacher stage
Adam optimizer is used to tun the learning rate scheduling
parameter of the LSTM model. It determines the learning rate At the teacher stage of the TLBO technique, the role of the
adaptively for every variable that exists in the training process teacher is to increase the mean grade of the class. Assume that
[30]. The first and second moments of gradients are estimated the objective function is f(X) with n-dimensionality variable,
to compute adaptive learning rates for various parameters. the ith student is demonstrated by Xi = [xi1, xi2, …, x]. At g,
This variant of stochastic gradient descent was named Adam consider the population size of the class is m, and the mean
by the authors. AdaGrad is a per-parameter adaptive gradient outcome of students in the present iteration is X gmean ¼ ð1=mÞ
Pm Pm Pm 
algorithm that preserves learning rates while learning. (e.g., i¼1 i¼1 xi2 ; ; i¼1 x . The student with optimal fitness is
Computer vision and natural language problems). It is the selected as the teacher of the present iteration, and it is signi-
computationally effective and easier model which comprises fied as Xteacher. Every student upgrades their position as fol-
the 1st order gradients with the least memory requirements for lows.
stochastic optimization. It can be mathematically defined as  
follows. X i;new ¼ X i;old þ r1 X teacher  T F X gmean ð12Þ

xt ¼ 1 *xt1  ð1  1 Þ*g t ð8Þ where Xi, new and Xi, previous are the new and previous locations
of ith student and r1 implies the arbitrary number ranging from
yt ¼ 2 *yt1  ð1  2 Þ*g 2t ð9Þ 0 and 1. When the new solution obtained is superior to the
xt previous one, the previous location of the student is replaced
Δ!t ¼ η pffiffiffiffiffiffiffiffiffiffiffiffi *g t ð10Þ
yt þ  with the new location [31]. The value of TF is arbitrarily de-
!tþ1 ¼ !t þ Δ!t ð11Þ fined by Eq. (13).
T F ¼ round ½1 þ rand ð0; 1Þf2  1g ð13Þ

η Initial learning rate and: vector value.


gt Gradient at time t beside ωj. 3.4.2 Learner stage
xt Exponential average of gradient beside ωj
yt Exponential average of squares of gradient beside ωj At the learner stage of the TLBO technique, the learners could
δ1, δ2 Hyperparameters improve their skills from others. The learner communicates
arbitrarily with the learners to enhance her/his skill. The
13680 T. Swathi et al.

Fig. 3 Flowchart of TLBO


algorithm

learning in the learner stage is given as follows. For ith indi- 4 Performance validation
vidual Xi in the jth round, arbitrarily selects the kth individual
Xk that is distinct from Xi and the upgraded equation of Xi is This section validates the suggested TLBO-LSTM
determined in (14) and (15). model’s stock price prediction outcome analysis on the
When Xi is superior to Xk based on its fitness, used dataset. To tune the output unit of the LSTM model
optimally, the TLBO method is used. Experiments on
X i;new ¼ X i;previous þ ri ðX i  X k Þ ð14Þ
Twitter data are conducted to ensure that the TLBO-
Otherwise LSTM model has a higher forecasting ability for stock
prices. The experimental results obtained with the
X i;new ¼ X i;previous þ ri ðX k  X i Þ ð15Þ TLBO-LSTM model demonstrate that it outperforms
state-of-the-art pro posals in a variety of w ays.
where ri represents the arbitrary number ranging between 0 Evaluation metrics are used to judge the quality of a
and 1. When the new location Xi, new is superior to previous statistical or machine learning model. A number of eval-
one Xi, previous, the previous location Xi, previous is replaced with uation measures can be used to test a model. These mea-
the new location Xi, new; then, the location of ith individual sures include things like classification accuracy,
remain unmodified.
An optimal deep learning-based LSTM for stock price prediction using twitter sentiment analysis 13681

logarithmic loss, and confusion matrix, among others. A


set of screenshots obtained during the simulation process
is provided in Appendix. Figure 4 On the basis of a
Twitter dataset analysis, it shows the confusion matrix
created by the LSTM model. The LSTM model has suc-
cessfully classified a set of 1796 instances into the
Negative class and 3597 instances into the Positive class,
as shown in the image. The following performance anal-
ysis was applied for the prediction process. The mathe-
matical representation of precision is given in the follow-
ing equation.
TP Fig. 5 Confusion matrix of TLBO-LSTM model
precision ¼ ð16Þ
TP þ FP

Where TP is denotes the True Positive values, FP denotes network software library. DeepClue is a program that
the False Positive, and FN denotes the False Negatives. analyses text data and forecasts stock price movements.
TP It consists of four blocks: word, bigram, title, and feed-
recall ¼ ð17Þ forward. The DeepClue system uses data from the news
TP þ FN
and Twitter to generate its predictions. The performance
ðprecisionÞ  ðrecallÞ
F score ¼ 2: ð18Þ ratio, a measure of the total value of PV system losses,
precision recall has been developed and validated. The performance ratio
TP þ TN (PR), which is conveyed as a percentage, describes the
accuracy ¼ ð19Þ
TP þ FP þ TN þ FN relationship between the real, theoretical energy outputs
of a PV facility. Generally speaking, the closer a PV
Similarly, Fig. 5 shows the confusion matrix produced
plant’s PR number is to 100 %, the more efficiently that
by the LSTM-TLBO algorithm on the Twitter dataset.
particular PV plant is running.
The figure clarifies that the LSTM-TLBO model has im-
Detailed result analyses of the proposed LSTM and TLBO-
proved results by classifying a set of 1900 instances un-
LSTM models are given in Table 1 and Fig. 6. From the
der the Negative class and 3586 instances under the
experimental values, the LSTM method has attained a profi-
Positive class. These values show that the LSTM-
cient outcome with an accuracy of 0.9313, precision of
TLBO algorithm has obtained improved classification
0.9533, sensitivity of 0.8528, specificity of 0.9761, F1-Score
outcomes over the LSTM model with the inclusion of
of 0.9003, AUC Score of 0.9145, kappa of 0.8481, Hamming
the TLBO algorithm. In comparison to current models,
Loss of 0.0687, MCC of 0.8511 and Log Loss of 2.3738.
DeepClue is a program that attempts to combine text data
However, the TLBO-LSTM technique has enhanced
and stock price data and creates a time series for it.
DeepClue is implemented using the Dynet neural

Table 1 Result analysis of proposed models

Performance measures LSTM TLBO-


LSTM

Accuracy 0.9313 0.9473


Precision 0.9533 0.9505
Sensitivity 0.8528 0.9022
Specificity 0.9761 0.9731
F1-Score 0.9003 0.9257
AUC Score 0.9145 0.9377
Kappa Score 0.8481 0.8850
Hamming Loss 0.0687 0.0527
Mathews Correlation Coefficient 0.8511 0.8857
Log Loss 2.3738 1.8191
Fig. 4 Confusion matrix of LSTM model without TLBO algorithm
13682 T. Swathi et al.

Fig. 6 Result analysis of TLBO-


LSTM model with different
measures

classification outcomes with an accuracy of 0.9473, precision LSTM results with previous techniques. The LR model
of 0.9505, sensitivity of 0.9022, specificity of 0.9731, F1- has a precision of 62.10%, a recall of 62.40%, and an F-
Score of 0.9257, AUC Score of 0.9377, kappa of 0.8850, score of 62.10%, as shown in the diagram. The RNN
Hamming Loss of 0.0527, MCC of 0.8857, and Log Loss of model also received a 62.46 F-score, 63.45% precision,
1.8191. and 63.65% recall. The RF model had a precision of
A ROC analysis of the LSTM model against the 71.10%, while the 70.20% precision model achieved
Twitter dataset is shown in Fig. 7, that the LSTM model 70.20% precision. Percent recall and an F-score of 69%,
has effectively classified the stock prices using Twitter the given TLBO-LSTM model, had 95.33% precision,
data with a higher ROC of 0.98. Besides, the ROC anal- 85.28% recall, and an F-score of 90%.
ysis of the TLBO-LSTM model demonstrated in Fig. 8 The computation time analysis of the TLBO-LSTM
portrays the enhanced classification outcome with a max- with other existing methods shows that the TLBO-
imum ROC of 0.99. LSTM model requires a minimal computation time of
Table 2 compares the proposed TLBO-LSTM model to 17.55 s, whereas the MDNN-ELM, DeepClue, and
previously published methods [9, 11]. In terms of preci- MFNN models require a maximum computation time of
sion, recall, and F-score, Fig. 9 compares the TLBO- 19.90s, 21.80s, and 27.80s, respectively. A False

Fig. 7 ROC analysis of LSTM


model
An optimal deep learning-based LSTM for stock price prediction using twitter sentiment analysis 13683

Fig. 8 ROC analysis of TLBO-


LSTM model

Positive Rate (FPR) is a statistic for assessing the accu- LSTM model has outperformed the other methods by
racy of a subset of machine learning models. The classi- obtaining a higher accuracy of 94.73%.
fier will anticipate the most likely class for incoming
data using what it has learned about previous data.
Furthermore, the FPR study demonstrates the superiority
of the TLBO-LSTM model over other techniques, with 5 Conclusion
an FPR of 5.43, which is significantly lower than the
other techniques’ values. Through the use of Twitter sentiment analysis, this article built
Accuracy analysis of the TLBO-LSTM model with a unique TLBO-LSTM model for stock price prediction. The
other existing techniques depicted in Fig. 10 proves that proposed TLBO-LSTM model forecasts stock prices using
the LR and RNN models have the least accuracy of four processes: pre-processing, LSTM-based classification,
62.42% and 64.29%, respectively. Followed by increased Adam-based learning rate scheduling, and TLBO-based out-
accuracy of 70.18% has been attained by the RF model, put unit optimization. The TLBO algorithm and Adam opti-
whereas the DeepClue and MFNN models have an accu- mizer contribute significantly to the LSTM model’s efficien-
racy of 88.50% and 83.50%, respectively. Next to that, cy. To ensure that the TLBO-LSTM model predicts stock
the MDNN-ELM model has an optimal result with an prices accurately, a large number of simulations are run on
accuracy of 93.40%. However, the presented TLBO- Twitter data. The experimental results obtained using the
TLBO-LSTM model demonstrate that it outperforms other

Table 2 Result analysis of the


exiting techniques with the Methods Precision Recall F- Accuracy FPR Time
proposed model in terms of score
different measures
TLBO-LSTM 95.33 85.28 90.00 94.73 5.43 17.55
MDNN-ELM – – – 93.40 6.60 19.90
DeepClue – – – 88.50 11.50 21.80
MFNN – – – 83.50 16.50 27.80
Random Forest 71.10 70.20 69.00 70.18 – –
Logistic Regression 62.10 62.40 62.10 62.42 – –
RNN 63.45 63.65 62.46 64.29 – –
13684 T. Swathi et al.

Fig. 9 Comparative analysis of


TLBO-LSTM model with
existing techniques

methods in a variety of ways. The TLBO-LSTM model superior outcome with a maximum accuracy than existing
outperformed the other strategies with higher accuracy of methods. Future work will add feature selection approaches
94.73%. The offered TLBO-LSTM model outperformed the into the TLBO-LSTM model to alleviate the curse of dimen-
other technology with a superior accuracy of 94.73%, 95.33% sionality and improve predictive performance. Also, forecast-
of precision,85.28% recall, and 90% f-score than the existing ing of textual data and financial time series with various ma-
methodology. The experimental findings of the TLBO-LSTM chine learning algorithms will be carried out to achieve the
model show promising results over the state of art methods in best performance in stock prediction.
terms of diverse aspects. The TLBO-LSTM model produced a

Fig. 10 Accuracy analysis of


TLBO-LSTM model with
existing techniques
Accuracy (%)
RNN
Logistic Regression
Random Forest
Methods

MFNN
DeepClue
MDNN-ELM
TLBO-LSTM
60 70 80 90 100
An optimal deep learning-based LSTM for stock price prediction using twitter sentiment analysis 13685

Appendix
13686 T. Swathi et al.

The above figures show the confusion matrix produced by the A ROC analysis of the LSTM model against the Twitter
LSTM-TLBO algorithm on the Twitter dataset. The figure dataset is shown in Fig. 7, that the LSTM model has effective-
clarifies that the LSTM-TLBO model has improved results ly classified the stock prices using Twitter data with a higher
by classifying a set of 1900 instances under the Negative class ROC of 0.98. Besides, ROC analysis of the TLBO-LSTM
and 3586 instances under the Positive class.
An optimal deep learning-based LSTM for stock price prediction using twitter sentiment analysis 13687

model demonstrated in Fig. 8 portrays the enhanced classifi- 16. Tripathi S et al (2021) IoT-based traffic prediction and traffic signal
control system for smart city. Soft Comput. https://doi.org/10.1007/
cation outcome with a maximum ROC of 0.99.
s00500-021-05896-x
17. Zhang X, Tan Y (2018) Deep stock ranker: a LSTM neural network
model for stock selection. International conference on data mining
and big data. Springer, pp 614–623
References 18. Li X, Cao J, Pan Z (2019) Market impact analysis via deep learned
architectures. Neural Comput & Applic 31:5989–6000
19. Chen K, Zhou Y, Dai F (2015) A LSTM-based method for stock
1. Pagolu VS, Reddy KN, Panda G, Majhi B (2016) Sentiment anal- returns prediction: a case study of China stock market. 2015 IEEE
ysis of Twitter data for predicting stock market movements. In 2016 international conference on big data. IEEE2823–2824
international conference on signal processing, communication, 20. Ding X, Zhang Y, Liu T, Duan J (2015) Deep learning for event-
power and embedded system (SCOPES), pp 1345-1350. IEEE driven stock prediction. Proceedings of the 24th international con-
2. Paulraj D (2020) A gradient boosted decision tree-based sentiment ference on artificial intelligenceIJCAI’15AAAI Press2327–2333
classification of twitter data. International Journal of Wavelets, 21. Akita R, Yoshihara A, Matsubara T, Uehara K (2016) Deep learn-
Multiresolution and Information Processing, World Scientific, ing for stock prediction using numerical and textual information.
ISSN 1793-690X (online), 18:(4):205027 1–21 2016IEEE/ACIS 15th international conference on computer and
3. Pak A, Paroubek P (2010) Twitter as a corpus for sentiment analysis information science. IEEE1–6
and opinion mining. In: Proceedings of the Seventh International 22. Nelson DM, Pereira AC, De Oliveira RA (2017) Stock market’s
Conference on Language Resources and Evaluation, pp 13201326 price movement prediction with LSTM neural networks.
4. Neelakandan S (2020) An automated learning model of conven- Proceedings of the international joint conference on neural net-
tional neural network based sentiment analysis on Twitter data. works2017-May. Proceedings of the international joint conference
Journal of Computational and Theoretical Nano Science 17(5): on neural networks IEEE1419–1426
2230–2236 23. Li W., Liao J (2018). A comparative study on trend forecasting
5. Teti E, Dallocchio M, Aniasi A (2019) The relationship between approach for stock price time series. Proceedings of the internation-
twitter and stock prices. Evidence from the US technology industry. al conference on anti-counterfeiting, security and identification,
Technological Forecasting and Social Change 149:119747 asid2017-Octob. Proceedings of the international conference on
6. Ambeth Kumar VD, Malathi S, Kumar A, Prakash M, Veluvolu anti-counterfeiting, security and identification, asid 74–78
KC (2020) Active volume control in smart phones based on user 24. Hu Z, Liu W, Bian J, Liu X, Liu T-Y (2018) Listening to chaotic
activity and ambient noise. Sensors 20(15):4117. https://doi.org/10. whispers: a deep learning framework for news-oriented stock trend
3390/s20154117 prediction. Proceedings of the eleventh ACM international confer-
7. Paulraj D (2020) An automated exploring and learning model for ence on web search and data miningWSDM ‘18New York, NY,
data prediction using balanced CA-Svm. Journal of Ambient USA: ACM261–269
Intelligence and Humanized Computing. Springer, pp 1-12, ISSN 25. Shi L, Member S, Teng Z, Wang L, Zhang Y, Binder A (2019)
1868-5137 (online), Published Online: April 2020 DeepClue : visual interpretation of text-based deep stock prediction.
8. Derakhshan A, Beigy H (2019) Sentiment analysis on stock social IEEE Trans Knowl Data Eng 31:1094–1108
media for stock price movement prediction. Eng Appl Artif Intell 26. Kumar BS, Ravi V (2016) A survey of the applications of text
85:569–578 mining in financial domain. Knowl-Based Syst 114:128–147
9. Zou F, Chen D, Wang J (2016) An improved teaching-learning- 27. Xing FZ, Cambria E, Welsch RE (2018) Natural language based
based optimization with the social character of PSO for global op- financial forecasting: a survey. Artif Intell Rev 50(1):49–73
timization. Computational Intelligence and Neuroscience:2016 28. Yoshihara A, Seki K, Uehara K (2015) Leveraging temporal prop-
10. Annamalai R, Rayen SJ, Arunajsmine J (2020) Social media net- erties of news events for stock market prediction. Artif Intell Res
works owing to disruptions for effective learning. Procedia 5(1):103
Computer Science 172:145–151. https://doi.org/10.1016/j.procs. 29. Rajaraman PV (2020) A Survey on Text Question Responsive
2020.05.022 Systems in English and Indian Languages. Soft Computing and
11. Gokul Anand J (2011) "trust based optimal routing in MANET's," Signal Processing. Advances in Intelligent Systems and
2011 international conference on emerging trends in electrical and Computing 1118. https://doi.org/10.1007/978-981-15-2475-2_25
computer technology. Nagercoil, India, pp 1150–1156. https://doi. 30. Jia Y, Wu Z, Xu Y, Ke D, Su K (2017) Long short-term memory
org/10.1109/ICETECT.2011.5760293 projection recurrent neural network architectures for piano’s con-
12. Divyabharathi S (2016) Large scale optimization to minimize net- tinuous note recognition. Journal of Robotics 2017
work traffic using MapReduce in big data applications. 31. Yaqub M, Jinchao F, Zia MS, Arshid K, Jia K, Rehman ZU,
International Conference on Computation of Power, Energy Mehmood A (2020) State-of-the-art CNN optimizer for brain tumor
Information and Communication (ICCPEIC), pp. 193–199, April segmentation in magnetic resonance images. Brain Sciences 10(7):
2016. 10.1109/ICCPEIC.2016.7557196 427
13. Anand R, Singh H (2021) Interpretable filter based convolutional 32. Ding X, Zhang Y, Liu T, Duan J (2016) Knowledge-driven event
neural network (IF-CNN) for glucose prediction and classification embedding for stock prediction. Proceedings of Coling 2016, the
using PD-SS algorithm. Measurement 183. https://doi.org/10.1016/ 26th International Conference on Computational Linguistics:
j.measurement.2021.109804 Technical Papers.2016
14. Bhukya RR, Hardas BM, Ch T et al (2022) An automated word 33. Rene Beulah J, Sumathy R, Varalakshmi G, Neelakandan S (2022)
embedding with parameter tuned model for web crawling. IoT enabled environmental toxicology for air pollution monitoring
Intelligent Automation & Soft Computing 32(3):1617–1632 using AI techniques. Environ Res 205:112574. https://doi.org/10.
15. Vargas DL, Evsukoff Vargas MR, De Lima BS, Evsukoff AG 1016/j.envres.2021.112574
(2017) Deep learning for stock market prediction from financial 34. Mathai PP, Karthikeyan C et al (2021) Deep learning based capsule
news articles. 2017 IEEE international conference on computation- neural network model for breast cancer diagnosis using mammo-
al intelligence and virtual environments for measurement systems gram images. Interdiscip Sci Comput Life Sci. https://doi.org/10.
and applications (CIVEMSA); Piscataway: IEEE; 2017 1007/s12539-021-00467-y
13688 T. Swathi et al.

35. Nofer M, Hinz O (2015) Using twitter to predict the stock market. temporal convolutional network. Companion Proceedings of the
Bus Inf Syst Eng 57(4):229–242 2019. World Wide Web Conference
36. Cyril CPD, Beulah JR, Mohan P, Harshavardhan A, 38. Jin Y, Liu Jin Z, Yang Y, Liu Y (2019) Stock closing price predic-
Sivabalaselvamani D An automated learning model for sentiment tion based on sentiment analysis and LSTM. Neural Computing and
analysis and data classification of Twitter data using balanced CA- Applications 32:9713–9729
SVM. https://doi.org/10.1177/1063293X211031485
37. Deng S, Zhang N, Zhang W, Chen J, Pan JZ, Chen H (2019) Publisher’s note Springer Nature remains neutral with regard to jurisdic-
Knowledge-driven stock trend prediction and explanation via tional claims in published maps and institutional affiliations.

You might also like